Index: raster/qgsrasterlayer.cpp =================================================================== --- src/core/raster/qgsrasterlayer.cpp (Revision 13391) +++ src/core/raster/qgsrasterlayer.cpp (Arbeitskopie) @@ -1,4 +1,4 @@ -/* ************************************************************************** +/*************************************************************************** qgsrasterlayer.cpp - description ------------------- begin : Sat Jun 22 2002 @@ -89,7 +89,36 @@ mHeight( std::numeric_limits::max() ), mInvertColor( false ) { + mIgnoreGeoTransform = false; + mIgnoreGCPs = false; + constructRasterLayer(path, baseName, loadDefaultStyleFlag); +} + +QgsRasterLayer::QgsRasterLayer( + QString const & path, + QString const & baseName, + bool loadDefaultStyleFlag, + bool ignoreGeoTransform, + bool ignoreGCPs ) + : QgsMapLayer( RasterLayer, baseName, path ), + // Constant that signals property not used. + QSTRING_NOT_SET( "Not Set" ), + TRSTRING_NOT_SET( tr( "Not Set" ) ), + mStandardDeviations( 0 ), + mDataProvider( 0 ), + mWidth( std::numeric_limits::max() ), + mHeight( std::numeric_limits::max() ), + mInvertColor( false ) +{ + mIgnoreGeoTransform = ignoreGeoTransform; + mIgnoreGCPs = ignoreGCPs; + + constructRasterLayer(path, baseName, loadDefaultStyleFlag); +} + +void QgsRasterLayer::constructRasterLayer( QString const & path, QString const & baseName, bool loadDefaultStyleFlag ) +{ mRasterType = QgsRasterLayer::GrayOrUndefined; mRedBandName = TRSTRING_NOT_SET; @@ -208,6 +237,9 @@ { setDataProvider( providerKey, layers, styles, format, crs ); } + + mIgnoreGeoTransform = false; + mIgnoreGCPs = false; // Default for the popup menu // TODO: popMenu = 0; @@ -2723,14 +2755,8 @@ if ( mProviderKey.isEmpty() ) { - if ( GDALGetGeoTransform( mGdalDataset, mGeoTransform ) != CE_None ) + if ( getGeoTransform( mGdalDataset, mGeoTransform) ) { - // if the raster does not have a valid transform we need to use - // a pixel size of (1,-1), but GDAL returns (1,1) - mGeoTransform[5] = -1; - } - else - { myMetadata += "

"; myMetadata += tr( "Origin:" ); myMetadata += "

\n"; @@ -5173,12 +5199,12 @@ mLastModified = lastModified( theFilename ); // Check if we need a warped VRT for this file. - if (( GDALGetGeoTransform( mGdalBaseDataset, mGeoTransform ) == CE_None - && ( mGeoTransform[1] < 0.0 - || mGeoTransform[2] != 0.0 - || mGeoTransform[4] != 0.0 - || mGeoTransform[5] > 0.0 ) ) - || GDALGetGCPCount( mGdalBaseDataset ) > 0 ) + if ( ( getGeoTransform( mGdalBaseDataset, mGeoTransform ) + && ( mGeoTransform[1] < 0.0 + || mGeoTransform[2] != 0.0 + || mGeoTransform[4] != 0.0 + || mGeoTransform[5] > 0.0 ) ) + || ( !mIgnoreGCPs && GDALGetGCPCount( mGdalBaseDataset ) > 0 ) ) { QgsLogger::warning( "Creating Warped VRT." ); @@ -5198,7 +5224,7 @@ GDALReferenceDataset( mGdalDataset ); } - //check f this file has pyramids + //check if this file has pyramids GDALRasterBandH myGDALBand = GDALGetRasterBand( mGdalDataset, 1 ); //just use the first band if ( myGDALBand == NULL ) { @@ -5813,3 +5839,27 @@ } } } + + +bool QgsRasterLayer::getGeoTransform(GDALDatasetH theDataset, double theGeoTransform[6]) const +{ + if ( theDataset == NULL ) + { + return false; + } + + if ( mIgnoreGeoTransform || (CE_None != GDALGetGeoTransform( theDataset, theGeoTransform )) ) + { + // if the raster does not have a valid transform we need to use + // a pixel size of (1,-1), but GDAL returns (1,1) + theGeoTransform[0] = 0; + theGeoTransform[1] = 1; + theGeoTransform[2] = 0; + theGeoTransform[3] = 0; + theGeoTransform[4] = 0; + theGeoTransform[5] = -1; + return false; + } + + return true; +} Index: raster/qgsrasterlayer.h =================================================================== --- src/core/raster/qgsrasterlayer.h (Revision 13391) +++ src/core/raster/qgsrasterlayer.h (Arbeitskopie) @@ -200,6 +200,22 @@ const QString & baseName = QString::null, bool loadDefaultStyleFlag = true ); + /** \brief This is the constructor for the RasterLayer class. + * + * Same as the QgsRasterLayer::QgsRasterLayer(const QString &, const QString &, bool) + * constructor, but adds the option to ignore dataset provided + * geotransforms and ground control points. This is useful + * for applications where pixel coordinates are desired (e.g. for the georeferencer + * plugin). + * + * @note added in 1.5 + */ + QgsRasterLayer( const QString & path, + const QString & baseName, + bool loadDefaultStyleFlag, + bool ignoreGeoTransform, + bool ignoreGCPs); + /** \brief [ data provider interface ] Constructor in provider mode */ QgsRasterLayer( int dummy, const QString & baseName = QString(), @@ -666,6 +682,8 @@ /** \brief Write layer specific state to project file Dom node */ bool writeXml( QDomNode & layer_node, QDomDocument & doc ); + /** \brief Store geotransform information of the given GDAL dataset in theGeoTransform. \return true on success. */ + virtual bool getGeoTransform(GDALDatasetH theDataset, double theGeoTransform[6]) const; @@ -675,6 +693,9 @@ // Private methods // + /** \brief Initialisation code shared by constructors. */ + void constructRasterLayer( QString const & path, QString const & baseName, bool loadDefaultStyleFlag ); + /** \brief Drawing routine for multiband image */ void drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort, @@ -879,6 +900,12 @@ /** \brief Flag indicating if the nodatavalue is valid*/ bool mValidNoDataValue; + + /** \brief Flag indicating whether the raster provided geotransform should be ignored. Used to display rasters in pixel coordinates. */ + bool mIgnoreGeoTransform; + + /** \brief Flag indicating whether the raster provided GCPs should be ignored. */ + bool mIgnoreGCPs; }; /*#include