[mapserver-commits] r9825 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Sat Feb 20 16:17:22 EST 2010


Author: jimk
Date: 2010-02-20 16:17:21 -0500 (Sat, 20 Feb 2010)
New Revision: 9825

Modified:
   trunk/mapserver/mapprimitive.c
   trunk/mapserver/mapserver.h
   trunk/mapserver/maptemplate.c
Log:
Fix #3170. Ignore GEOS errors when trying to buffer a degenerate
shape when processing a [shpxy] tag in a template. Since degenerate shape 
parts are skipped later in processShpxyTag so they won't be emitted.


Modified: trunk/mapserver/mapprimitive.c
===================================================================
--- trunk/mapserver/mapprimitive.c	2010-02-20 20:40:10 UTC (rev 9824)
+++ trunk/mapserver/mapprimitive.c	2010-02-20 21:17:21 UTC (rev 9825)
@@ -1993,3 +1993,21 @@
   snprintf(buffer, buffer_length, format, point->x, point->y);
 #endif
 }
+
+/* Returns true if a shape contains only degenerate parts */
+int msIsDegenerateShape(shapeObj *shape)
+{
+  int i;
+  int non_degenerate_parts = 0;
+  for(i=0; i<shape->numlines; i++) { /* e.g. part */
+	
+    /* skip degenerate parts, really should only happen with pixel output */ 
+    if((shape->type == MS_SHAPE_LINE && shape->line[i].numpoints < 2) ||
+       (shape->type == MS_SHAPE_POLYGON && shape->line[i].numpoints < 3))
+     continue;
+	
+    non_degenerate_parts++;
+  }
+  return( non_degenerate_parts == 0 );
+}
+

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2010-02-20 20:40:10 UTC (rev 9824)
+++ trunk/mapserver/mapserver.h	2010-02-20 21:17:21 UTC (rev 9825)
@@ -1715,6 +1715,7 @@
                                            char *buffer, int buffer_length);
 MS_DLL_EXPORT void msPointToFormattedString(pointObj *point, const char*format,
                                            char *buffer, int buffer_length);
+MS_DLL_EXPORT int msIsDegenerateShape(shapeObj *shape);
 
 MS_DLL_EXPORT void msMergeRect(rectObj *a, rectObj *b);
 MS_DLL_EXPORT double msDistancePointToPoint(pointObj *a, pointObj *b);

Modified: trunk/mapserver/maptemplate.c
===================================================================
--- trunk/mapserver/maptemplate.c	2010-02-20 20:40:10 UTC (rev 9824)
+++ trunk/mapserver/maptemplate.c	2010-02-20 21:17:21 UTC (rev 9825)
@@ -1964,12 +1964,16 @@
       if(buffer != 0 && bufferUnits == MS_PIXELS) {
         shapeObj *bufferShape=NULL;
 
-	bufferShape = msGEOSBuffer(&tShape, buffer);
-	if(!bufferShape) return(MS_FAILURE); /* buffer failed */
-	msFreeShape(&tShape); /* avoid memory leak */
-	msCopyShape(bufferShape, &tShape);
-	msFreeShape(bufferShape);
-      }
+        bufferShape = msGEOSBuffer(&tShape, buffer);
+        if(!bufferShape) {
+          if(!msIsDegenerateShape(&tShape)) /* If shape is degenerate this is expected. */
+            return(MS_FAILURE); /* buffer failed */
+        } else {
+          msFreeShape(&tShape); /* avoid memory leak */
+          msCopyShape(bufferShape, &tShape);
+          msFreeShape(bufferShape);
+        }
+      } 
 #endif
 
     } else if(projectionString) {



More information about the mapserver-commits mailing list