Logo Search packages:      
Sourcecode: qgis version File versions

bool QgsRasterLayer::readFile ( QString const &  fileName  )  [private]

Load the given raster file

Returns:
true if successfully read file
Note:
Called from ctor if a raster image given there

Definition at line 431 of file qgsrasterlayer.cpp.

References adfGeoTransform, blueBandNameQString, buildRasterPyramidList(), drawingStyle, gdalDataset, getMetadata(), getRasterBandName(), getRasterBandStats(), grayBandNameQString, greenBandNameQString, hasBand(), hasPyramidsFlag, QgsMapLayer::layerExtent, mPyramidPixmap, noDataValueDouble, rasterLayerType, rasterStatsVector, rasterXDimInt, rasterYDimInt, readColorTable(), redBandNameQString, QgsRect::setXmax(), QgsRect::setXmin(), QgsRect::setYmax(), QgsRect::setYmin(), and QgsMapLayer::valid.

Referenced by QgsRasterLayer(), and readXML_().

{
    GDALAllRegister();

    //open the dataset making sure we handle char encoding of locale properly
    gdalDataset = (GDALDataset *) GDALOpen((const char*)(fileName.local8Bit()), GA_ReadOnly);

    if (gdalDataset == NULL)
    {
        valid = FALSE;
        return false;
    }
    //check f this file has pyramids
    GDALRasterBandH myGDALBand = GDALGetRasterBand( gdalDataset, 1 ); //just use the first band
    if( GDALGetOverviewCount(myGDALBand) > 0 )
    {
        hasPyramidsFlag=true;
    }
    else
    {
        hasPyramidsFlag=false;
    }

    //populate the list of what pyramids exist
    buildRasterPyramidList();

    //load  up the pyramid icons
#if defined(WIN32) || defined(Q_OS_MACX)
    QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";
#endif

    mPyramidPixmap.load(QString(PKGDATAPATH) + QString("/images/icons/pyramid.png"));
    mNoPyramidPixmap.load(QString(PKGDATAPATH) + QString("/images/icons/no_pyramid.png"));

    //just testing remove this later
    getMetadata();

    double myXMaxDouble = adfGeoTransform[0] +
        gdalDataset->GetRasterXSize() * adfGeoTransform[1] +
        gdalDataset->GetRasterYSize() * adfGeoTransform[2];
    double myYMinDouble = adfGeoTransform[3] +
        gdalDataset->GetRasterXSize() * adfGeoTransform[4] +
        gdalDataset->GetRasterYSize() * adfGeoTransform[5];

    layerExtent.setXmax(myXMaxDouble);
    layerExtent.setXmin(adfGeoTransform[0]);
    layerExtent.setYmax(adfGeoTransform[3]);
    layerExtent.setYmin(myYMinDouble);

    //
    // Set up the x and y dimensions of this raster layer
    //
    rasterXDimInt = gdalDataset->GetRasterXSize();
    rasterYDimInt = gdalDataset->GetRasterYSize();

    //
    // Determin the no data value
    //
    noDataValueDouble = gdalDataset->GetRasterBand(1)->GetNoDataValue();

    //initialise the raster band stats vector
    for (int i = 1; i <= gdalDataset->GetRasterCount(); i++)
    {
        GDALRasterBand *myGdalBand = gdalDataset->GetRasterBand(i);
        QString myColorQString = GDALGetColorInterpretationName(myGdalBand->GetColorInterpretation());
        RasterBandStats myRasterBandStats;
        myRasterBandStats.bandName = myColorQString + " (" + QString::number(i) + ")";
        //myRasterBandStats.bandName=QString::number(i) + " : " + myColorQString;
        myRasterBandStats.bandNoInt = i;
        myRasterBandStats.statsGatheredFlag = false;

        // Read color table
        readColorTable ( myGdalBand, &(myRasterBandStats.colorTable) );

        rasterStatsVector.push_back(myRasterBandStats);
    }


    //decide what type of layer this is...
    //note that multiband images can have one or more 'undefindd' bands,
    //so we must do this check first!
    if ((gdalDataset->GetRasterCount() > 1))
    {
        rasterLayerType = MULTIBAND;
    }
    else if (hasBand("Palette")) //dont tr() this its a gdal word!
    {
        rasterLayerType = PALETTE;
    }
    else
    {
        rasterLayerType = GRAY_OR_UNDEFINED;
    }

    if (rasterLayerType == PALETTE)
    {
        redBandNameQString = redTranslatedQString; // sensible default
        greenBandNameQString = greenTranslatedQString; // sensible default
        blueBandNameQString = blueTranslatedQString; // sensible default
        grayBandNameQString = tr("Not Set");  //sensible default
        drawingStyle = PALETTED_MULTI_BAND_COLOR; //sensible default
    }
    else if (rasterLayerType == MULTIBAND)
    {
        //we know we have at least 2 layers...
        redBandNameQString = getRasterBandName(1);  // sensible default
        greenBandNameQString = getRasterBandName(2);  // sensible default
        //for the third layer we cant be sure so..
        if (gdalDataset->GetRasterCount() > 2)
        {
            blueBandNameQString = getRasterBandName(3); // sensible default
        }
        else
        {
            blueBandNameQString = tr("Not Set");  // sensible default
        }
        grayBandNameQString = tr("Not Set");  //sensible default
        drawingStyle = MULTI_BAND_COLOR;  //sensible default
    }
    else                        //GRAY_OR_UNDEFINED
    {
        getRasterBandStats(1);
        redBandNameQString = tr("Not Set"); //sensible default
        greenBandNameQString = tr("Not Set"); //sensible default
        blueBandNameQString = tr("Not Set");  //sensible default
        drawingStyle = SINGLE_BAND_GRAY;  //sensible default
        if (hasBand("Gray"))
        {
            grayBandNameQString = "Gray"; // sensible default //dont tr() this its a gdal word!
        }
        else if (hasBand("Undefined")) //dont tr() this its a gdal word!
        {
            grayBandNameQString = "Undefined";  // sensible default
        }
    }

    return true;

} // QgsRasterLayer::readFile


Generated by  Doxygen 1.6.0   Back to index