From 5635299b47e4742cc2ddb070147397a476ee1c9f Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Thu, 17 Sep 2009 02:33:49 +0000 Subject: [PATCH] Add lwgeom_is_empty() test git-svn-id: http://svn.osgeo.org/postgis/trunk@4507 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/liblwgeom.h | 6 ++++ liblwgeom/lwgeom.c | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/liblwgeom/liblwgeom.h b/liblwgeom/liblwgeom.h index 356135a84..1c9f84a03 100644 --- a/liblwgeom/liblwgeom.h +++ b/liblwgeom/liblwgeom.h @@ -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); diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index eb830cc60..879be127e 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -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 -- 2.49.0