[Thuban-commits] r2881 - in trunk/thuban: . libraries/thuban test

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 10 09:14:15 CEST 2009


Author: dpinte
Date: 2009-07-10 09:14:14 +0200 (Fri, 10 Jul 2009)
New Revision: 2881

Modified:
   trunk/thuban/ChangeLog
   trunk/thuban/libraries/thuban/gdalwarp.cpp
   trunk/thuban/test/test_baserenderer.py
Log:
2009-07-09 Didrik Pinte <dpinte at dipole-consulting.com>

  * libraries/thuban/gdalwarp.py : fixing bug loading files with GDAL thanks to
    Evan Rouault
  * test/test_baserenderer.py : added a test replicating the problem loading 
    files with GDAL



Modified: trunk/thuban/ChangeLog
===================================================================
--- trunk/thuban/ChangeLog	2009-06-29 14:06:24 UTC (rev 2880)
+++ trunk/thuban/ChangeLog	2009-07-10 07:14:14 UTC (rev 2881)
@@ -1,3 +1,10 @@
+2009-07-09 Didrik Pinte <dpinte at dipole-consulting.com>
+
+  * libraries/thuban/gdalwarp.py : fixing bug loading files with GDAL thanks to
+    Evan Rouault
+  * test/test_baserenderer.py : added a test replicating the problem loading 
+    files with GDAL
+
 2009-06-29 Didrik Pinte <dpinte at dipole-consulting.com>
 
   * Thuban/UI/resource.py : freezing support improved

Modified: trunk/thuban/libraries/thuban/gdalwarp.cpp
===================================================================
--- trunk/thuban/libraries/thuban/gdalwarp.cpp	2009-06-29 14:06:24 UTC (rev 2880)
+++ trunk/thuban/libraries/thuban/gdalwarp.cpp	2009-07-10 07:14:14 UTC (rev 2881)
@@ -146,6 +146,7 @@
 #include "gdal.h"
 #include "gdal_alg.h"
 #include "gdal_priv.h"
+
 #include "gdalwarper.h"
 #include "cpl_string.h"
 #include "ogr_srs_api.h"
@@ -160,6 +161,11 @@
 #define OPTS_ALPHA 2
 #define OPTS_INVERT_MASK_BITS 4
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 CPL_CVSID("$Id$");
 
 static GDALDatasetH 
@@ -205,9 +211,7 @@
 /************************************************************************/
 /*                            initgdalwarp                              */
 /************************************************************************/
-#ifdef __cplusplus
-extern "C"
-#endif
+
 void initgdalwarp(void)
 {
     PyObject * shapelib = NULL;
@@ -232,7 +236,7 @@
     char *pszResult = NULL;
 
     CPLErrorReset();
-
+    
     hSRS = OSRNewSpatialReference( NULL );
     if( OSRSetFromUserInput( hSRS, pszUserInput ) == OGRERR_NONE )
         OSRExportToWkt( hSRS, &pszResult );
@@ -244,8 +248,7 @@
                   pszUserInput );
         exit( 1 );
     }
-#endif
-    
+#endif    
     OSRDestroySpatialReference( hSRS );
 
     return pszResult;
@@ -705,6 +708,7 @@
 /* -------------------------------------------------------------------- */
 /*      Open source dataset.                                            */
 /* -------------------------------------------------------------------- */
+
     hSrcDS = GDALOpen( pszSrcFilename, GA_ReadOnly );
     
     if( hSrcDS == NULL )
@@ -1017,8 +1021,11 @@
 
     //GDALDumpOpenDatasets( stderr );
 
-    GDALDestroyDriverManager();
-
+	// Do not call GDALDestroyDriverManager as we will most probably use 
+	// ProjectRasterFile more than once.
+	// Thanks to Evan Rouault / 2009-07-09
+    //GDALDestroyDriverManager();
+	
 #   if PY_VERSION_HEX >=0x02040000
         if (savedlocale)
 	    setlocale( LC_NUMERIC, savedlocale);
@@ -1107,8 +1114,10 @@
                                          NULL, pszTargetSRS, 
                                          TRUE, 1000.0, nOrder );
 
-    if( hTransformArg == NULL )
+    if( hTransformArg == NULL ) {
+        GDALClose( hSrcDS );
         return NULL;
+	}
 
     //
     // This could happen if the proj library didn't load correctly
@@ -1123,20 +1132,22 @@
 /* -------------------------------------------------------------------- */
 /*      Get approximate output definition.                              */
 /* -------------------------------------------------------------------- */
