From: Sandro Santilli Date: Tue, 14 Feb 2012 13:31:22 +0000 (+0000) Subject: Make one-point lines convertible to GEOS, see #1543 X-Git-Tag: 2.0.0alpha5~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9662411e8bd0b7fbd8e79de7a70c3415ff91c87;p=postgis Make one-point lines convertible to GEOS, see #1543 git-svn-id: http://svn.osgeo.org/postgis/trunk@9184 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index a119418b9..deb5593f3 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -297,6 +297,13 @@ LWGEOM2GEOS(const LWGEOM *lwgeom) break; case LINETYPE: lwl = (LWLINE *)lwgeom; + if ( lwl->points->npoints == 1 ) { + /* Duplicate point, to make geos-friendly */ + lwl->points = ptarray_addPoint(lwl->points, + getPoint_internal(lwl->points, 0), + FLAGS_NDIMS(lwl->points->flags), + lwl->points->npoints); + } sq = ptarray_to_GEOSCoordSeq(lwl->points); g = GEOSGeom_createLineString(sq); if ( ! g ) @@ -322,6 +329,7 @@ LWGEOM2GEOS(const LWGEOM *lwgeom) else { sq = ptarray_to_GEOSCoordSeq(lwpoly->rings[0]); + /* TODO: check ring for being closed and fix if not */ shell = GEOSGeom_createLinearRing(sq); if ( ! shell ) return NULL; /*lwerror("LWGEOM2GEOS: exception during polygon shell conversion"); */ diff --git a/regress/tickets.sql b/regress/tickets.sql index 680661c51..615826466 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -590,6 +590,12 @@ select '#1042',round((st_ymax(st_minimumboundingcircle('LINESTRING(-1 -1, 1 1)') select '#1398a', st_astext(st_snaptogrid(st_project('POINT(-120 45)'::geography, 100000, radians(45))::geometry,0.000001)); select '#1398b', st_astext(st_snaptogrid(st_project('POINT(20 85)'::geography, 2000000, radians(0.1))::geometry,0.000001)); +-- #1543 +with inp as ( select +'0105000000020000000102000000040000000000000000000000000000000000000000000000000024400000000000000000000000000000244000000000000024400000000000000000000000000000000001020000000100000000000000000000000000000000000000' +::geometry as g ) +select '#1543', st_astext(g), st_astext(st_buildarea(g)) from inp; + -- Clean up DELETE FROM spatial_ref_sys; diff --git a/regress/tickets_expected b/regress/tickets_expected index 681279cc8..9b7c56774 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -67,10 +67,10 @@ NOTICE: No points or linestrings in input array #304 #304.a|21 #304.b|1 -#408|IllegalArgumentException: point array must contain 0 or >1 elements -NOTICE: IllegalArgumentException: point array must contain 0 or >1 elements +#408|Too few points in geometry component[2310341.45565344 4836396.65124226] +NOTICE: Too few points in geometry component at or near point 2310341.4556534393 4836396.6512422552 #408.1|f -#408.2|IllegalArgumentException: point array must contain 0 or >1 elements +#408.2|Too few points in geometry component[0 0] NOTICE: IllegalArgumentException: Invalid number of points in LinearRing found 2 - must be 0 or >= 4 #408.3|f #408.4|IllegalArgumentException: Invalid number of points in LinearRing found 2 - must be 0 or >= 4 @@ -196,3 +196,4 @@ ERROR: AddToPROJ4SRSCache: couldn't parse proj4 string: '': (null) #1042|2 #1398a|POINT(-119.093153 45.632669) #1398b|POINT(-160.137654 77.091608) +#1543|MULTILINESTRING((0 0,10 0,10 10,0 0),(0 0))|POLYGON((0 0,10 10,10 0,0 0))