qgsrasterlayer_ignore_geotransform.diff

mmassing -, 2010-06-12 02:38 AM

Download (6.3 KB)

View differences:

src/core/raster/qgsrasterlayer.cpp (Arbeitskopie)
1
/* **************************************************************************
1
/***************************************************************************
2 2
        qgsrasterlayer.cpp -  description
3 3
   -------------------
4 4
begin                : Sat Jun 22 2002
......
89 89
    mHeight( std::numeric_limits<int>::max() ),
90 90
    mInvertColor( false )
91 91
{
92
  mIgnoreGeoTransform = false;
93
  mIgnoreGCPs         = false;
92 94

  
95
  constructRasterLayer(path, baseName, loadDefaultStyleFlag);
96
}
97

  
98
QgsRasterLayer::QgsRasterLayer(
99
  QString const & path,
100
  QString const & baseName,
101
  bool loadDefaultStyleFlag,
102
  bool ignoreGeoTransform,
103
  bool ignoreGCPs )
104
    : QgsMapLayer( RasterLayer, baseName, path ),
105
    // Constant that signals property not used.
106
    QSTRING_NOT_SET( "Not Set" ),
107
    TRSTRING_NOT_SET( tr( "Not Set" ) ),
108
    mStandardDeviations( 0 ),
109
    mDataProvider( 0 ),
110
    mWidth( std::numeric_limits<int>::max() ),
111
    mHeight( std::numeric_limits<int>::max() ),
112
    mInvertColor( false )
113
{
114
  mIgnoreGeoTransform = ignoreGeoTransform;
115
  mIgnoreGCPs         = ignoreGCPs;
116
  
117
  constructRasterLayer(path, baseName, loadDefaultStyleFlag);
118
}
119

  
120
void QgsRasterLayer::constructRasterLayer( QString const & path, QString const & baseName, bool loadDefaultStyleFlag )
121
{  
93 122
  mRasterType = QgsRasterLayer::GrayOrUndefined;
94 123

  
95 124
  mRedBandName = TRSTRING_NOT_SET;
......
208 237
  {
209 238
    setDataProvider( providerKey, layers, styles, format, crs );
210 239
  }
240
  
241
  mIgnoreGeoTransform = false;
242
  mIgnoreGCPs         = false;
211 243

  
212 244
  // Default for the popup menu
213 245
  // TODO: popMenu = 0;
......
2723 2755

  
2724 2756
  if ( mProviderKey.isEmpty() )
2725 2757
  {
2726
    if ( GDALGetGeoTransform( mGdalDataset, mGeoTransform ) != CE_None )
2758
    if ( getGeoTransform( mGdalDataset, mGeoTransform) )
2727 2759
    {
2728
      // if the raster does not have a valid transform we need to use
2729
      // a pixel size of (1,-1), but GDAL returns (1,1)
2730
      mGeoTransform[5] = -1;
2731
    }
2732
    else
2733
    {
2734 2760
      myMetadata += "<p class=\"glossy\">";
2735 2761
      myMetadata += tr( "Origin:" );
2736 2762
      myMetadata += "</p>\n";
......
5173 5199
  mLastModified = lastModified( theFilename );
5174 5200

  
5175 5201
  // Check if we need a warped VRT for this file.
5176
  if (( GDALGetGeoTransform( mGdalBaseDataset, mGeoTransform ) == CE_None
5177
        && ( mGeoTransform[1] < 0.0
5178
             || mGeoTransform[2] != 0.0
5179
             || mGeoTransform[4] != 0.0
5180
             || mGeoTransform[5] > 0.0 ) )
5181
      || GDALGetGCPCount( mGdalBaseDataset ) > 0 )
5202
  if ( ( getGeoTransform( mGdalBaseDataset, mGeoTransform )
5203
         && ( mGeoTransform[1] < 0.0
5204
              || mGeoTransform[2] != 0.0
5205
              || mGeoTransform[4] != 0.0
5206
              || mGeoTransform[5] > 0.0 ) )
5207
         || ( !mIgnoreGCPs && GDALGetGCPCount( mGdalBaseDataset ) > 0 ) )
5182 5208
  {
5183 5209
    QgsLogger::warning( "Creating Warped VRT." );
5184 5210

  
......
5198 5224
    GDALReferenceDataset( mGdalDataset );
5199 5225
  }
5200 5226

  
5201
  //check f this file has pyramids
5227
  //check if this file has pyramids
5202 5228
  GDALRasterBandH myGDALBand = GDALGetRasterBand( mGdalDataset, 1 ); //just use the first band
5203 5229
  if ( myGDALBand == NULL )
5204 5230
  {
......
5813 5839
    }
5814 5840
  }
5815 5841
}
5842

  
5843

  
5844
bool QgsRasterLayer::getGeoTransform(GDALDatasetH theDataset, double theGeoTransform[6]) const
5845
{
5846
  if ( theDataset == NULL )
5847
  {
5848
    return false;
5849
  }
5850

  
5851
  if ( mIgnoreGeoTransform || (CE_None != GDALGetGeoTransform( theDataset, theGeoTransform )) )
5852
  {
5853
    // if the raster does not have a valid transform we need to use
5854
    // a pixel size of (1,-1), but GDAL returns (1,1)
5855
    theGeoTransform[0] =  0;
5856
    theGeoTransform[1] =  1;
5857
    theGeoTransform[2] =  0;
5858
    theGeoTransform[3] =  0;
5859
    theGeoTransform[4] =  0;
5860
    theGeoTransform[5] = -1;
5861
    return false;
5862
  }
5863

  
5864
  return true;
5865
}
src/core/raster/qgsrasterlayer.h (Arbeitskopie)
200 200
                    const QString &  baseName = QString::null,
201 201
                    bool loadDefaultStyleFlag = true );
202 202

  
203
    /** \brief This is the constructor for the RasterLayer class.
204
     *
205
     * Same as the QgsRasterLayer::QgsRasterLayer(const QString &, const QString &, bool)
206
     * constructor, but adds the option to ignore dataset provided
207
     * geotransforms and ground control points. This is useful
208
     * for applications where pixel coordinates are desired (e.g. for the georeferencer
209
     * plugin).
210
     *
211
     * @note added in 1.5
212
     */
