[QGIS Commit] r14576 - in branches/raster-providers/src: core/raster providers/gdal

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Nov 12 15:03:27 EST 2010


Author: rblazek
Date: 2010-11-12 12:03:27 -0800 (Fri, 12 Nov 2010)
New Revision: 14576

Modified:
   branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
   branches/raster-providers/src/providers/gdal/qgsgdalprovider.cpp
Log:
gdal provider working

Modified: branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- branches/raster-providers/src/core/raster/qgsrasterlayer.cpp	2010-11-12 19:52:56 UTC (rev 14575)
+++ branches/raster-providers/src/core/raster/qgsrasterlayer.cpp	2010-11-12 20:03:27 UTC (rev 14576)
@@ -3291,6 +3291,8 @@
     mDrawingStyle = SingleBandGray;  //sensible default
     mGrayBandName = bandName( 1 );
   }
+  // Debug
+  //mDrawingStyle = SingleBandPseudoColor;
 
   // Store timestamp
   // TODO move to provider
@@ -5629,12 +5631,13 @@
   mNumCurrentImageRows = ySize;
   QgsDebugMsg( "alloc " + QString::number( size * xSize * ySize) );
   mCurrentGDALData = VSIMalloc( size * xSize * ySize );
-  double *p = (double *)mCurrentGDALData;
-  for ( int i = 0; i  < xSize * ySize; i++ ) 
-  {
-    *p = mDataProvider->noDataValue();
-    p++;
-  }
+  // TODO just debug - attention type width -> crash
+  //double *p = (double *)mCurrentGDALData;
+  //for ( int i = 0; i  < xSize * ySize; i++ ) 
+  //{
+    //*p = mDataProvider->noDataValue();
+    //p++;
+  //}
   //CPLErr myErr = GDALRasterIO( mRasterBand, GF_Read, mViewPort->rectXOffset,
   //                             mViewPort->rectYOffset + mCurrentRow, mViewPort->clippedWidth, rasterYSize,
   //                             mCurrentGDALData, xSize, ySize, type, 0, 0 );

Modified: branches/raster-providers/src/providers/gdal/qgsgdalprovider.cpp
===================================================================
--- branches/raster-providers/src/providers/gdal/qgsgdalprovider.cpp	2010-11-12 19:52:56 UTC (rev 14575)
+++ branches/raster-providers/src/providers/gdal/qgsgdalprovider.cpp	2010-11-12 20:03:27 UTC (rev 14576)
@@ -192,6 +192,7 @@
     mNoDataValue = myNoDataValue;
     mValidNoDataValue = true;
   }
+  QgsDebugMsg( QString("mNoDataValue = %1").arg ( mNoDataValue ) ); 
 
   mValid = true;
   QgsDebugMsg( "end" );
@@ -392,12 +393,11 @@
   myMemGeoTransform[2] = 0; /* rotation, 0 if image is "north up" */
   myMemGeoTransform[3] = theExtent.yMaximum(); /* top left y */
   myMemGeoTransform[4] = 0; /* rotation, 0 if image is "north up" */
-  myMemGeoTransform[5] = theExtent.height()/thePixelHeight; /* n-s pixel resolution */
+  myMemGeoTransform[5] = -1. *  theExtent.height()/thePixelHeight; /* n-s pixel resolution */
 
   double myGeoTransform[6];
   GDALGetGeoTransform( mGdalDataset, myGeoTransform );
-  GDALSetGeoTransform( myGdalMemDataset, myGeoTransform );
-  GDALGetGeoTransform( myGdalMemDataset, myMemGeoTransform );
+  GDALSetGeoTransform( myGdalMemDataset, myMemGeoTransform );
 
   for ( int i = 0 ; i < 6; i++ ) 
   {
@@ -421,7 +421,7 @@
   myWarpOptions->pfnProgress = GDALTermProgress;   
 
   QgsDebugMsg ( "src wkt: " +  QString (GDALGetProjectionRef(mGdalDataset) ) ); 
-  QgsDebugMsg ( "dst wkt: " +  QString ( GDALGetProjectionRef(myGdalMemDataset) ) ); 
+  QgsDebugMsg ( "dst wkt: " +  QString (GDALGetProjectionRef(myGdalMemDataset) ) ); 
   myWarpOptions->pTransformerArg = 
       GDALCreateGenImgProjTransformer( 
         mGdalDataset, 
@@ -430,13 +430,16 @@
         GDALGetProjectionRef(myGdalMemDataset), 
         FALSE, 0.0, 1 
       );
+  CPLAssert( myWarpOptions->pTransformerArg  != NULL); 
   myWarpOptions->pfnTransformer = GDALGenImgProjTransform;
 
+
   GDALWarpOperation myOperation;
 
   myOperation.Initialize( myWarpOptions );
   CPLErrorReset();
-  CPLErr myErr = myOperation.ChunkAndWarpImage( 0, 0, thePixelWidth, thePixelHeight ); 
+  CPLErr myErr;
+  myErr = myOperation.ChunkAndWarpImage( 0, 0, thePixelWidth, thePixelHeight ); 
   if ( myErr != CPLE_None )
   {
     QMessageBox::warning( 0, QObject::tr( "Warning" ),
@@ -448,14 +451,11 @@
   GDALDestroyGenImgProjTransformer( myWarpOptions->pTransformerArg );
   GDALDestroyWarpOptions( myWarpOptions );
 
-  // this works 
-  //myErr = GDALRasterIO( myGdalBand, GF_Read, 0, 0, 
-  //  xSize(), ySize(),
-  //  theBlock,  thePixelWidth, thePixelHeight,
-  //  myGdalDataType, 0, 0 ); 
+  // without this it does not work (data not written), 
+  GDALFlushCache  (  myGdalMemDataset );
+  // with this it is causing crash ???
+  GDALClose( myGdalMemDataset ); 
 
-  //GDALClose( myGdalMemDataset ); 
-
 }
 
 double  QgsGdalProvider::noDataValue() const {



More information about the QGIS-commit mailing list