]> granicus.if.org Git - postgis/commitdiff
Add lwgeom_is_empty() test
authorPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 17 Sep 2009 02:33:49 +0000 (02:33 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 17 Sep 2009 02:33:49 +0000 (02:33 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@4507 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h
liblwgeom/lwgeom.c

index 356135a84dda9df53c91c85bd0ad586f768fdaa6..1c9f84a03f39226eca55bc4178acc3b38b46892a 100644 (file)
@@ -1260,6 +1260,12 @@ extern int lwgeom_needs_bbox(LWGEOM *geom);
 extern int lwgeom_count_vertices(LWGEOM *geom);
 extern int32 lwgeom_npoints(uchar *serialized);
 
+/**
+* Return true of false depending on whether a geometry is an "empty" 
+* geometry (no vertices members)
+*/
+extern int lwgeom_is_empty(LWGEOM *geom);
+
 /* Is lwgeom1 geometrically equal to lwgeom2 ? */
 char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2);
 char ptarray_same(const POINTARRAY *pa1, const POINTARRAY *pa2);
index eb830cc60f98e3e9e5d600f3d7d034a81e6b834c..879be127e44c8ab26f87276a5dee2b928be19283 100644 (file)
@@ -1063,3 +1063,72 @@ int lwgeom_count_vertices(LWGEOM *geom)
        LWDEBUGF(3, "counted %d vertices", result);
        return result;
 }
+
+static int lwpoint_is_empty(LWPOINT *point)
+{
+       if( ! point->point || point->point->npoints == 0 )
+               return LW_TRUE;
+       return LW_FALSE;
+}
+
+static int lwline_is_empty(LWLINE *line)
+{
+       if( !line->points || line->points->npoints == 0 )
+               return LW_TRUE;
+       return LW_FALSE;
+}
+
+static int lwpoly_is_empty(LWPOLY *poly)
+{
+       if( !poly->rings || poly->nrings == 0 )
+               return LW_TRUE;
+       return LW_FALSE;
+}
+
+static int lwcircstring_is_empty(LWCIRCSTRING *circ)
+{
+       if( !circ->points || circ->points->npoints == 0 )
+               return LW_TRUE;
+       return LW_FALSE;
+}
+
+static int lwcollection_is_empty(LWCOLLECTION *col)
+{
+       if( !col->geoms || col->ngeoms == 0 )
+               return LW_TRUE;
+       return LW_FALSE;
+}
+
+int lwgeom_is_empty(LWGEOM *geom)
+{
+       int result = LW_FALSE;
+       LWDEBUGF(4, "got type %d", TYPE_GETTYPE(geom->type));
+       switch (TYPE_GETTYPE(geom->type))
+       {
+               case POINTTYPE:
+                       return lwpoint_is_empty((LWPOINT*)geom);
+                       break;
+               case LINETYPE:
+                       return lwline_is_empty((LWLINE*)geom);
+                       break;
+               case CIRCSTRINGTYPE:
+                       return lwcircstring_is_empty((LWCIRCSTRING*)geom);
+                       break;
+               case POLYGONTYPE:
+                       return lwpoly_is_empty((LWPOLY*)geom);
+                       break;
+               case MULTIPOINTTYPE:
+               case MULTILINETYPE:
+               case MULTIPOLYGONTYPE:
+               case COMPOUNDTYPE:
+               case MULTICURVETYPE:
+               case MULTISURFACETYPE:
+               case COLLECTIONTYPE:
+                       return lwcollection_is_empty((LWCOLLECTION *)geom);
+                       break;
+               default:
+                       lwerror("unsupported input geometry type: %d", TYPE_GETTYPE(geom->type));
+                       break;
+       }
+       return result;
+}
\ No newline at end of file