[mapserver-commits] r9558 - in trunk/mapserver: . mapscript/php3 mapscript/swiginc

svn at osgeo.org svn at osgeo.org
Fri Nov 20 13:11:51 EST 2009


Author: sdlime
Date: 2009-11-20 13:11:50 -0500 (Fri, 20 Nov 2009)
New Revision: 9558

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapgeos.c
   trunk/mapserver/mapscript/php3/mapscript_i.c
   trunk/mapserver/mapscript/php3/php_mapscript.c
   trunk/mapserver/mapscript/php3/php_mapscript.h
   trunk/mapserver/mapscript/swiginc/shape.i
   trunk/mapserver/mapserver.h
Log:
Added simplfy and topologyPreservingSimplify to MapScript (#2753)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2009-11-20 14:12:06 UTC (rev 9557)
+++ trunk/mapserver/HISTORY.TXT	2009-11-20 18:11:50 UTC (rev 9558)
@@ -14,6 +14,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- Added simplfy and topologyPreservingSimplify to MapScript (#2753)
+
 - Fixed Oracle FastCGI memory leak (#3187)
  
 - layer->project flag not being reset properly for drawquerylayer (#673 #2079)

Modified: trunk/mapserver/mapgeos.c
===================================================================
--- trunk/mapserver/mapgeos.c	2009-11-20 14:12:06 UTC (rev 9557)
+++ trunk/mapserver/mapgeos.c	2009-11-20 18:11:50 UTC (rev 9558)
@@ -667,6 +667,50 @@
 #endif
 }
 
+shapeObj *msGEOSSimplify(shapeObj *shape, double tolerance)
+{
+#ifdef USE_GEOS
+  GEOSGeom g1, g2; 
+
+  if(!shape) 
+    return NULL;
+
+  if(!shape->geometry) /* if no geometry for the shape then build one */
+    shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape);
+
+  g1 = (GEOSGeom) shape->geometry;
+  if(!g1) return NULL;
+  
+  g2 = GEOSSimplify(g1, tolerance);
+  return msGEOSGeometry2Shape(g2);
+#else
+  msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSTopologyPreservingSimplifier()");
+  return NULL;
+#endif
+}
+
+shapeObj *msGEOSTopologyPreservingSimplify(shapeObj *shape, double tolerance)
+{
+#ifdef USE_GEOS
+  GEOSGeom g1, g2; 
+
+  if(!shape) 
+    return NULL;
+
+  if(!shape->geometry) /* if no geometry for the shape then build one */
+    shape->geometry = (GEOSGeom) msGEOSShape2Geometry(shape);
+
+  g1 = (GEOSGeom) shape->geometry;
+  if(!g1) return NULL;
+  
+  g2 = GEOSTopologyPreserveSimplify(g1, tolerance);
+  return msGEOSGeometry2Shape(g2);
+#else
+  msSetError(MS_GEOSERR, "GEOS support is not available.", "msGEOSTopologyPreservingSimplifier()");
+  return NULL;
+#endif
+}
+
 shapeObj *msGEOSConvexHull(shapeObj *shape)
 {
 #ifdef USE_GEOS

Modified: trunk/mapserver/mapscript/php3/mapscript_i.c
===================================================================
--- trunk/mapserver/mapscript/php3/mapscript_i.c	2009-11-20 14:12:06 UTC (rev 9557)
+++ trunk/mapserver/mapscript/php3/mapscript_i.c	2009-11-20 18:11:50 UTC (rev 9558)
@@ -1080,6 +1080,18 @@
     return msGEOSBuffer(self, width);
 }
 
+
+shapeObj *shapeObj_simplify(shapeObj *self, double tolerance)
+{
+    return msGEOSSimplify(self, tolerance);
+}
+
+
+shapeObj *shapeObj_topologypreservingsimplify(shapeObj *self, double tolerance)
+{
+    return msGEOSTopologyPreservingSimplify(self, tolerance);
+}
+
  
 shapeObj *shapeObj_convexHull(shapeObj *self)
 {

Modified: trunk/mapserver/mapscript/php3/php_mapscript.c
===================================================================
--- trunk/mapserver/mapscript/php3/php_mapscript.c	2009-11-20 14:12:06 UTC (rev 9557)
+++ trunk/mapserver/mapscript/php3/php_mapscript.c	2009-11-20 18:11:50 UTC (rev 9558)
@@ -303,6 +303,8 @@
 
 /*geos related functions*/
 DLEXPORT void php3_ms_shape_buffer(INTERNAL_FUNCTION_PARAMETERS);
+DLEXPORT void php3_ms_shape_topologypreservingsimplify(INTERNAL_FUNCTION_PARAMETERS);
+DLEXPORT void php3_ms_shape_simplify(INTERNAL_FUNCTION_PARAMETERS);
 DLEXPORT void php3_ms_shape_convexhull(INTERNAL_FUNCTION_PARAMETERS);
 DLEXPORT void php3_ms_shape_boundary(INTERNAL_FUNCTION_PARAMETERS);
 DLEXPORT void php3_ms_shape_Union(INTERNAL_FUNCTION_PARAMETERS);
@@ -907,6 +909,8 @@
     {"getpointusingmeasure", php3_ms_shape_getpointusingmeasure, NULL},
     {"getmeasureusingpoint", php3_ms_shape_getmeasureusingpoint, NULL},
     {"buffer",          php3_ms_shape_buffer,           NULL},
+    {"topologypreservingsimplify", php3_ms_shape_topologypreservingsimplify, NULL},
+    {"simplify",        php3_ms_shape_simplify,         NULL},
     {"convexhull",      php3_ms_shape_convexhull,       NULL},
     {"boundary",        php3_ms_shape_boundary,         NULL},
     {"containsshape",   php3_ms_shape_contains_geos,    NULL},
@@ -12062,7 +12066,90 @@
 }
  
 
+
 /**********************************************************************
+ *                        shape->topologypreservingsimplify(tolerance)
+ **********************************************************************/
+/* {{{ proto int shape.topologypreservingsimplify(double tolerance)
+   Given a shape and a tolerance, return a simplified shape object using 
+   underlying GEOS library*/
+
+DLEXPORT void php3_ms_shape_topologypreservingsimplify(INTERNAL_FUNCTION_PARAMETERS)
+{
+    pval        *pThis, *pTolerance;
+    shapeObj     *self = NULL;
+    shapeObj    *return_shape = NULL;
+    HashTable   *list=NULL;
+
+    pThis = getThis();
+
+    if (pThis == NULL ||
+        getParameters(ht, 1, &pTolerance) !=SUCCESS)
+    {
+        WRONG_PARAM_COUNT;
+    }
+
+    convert_to_double(pTolerance);
+
+    self = (shapeObj *)_phpms_fetch_handle2(pThis, 
+                                            PHPMS_GLOBAL(le_msshape_ref),
+                                            PHPMS_GLOBAL(le_msshape_new),
+                                            list TSRMLS_CC);
+    if (self == NULL)
+      RETURN_FALSE;
+
+    return_shape = shapeObj_topologypreservingsimplify(self, 
+                                                     pTolerance->value.dval);
+    if (return_shape  == NULL)
+       RETURN_FALSE;
+        
+    _phpms_build_shape_object(return_shape, 
+                              PHPMS_GLOBAL(le_msshape_new), NULL,
+                              list, return_value TSRMLS_CC);
+}
+
+/**********************************************************************
+ *                        shape->simplify(tolerance)
+ **********************************************************************/
+/* {{{ proto int shape.simplify(double tolerance)
+   Given a shape and a tolerance, return a simplified shape object using 
+   underlying GEOS library*/
+
+DLEXPORT void php3_ms_shape_simplify(INTERNAL_FUNCTION_PARAMETERS)
+{
+    pval        *pThis, *pTolerance;
+    shapeObj     *self = NULL;
+    shapeObj    *return_shape = NULL;
+    HashTable   *list=NULL;
+
+    pThis = getThis();
+
+    if (pThis == NULL ||
+        getParameters(ht, 1, &pTolerance) !=SUCCESS)
+    {
+        WRONG_PARAM_COUNT;
+    }
+
+    convert_to_double(pTolerance);
+
+    self = (shapeObj *)_phpms_fetch_handle2(pThis, 
+                                            PHPMS_GLOBAL(le_msshape_ref),
+                                            PHPMS_GLOBAL(le_msshape_new),
+                                            list TSRMLS_CC);
+    if (self == NULL)
+      RETURN_FALSE;
+
+    return_shape = shapeObj_simplify(self, pTolerance->value.dval);
+    if (return_shape  == NULL)
+       RETURN_FALSE;
+        
+    _phpms_build_shape_object(return_shape, 
+                              PHPMS_GLOBAL(le_msshape_new), NULL,
+                              list, return_value TSRMLS_CC);
+}
+ 
+
+/**********************************************************************
  *                        shape->convexhull()
  **********************************************************************/
 /* {{{ proto int shape.convexhull()

Modified: trunk/mapserver/mapscript/php3/php_mapscript.h
===================================================================
--- trunk/mapserver/mapscript/php3/php_mapscript.h	2009-11-20 14:12:06 UTC (rev 9557)
+++ trunk/mapserver/mapscript/php3/php_mapscript.h	2009-11-20 18:11:50 UTC (rev 9558)
@@ -261,6 +261,8 @@
 pointObj        *shapeObj_getmeasureusingpoint(shapeObj *self, pointObj *point);
 
 shapeObj        *shapeObj_buffer(shapeObj *self, double width);
+shapeObj        *shapeObj_simplify(shapeObj *self, double tolerance);
+shapeObj        *shapeObj_topologypreservingsimplify(shapeObj *self, double tolerance);
 shapeObj        *shapeObj_convexHull(shapeObj *self);
 shapeObj        *shapeObj_boundary(shapeObj *self);
 int             shapeObj_contains_geos(shapeObj *self, shapeObj *poshape);

Modified: trunk/mapserver/mapscript/swiginc/shape.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/shape.i	2009-11-20 14:12:06 UTC (rev 9557)
+++ trunk/mapserver/mapscript/swiginc/shape.i	2009-11-20 18:11:50 UTC (rev 9558)
@@ -123,6 +123,12 @@
     %newobject buffer;
     shapeObj *buffer(double width) { return msGEOSBuffer(self, width); }
 
+    %newobject simplify;
+    shapeObj *simplify(double tolerance) { return msGEOSSimplify(self, tolerance); }
+
+    %newobject topologyPreservingSimplify;
+    shapeObj *topologyPreservingSimplify(double tolerance) { return msGEOSTopologyPreservingSimplify(self, tolerance); }
+
     %newobject convexHull;
     shapeObj *convexHull() { return msGEOSConvexHull(self); }
 

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2009-11-20 14:12:06 UTC (rev 9557)
+++ trunk/mapserver/mapserver.h	2009-11-20 18:11:50 UTC (rev 9558)
@@ -2346,6 +2346,8 @@
 MS_DLL_EXPORT char *msGEOSShapeToWKT(shapeObj *shape);
 
 MS_DLL_EXPORT shapeObj *msGEOSBuffer(shapeObj *shape, double width);
+MS_DLL_EXPORT shapeObj *msGEOSSimplify(shapeObj *shape, double tolerance);
+MS_DLL_EXPORT shapeObj *msGEOSTopologyPreservingSimplify(shapeObj *shape, double tolerance);
 MS_DLL_EXPORT shapeObj *msGEOSConvexHull(shapeObj *shape);
 MS_DLL_EXPORT shapeObj *msGEOSBoundary(shapeObj *shape);
 MS_DLL_EXPORT pointObj *msGEOSGetCentroid(shapeObj *shape);



More information about the mapserver-commits mailing list