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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Oct 16 01:27:07 CEST 2006


Author: bernhard
Date: 2006-10-16 01:27:05 +0200 (Mon, 16 Oct 2006)
New Revision: 2712

Modified:
   trunk/thuban/ChangeLog
   trunk/thuban/Thuban/UI/renderer.py
   trunk/thuban/libraries/thuban/gdalwarp.cpp
   trunk/thuban/test/test_baserenderer.py
Log:
* Thuban/UI/renderer.py: Added module variable verbose and
added verbose output before doing a raster projection.
Minor: Added (c) year 2006.

* test/test_baserenderer.py: Added new function
test_projected_raster_decimalcommalocale()
Added new author Bernhard Reiter and new copyright year 2006.

* libraries/thuban/gdalwarp.cpp(ProjectRasterFile): Adding
switching to LC_NUMERIC "C" and back before calling GDAL functions -
only #if python >=2.4 .


Modified: trunk/thuban/ChangeLog
===================================================================
--- trunk/thuban/ChangeLog	2006-10-10 10:30:54 UTC (rev 2711)
+++ trunk/thuban/ChangeLog	2006-10-15 23:27:05 UTC (rev 2712)
@@ -1,3 +1,17 @@
+2006-10-15 Bernhard Reiter <bernhard at intevation.de>
+
+	* Thuban/UI/renderer.py: Added module variable verbose and
+	added verbose output before doing a raster projection.
+	Minor: Added (c) year 2006.
+
+	* test/test_baserenderer.py: Added new function
+	test_projected_raster_decimalcommalocale()
+	Added new author Bernhard Reiter and new copyright year 2006.
+
+	* libraries/thuban/gdalwarp.cpp(ProjectRasterFile): Adding
+	switching to LC_NUMERIC "C" and back before calling GDAL functions -
+	only #if python >=2.4 .
+
 2006-10-10 Didrik Pinte <dpinte at itae.be>
 
 	Win32 build updates 
@@ -31,7 +45,7 @@
 	with setlocale().
 
 	* test/runtests.py: Added new option ---setdecimalcommalocale
-   	to run all tests with an LC_NUMERIC that uses comma as decimal_point.
+	to run all tests with an LC_NUMERIC that uses comma as decimal_point.
 	Minor: Added (c) year 2006. Fixed typo in a docstring.
 
 	* test/test_transientdb.py: Minor: Added (c) year 2006. Fixed typo in

Modified: trunk/thuban/Thuban/UI/renderer.py
===================================================================
--- trunk/thuban/Thuban/UI/renderer.py	2006-10-10 10:30:54 UTC (rev 2711)
+++ trunk/thuban/Thuban/UI/renderer.py	2006-10-15 23:27:05 UTC (rev 2712)
@@ -1,4 +1,4 @@
-# Copyright (c) 2001-2005 by Intevation GmbH
+# Copyright (c) 2001-2006 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh at intevation.de> (2001-2003)
 # Jonathan Coles <jonathan at intevation.de> (2003)
@@ -47,6 +47,7 @@
 if Thuban.Model.resource.has_gdal_support():
     from gdalwarp import ProjectRasterFile
 
+verbose = 0 # whether to talk more on stdout
 
 # Map the strings used for the format parameter of the draw_raster_data
 # method to the appropriate wxWindows constants
@@ -127,6 +128,11 @@
                 options = options & ~2 # ALPHA_MASK not supported
 
             try:
+                if verbose > 0:
+                    print "doing ProjectRasterFile '%s' -> '%s'" % \
+                                (srcProj, dstProj)
+                    print "extents:", extents, "resolution:", resolution
+                    print "dimensions:", dimensions, "options:", options
                 ret = ProjectRasterFile(layer.GetImageFilename(),
                                         srcProj, dstProj,
                                         extents, resolution, dimensions,

Modified: trunk/thuban/libraries/thuban/gdalwarp.cpp
===================================================================
--- trunk/thuban/libraries/thuban/gdalwarp.cpp	2006-10-10 10:30:54 UTC (rev 2711)
+++ trunk/thuban/libraries/thuban/gdalwarp.cpp	2006-10-15 23:27:05 UTC (rev 2712)
@@ -139,6 +139,8 @@
  *
  */
 
+#include <locale.h>
+
 #include <Python.h>
 
 #include "gdal.h"
@@ -629,6 +631,8 @@
     unsigned int        masklen = 0;
     int                 options = 0;
 
+    char * 		savedlocale = NULL;
+
     GDALWarpOperation oWO;
     GDALWarpOptions *psWO = NULL;
 
@@ -657,6 +661,19 @@
 
     pszSrcFilename = PyString_AsString( filename );
 
+#   if PY_VERSION_HEX >=0x02040000
+	/* python before 2.4 only called modules with LC_NUMERIC "C". 
+	 * so we only need to act for >=2.4 */
+        savedlocale = setlocale( LC_NUMERIC, NULL );
+        if (! setlocale( LC_NUMERIC, "C" ))
+        {
+            PyErr_SetString(PyExc_ValueError, 
+	    	"Could not switch to locale \"C\".");
+	    /* did not open anything, so no need to jump to getOut */
+	    return NULL;
+        }
+#   endif
+
     pszSourceSRS = SanitizeSRS( PyString_AsString( srcImageArgs ) );
     pszTargetSRS = SanitizeSRS( PyString_AsString( dstImageArgs ) );
 
@@ -995,6 +1012,11 @@
     //GDALDumpOpenDatasets( stderr );
 
     GDALDestroyDriverManager();
+
+#   if PY_VERSION_HEX >=0x02040000
+        if (savedlocale)
+	    setlocale( LC_NUMERIC, savedlocale);
+#   endif
     
     if ( !err && CPLGetLastErrorNo() )
     {

Modified: trunk/thuban/test/test_baserenderer.py
===================================================================
--- trunk/thuban/test/test_baserenderer.py	2006-10-10 10:30:54 UTC (rev 2711)
+++ trunk/thuban/test/test_baserenderer.py	2006-10-15 23:27:05 UTC (rev 2712)
@@ -1,6 +1,7 @@
-# Copyright (C) 2003, 2005 by Intevation GmbH
+# Copyright (C) 2003, 2005, 2006 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh at intevation.de>
+# Bernhard Reiter <bernhard at intevation.de>
 #
 # This program is free software under the GPL (>=v2)
 # Read the file COPYING coming with the software for details.
@@ -14,7 +15,9 @@
 import os
 import binascii
 import unittest
+import locale
 
+import localessupport
 from mockgeo import SimpleShapeStore
 import support
 support.initthuban()
@@ -342,6 +345,34 @@
                             (-24, 65, -23, 66), [0, 0], (20, 20), opts)
             self.assertEquals(img_data, data)
 
+    def test_projected_raster_decimalcommalocale(self):
+        if not Thuban.Model.resource.has_gdal_support():
+            raise support.SkipTest("No gdal support")
+
+        def _do_project_island():
+            """Project island.tif and return result."""
+            layer = RasterLayer("raster layer",
+                                os.path.join("..", "Data", "iceland",
+                                             "island.tif"))
+
+            dc = MockDC(size = (10, 5))
+            renderer = SimpleRenderer(dc, map, 34, (800, 2250))
+
+            projection = "+proj=latlong +to_meter=0.017453 +ellps=clrk66"
+            new_projection = "+proj=utm +zone=27 +ellps=clrk66"
+
+            return renderer.projected_raster_layer(layer, \
+                            projection, new_projection, \
+                            (322003.1320390497, 6964094.1718668584, 876022.1891829354, 7460469.6276894147), [0, 0], (10,5), 1)
+
+        oldlocale = localessupport.setdecimalcommalocale()
+        img_data2 = _do_project_island()
+        locale.setlocale(locale.LC_NUMERIC, oldlocale)
+
+        img_data1 = _do_project_island()
+
+        self.assertEquals(img_data1, img_data2)
+
     def test_raster_no_projection(self):
         """Test BaseRenderer with raster layer and no projections
 



More information about the Thuban-commits mailing list