From 7fba2e0c266bfc827ecf5f43e5c0c341bcbd02cd Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 20 Apr 2012 03:23:47 +0000 Subject: [PATCH] st_isclosed() doesn't return false for unclosed POLYGONS only LINESTRINGS (#1756) git-svn-id: http://svn.osgeo.org/postgis/trunk@9650 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/liblwgeom.h.in | 5 ----- liblwgeom/liblwgeom_internal.h | 10 ++++++++++ liblwgeom/lwgeom.c | 2 ++ liblwgeom/lwline.c | 2 +- liblwgeom/lwpoly.c | 28 ++++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 76326a9ba..70cd275e1 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -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 diff --git a/liblwgeom/liblwgeom_internal.h b/liblwgeom/liblwgeom_internal.h index 37c6e1e62..368bfcdd1 100644 --- a/liblwgeom/liblwgeom_internal.h +++ b/liblwgeom/liblwgeom_internal.h @@ -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. diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 98215aea8..dc5f47d83 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -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: diff --git a/liblwgeom/lwline.c b/liblwgeom/lwline.c index 46061f3c7..a902ea64a 100644 --- a/liblwgeom/lwline.c +++ b/liblwgeom/lwline.c @@ -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); diff --git a/liblwgeom/lwpoly.c b/liblwgeom/lwpoly.c index aad9edb7f..1ec3c7ff1 100644 --- a/liblwgeom/lwpoly.c +++ b/liblwgeom/lwpoly.c @@ -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; +} + + + -- 2.40.0