+	double adfExtent[4];
     if( GDALSuggestedWarpOutput( hSrcDS, 
                                  GDALGenImgProjTransform, hTransformArg, 
-                                 adfDstGeoTransform, &nPixels, &nLines )
-        != CE_None )
+                                 adfDstGeoTransform, &nPixels, &nLines)
+        != CE_None ) {
+		GDALClose( hSrcDS );
         return NULL;
-
-    GDALDestroyGenImgProjTransformer( hTransformArg );
-
+	}
+	
+	GDALDestroyGenImgProjTransformer( hTransformArg );
+	
 /* -------------------------------------------------------------------- */
 /*      Did the user override some parameters?                          */
 /* -------------------------------------------------------------------- */
     if( dfXRes != 0.0 && dfYRes != 0.0 )
     {
-        CPLAssert( nForcePixels == 0 && nForceLines == 0 );
         if( dfMinX == 0.0 && dfMinY == 0.0 && dfMaxX == 0.0 && dfMaxY == 0.0 )
         {
             dfMinX = adfDstGeoTransform[0];
@@ -1157,10 +1168,10 @@
     {
         if( dfMinX == 0.0 && dfMinY == 0.0 && dfMaxX == 0.0 && dfMaxY == 0.0 )
         {
-            dfMinX = adfDstGeoTransform[0];
-            dfMaxX = adfDstGeoTransform[0] + adfDstGeoTransform[1] * nPixels;
-            dfMaxY = adfDstGeoTransform[3];
-            dfMinY = adfDstGeoTransform[3] + adfDstGeoTransform[5] * nLines;
+			dfMinX = adfDstGeoTransform[0];
+			dfMaxX = adfDstGeoTransform[0] + adfDstGeoTransform[1] * nPixels;
+			dfMaxY = adfDstGeoTransform[3];
+			dfMinY = adfDstGeoTransform[3] + adfDstGeoTransform[5] * nLines;
         }
 
         dfXRes = (dfMaxX - dfMinX) / nForcePixels;
@@ -1183,6 +1194,7 @@
         nPixels = (int) ((dfMaxX - dfMinX + (dfXRes/2.0)) / dfXRes);
         nLines = (int) ((dfMaxY - dfMinY + (dfYRes/2.0)) / dfYRes);
 
+
         adfDstGeoTransform[0] = dfMinX;
         adfDstGeoTransform[3] = dfMaxY;
     }
@@ -1204,9 +1216,9 @@
     hDstDS = GDALCreate( hDriver, pszFilename, nPixels, nLines, 
                          nDstBandCount, eDT, papszCreateOptions );
     
-    if( hDstDS == NULL )
+    if( hDstDS == NULL ) {
         return NULL;
-
+	}
 /* -------------------------------------------------------------------- */
 /*      Write out the projection definition.                            */
 /* -------------------------------------------------------------------- */
@@ -1232,7 +1244,10 @@
     hCT = GDALGetRasterColorTable( GDALGetRasterBand(hSrcDS,1) );
     if( hCT != NULL )
         GDALSetRasterColorTable( GDALGetRasterBand(hDstDS,1), hCT );
-
+	
     return hDstDS;
 }
     
+#ifdef __cplusplus
+}
+#endif

Modified: trunk/thuban/test/test_baserenderer.py
===================================================================
--- trunk/thuban/test/test_baserenderer.py	2009-06-29 14:06:24 UTC (rev 2880)
+++ trunk/thuban/test/test_baserenderer.py	2009-07-10 07:14:14 UTC (rev 2881)
@@ -344,7 +344,34 @@
             img_data = renderer.projected_raster_layer(layer, "", "", 
                             (-24, 65, -23, 66), [0, 0], (20, 20), opts)
             self.assertEquals(img_data, data)
-
+        
+    def test_projected_raster_broken(self):
+        """
+        Until using gdal 1.5, we could load more than one file with gdal 
+        without problems. After 1.5 we had problems having this message in
+        the stdout when loading a second file with GDAL:
+        
+        ERROR 4: `../Data/iceland/island.tif' not recognised as a 
+                supported file format.
+        
+        This was only after a call to ProjectRasterFile.
+        
+        If this test passes without IOException, the problem will be solved.
+        """
+        tiffile= os.path.join("..", "Data", "iceland",
+                                             "island.tif")
+        projection = "+proj=latlong +to_meter=0.017453 +ellps=clrk66"
+        new_projection = "+proj=utm +zone=27 +ellps=clrk66"
+        
+        from osgeo.gdal import Open
+        t1 =  RasterLayer("rast",tiffile)
+        v = ProjectRasterFile(tiffile,projection, new_projection, \
+                            (322003.1320390497, 6964094.1718668584,\
+                             876022.1891829354, 7460469.6276894147), \
+                            [0, 0], (10,5), 1)
+        v =None
+        t2 = RasterLayer("rast3", tiffile)
+        
     def test_projected_raster_decimalcommalocale(self):
         if not Thuban.Model.resource.has_gdal_support():
             raise support.SkipTest(Thuban.Model.resource.gdal_support_status)



More information about the Thuban-commits mailing list