[Thuban-commits] r2808 - in branches/WIP-pyshapelib-Unicode/thuban: . Thuban/Model Thuban/UI libraries/thuban

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jan 16 16:37:59 CET 2008


Author: bramz
Date: 2008-01-16 16:37:58 +0100 (Wed, 16 Jan 2008)
New Revision: 2808

Modified:
   branches/WIP-pyshapelib-Unicode/thuban/ChangeLog
   branches/WIP-pyshapelib-Unicode/thuban/Thuban/Model/layer.py
   branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/viewport.py
   branches/WIP-pyshapelib-Unicode/thuban/libraries/thuban/wxproj.cpp
Log:
Forward porting trunk (2801:2807] to WIP-pyshapelib-Unicode branch. (previous merge was (2793:2801] instead of (2793:2793].

Modified: branches/WIP-pyshapelib-Unicode/thuban/ChangeLog
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/ChangeLog	2008-01-15 20:20:10 UTC (rev 2807)
+++ branches/WIP-pyshapelib-Unicode/thuban/ChangeLog	2008-01-16 15:37:58 UTC (rev 2808)
@@ -1,3 +1,26 @@
+2008-01-16   Bram de Greve <bram.degreve at bramz.net>
+
+	Forward porting trunk (2801:2807] to WIP-pyshapelib-Unicode branch.
+	The previous merge was erroneously indicated as (2793:2793],
+	that should have been (2793:2801].
+
+2008-01-09   Bernhard Reiter <bernhard at intevation.de>
+
+	Making Thuban robust against shapefiles which contain empty shapes.
+
+	* libraries/thuban/wxproj.cpp(project_points): setting an exception
+	now if called with no points at all. This is necessary, because 
+	the NULL pointer already indicates an error condition, thus it
+	cannot be used to indicate that there was no point in the result.
+	(draw_polygon_shape, (point_in_polygon_shape): stop if there 
+	are no points in the shape.
+	Propagate an error condition on failure of (project_points()).
+	(point_in_polygon_shape): shifted some lines around to allow
+	a cleanup jump point.
+
+	* Thuban/Model/layer.py, Thuban/UI/viewport.py: removed unused import
+	of  point_in_polygon_shape.
+
 2008-01-09   Bram de Greve <bram.degreve at bramz.net>
 
 	* forward ported trunk (2793:2793] to WIP-pyshapelib-Unicode

Modified: branches/WIP-pyshapelib-Unicode/thuban/Thuban/Model/layer.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/Thuban/Model/layer.py	2008-01-15 20:20:10 UTC (rev 2807)
+++ branches/WIP-pyshapelib-Unicode/thuban/Thuban/Model/layer.py	2008-01-16 15:37:58 UTC (rev 2808)
@@ -12,7 +12,7 @@
 import os
 import warnings
 
-from wxproj import point_in_polygon_shape, shape_centroid
+from wxproj import shape_centroid
 
 from Thuban import _
 

Modified: branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/viewport.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/viewport.py	2008-01-15 20:20:10 UTC (rev 2807)
+++ branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/viewport.py	2008-01-16 15:37:58 UTC (rev 2808)
@@ -18,7 +18,7 @@
 import sys
 from math import hypot
 
-from wxproj import point_in_polygon_shape, shape_centroid
+from wxproj import shape_centroid
 
 from Thuban.Model.messages import MAP_PROJECTION_CHANGED, \
      LAYER_PROJECTION_CHANGED, TITLE_CHANGED, \

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/thuban/wxproj.cpp
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/thuban/wxproj.cpp	2008-01-15 20:20:10 UTC (rev 2807)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/thuban/wxproj.cpp	2008-01-16 15:37:58 UTC (rev 2808)
@@ -185,7 +185,12 @@
 {
     int i;
     int num_points = num_vertices + num_parts - 1;
-    if (num_points <= 0) return NULL;
+    if (num_points <= 0) 
+    {
+        PyErr_SetString(PyExc_ValueError, 
+                "project_points() called without points");
+        return NULL;
+    }
 
     wxPoint* points = (wxPoint*)malloc(num_points * sizeof(wxPoint));
     if (!points)
@@ -373,6 +378,12 @@
 			    "Can't get shape %d from shapefile", shape_index);
     
     num_points = shape->nVertices + shape->nParts - 1;
+    if (num_points <= 0 )
+    {
+        /* printf("empty shape\n"); TODO: empty shape, should we log this? */
+        goto draw_polygon_shape_cleanup2;
+    }
+
     points = project_points(shape->nVertices, shape->nParts,
 			    shape->padfX, shape->padfY, shape->panPartStart,
 			    draw_info->forward, 
@@ -381,6 +392,9 @@
                             draw_info->scaley, 
                             draw_info->offx, 
                             draw_info->offy);
+    /* propagating the error if there is an exception pending */
+    if (!points) return NULL;
+
     dc = draw_info->dc;
 
     // If the shape is a polygon and a non-transparent brush was given,
@@ -421,6 +435,7 @@
     
     free(points);
 
+  draw_polygon_shape_cleanup2: 
     pyshapelib_api->SHPDestroyObject(shape);
 
     Py_INCREF(Py_None);
@@ -518,12 +533,22 @@
 	return PyErr_Format(PyExc_ValueError,
 			    "Can't get shape %d from shapefile", shape_index);
 
+    long scaled_px = (px << PREC_BITS) + 1, scaled_py = (py << PREC_BITS) + 1;
+
     num_points = shape->nVertices + shape->nParts - 1;
+    if (num_points <= 0 )
+    {
+        /* TODO: empty shape, should we log this somehow? */
+        result = -1;
+        goto point_in_polygon_shape_cleanup2;
+    }
+
     points = project_points(shape->nVertices, shape->nParts,
 			    shape->padfX, shape->padfY, shape->panPartStart,
 			    forward, inverse, scalex, scaley, offx, offy);
+    /* propagating the error if there is an exception pending */
+    if (!points) return NULL;
 
-    long scaled_px = (px << PREC_BITS) + 1, scaled_py = (py << PREC_BITS) + 1;
 
     cross_count = 0; linehit = 0;
     for (int part = 0; part < shape->nParts; part++)
@@ -565,8 +590,6 @@
 
     free(points);
 
-    pyshapelib_api->SHPDestroyObject(shape);
-
     if (filled)
     {
 	if (stroked && linehit)
@@ -585,6 +608,8 @@
 	result = 0;
 		
 
+  point_in_polygon_shape_cleanup2:
+    pyshapelib_api->SHPDestroyObject(shape);
     return PyInt_FromLong(result);
 }
 



More information about the Thuban-commits mailing list