213
    QgsRasterLayer( const QString & path,
214
                    const QString & baseName,
215
                    bool loadDefaultStyleFlag,
216
                    bool ignoreGeoTransform, 
217
                    bool ignoreGCPs);
218

  
203 219
    /**  \brief [ data provider interface ] Constructor in provider mode */
204 220
    QgsRasterLayer( int dummy,
205 221
                    const QString & baseName = QString(),
......
666 682
    /** \brief Write layer specific state to project file Dom node */
667 683
    bool writeXml( QDomNode & layer_node, QDomDocument & doc );
668 684

  
685
    /** \brief Store geotransform information of the given GDAL dataset in theGeoTransform. \return true on success. */
686
    virtual bool getGeoTransform(GDALDatasetH theDataset, double theGeoTransform[6]) const;
669 687

  
670 688

  
671 689

  
......
675 693
    // Private methods
676 694
    //
677 695

  
696
    /** \brief Initialisation code shared by constructors. */
697
    void constructRasterLayer( QString const & path, QString const & baseName, bool loadDefaultStyleFlag );
698

  
678 699
    /** \brief Drawing routine for multiband image  */
679 700
    void drawMultiBandColor( QPainter * theQPainter,
680 701
                             QgsRasterViewPort * theRasterViewPort,
......
879 900

  
880 901
    /** \brief Flag indicating if the nodatavalue is valid*/
881 902
    bool mValidNoDataValue;
903
    
904
    /** \brief Flag indicating whether the raster provided geotransform should be ignored. Used to display rasters in pixel coordinates. */
905
    bool mIgnoreGeoTransform;
906

  
907
    /** \brief Flag indicating whether the raster provided GCPs should be ignored. */
908
    bool mIgnoreGCPs;
882 909
};
883 910

  
884 911
/*#include <QColor>