]> granicus.if.org Git - postgis/commitdiff
st_isclosed() doesn't return false for unclosed POLYGONS only LINESTRINGS (#1756)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 20 Apr 2012 03:23:47 +0000 (03:23 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 20 Apr 2012 03:23:47 +0000 (03:23 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9650 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h.in
liblwgeom/liblwgeom_internal.h
liblwgeom/lwgeom.c
liblwgeom/lwline.c
liblwgeom/lwpoly.c

index 76326a9ba6940c586cc8727cdbf482d45f867f1f..70cd275e145dc2176fe5519480bd1cb74be62c29 100644 (file)
@@ -1084,11 +1084,6 @@ extern void lwpoly_reverse(LWPOLY *poly);
 extern void lwtriangle_reverse(LWTRIANGLE *triangle);
 extern char* lwgeom_summary(const LWGEOM *lwgeom, int offset);
 extern char* lwpoint_to_latlon(const LWPOINT *p, const char *format);
-extern int lwline_is_closed(const LWLINE *line);
-extern int lwcircstring_is_closed(const LWCIRCSTRING *curve);
-extern int lwcompound_is_closed(const LWCOMPOUND *curve);
-extern int lwpsurface_is_closed(const LWPSURFACE *psurface);
-extern int lwtin_is_closed(const LWTIN *tin);
 
 /**
 * Ensure the outer ring is clockwise oriented and all inner rings 
index 37c6e1e620c01e141c669012460bf60d98d541e6..368bfcdd102537f18c69b9140177fb99907dbe66 100644 (file)
@@ -335,6 +335,16 @@ LWGEOM* lwline_remove_repeated_points(LWLINE *in);
 LWGEOM* lwcollection_remove_repeated_points(LWCOLLECTION *in);
 LWGEOM* lwpoly_remove_repeated_points(LWPOLY *in);
 
+/*
+* Closure test
+*/
+int lwline_is_closed(const LWLINE *line);
+int lwpoly_is_closed(const LWPOLY *poly);
+int lwcircstring_is_closed(const LWCIRCSTRING *curve);
+int lwcompound_is_closed(const LWCOMPOUND *curve);
+int lwpsurface_is_closed(const LWPSURFACE *psurface);
+int lwtin_is_closed(const LWTIN *tin);
+
 
 /*
  * Split a line by a point and push components to the provided multiline.
index 98215aea81edd4529b07ad9930b6c755d52b4d5b..dc5f47d83b2d22578c331fb4631bd44d7a4742b7 100644 (file)
@@ -788,6 +788,8 @@ lwgeom_is_closed(const LWGEOM *geom)
        {
        case LINETYPE:
                return lwline_is_closed((LWLINE*)geom);
+       case POLYGONTYPE:
+               return lwpoly_is_closed((LWPOLY*)geom);
        case CIRCSTRINGTYPE:
                return lwcircstring_is_closed((LWCIRCSTRING*)geom);
        case COMPOUNDTYPE:
index 46061f3c7d2f9c6b242cfff47b8028839f9cc662..a902ea64adcf79ee8de210cd0374bef6626923c5 100644 (file)
@@ -427,7 +427,7 @@ lwline_remove_repeated_points(LWLINE *lwline)
 int
 lwline_is_closed(const LWLINE *line)
 {
-       if (FLAGS_GET_Z(line->type))
+       if (FLAGS_GET_Z(line->flags))
                return ptarray_isclosed3d(line->points);
 
        return ptarray_isclosed2d(line->points);
index aad9edb7fe6d597b48e4fd2c03736248fd33f289..1ec3c7ff1701c2a171e7d4f7487eaf59b42be8e3 100644 (file)
@@ -473,3 +473,31 @@ lwpoly_perimeter_2d(const LWPOLY *poly)
 
        return result;
 }
+
+int
+lwpoly_is_closed(const LWPOLY *poly)
+{
+       int i = 0;
+       
+       if ( poly->nrings == 0 ) 
+               return LW_TRUE;
+               
+       for ( i = 0; i < poly->nrings; i++ )
+       {
+               if (FLAGS_GET_Z(poly->flags))
+               {
+                       if ( ! ptarray_isclosed3d(poly->rings[i]) )
+                               return LW_FALSE;
+               }
+               else
+               {       
+                       if ( ! ptarray_isclosed2d(poly->rings[i]) )
+                               return LW_FALSE;
+               }
+       }
+       
+       return LW_TRUE;
+}
+
+
+