Skip to content

Commit

Permalink
Allow passing TINs to GEOS functions.
Browse files Browse the repository at this point in the history
Closes #4378
Closes #392



git-svn-id: http://svn.osgeo.org/postgis/trunk@17396 b70326c6-7e19-0410-871a-916f4a2858ee
  • Loading branch information
Komzpa committed Apr 17, 2019
1 parent a142c08 commit 358dc24
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -88,6 +88,8 @@ PostGIS 3.0.0
- #4295, Allow GEOMETRYCOLLECTION in ST_Overlaps, ST_Contains, ST_ContainsProperly,
ST_Covers, ST_CoveredBy, ST_Crosses, ST_Touches, ST_Disjoint, ST_Relate,
ST_Equals (Esteban Zimányi)
- #4378, Allow passing TINs as input to GEOS-backed functions (Darafei
Praliaskouski)

PostGIS 2.5.0
2018/09/23
Expand Down
72 changes: 42 additions & 30 deletions liblwgeom/cunit/cu_geos.c
Expand Up @@ -20,49 +20,61 @@

#include "liblwgeom_internal.h"

static void test_geos_noop(void)
static void
test_geos_noop(void)
{
size_t i;

char *ewkt[] =
{
"POINT(0 0.2)",
"LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
"MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
"SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
"SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
"POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
"SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
"SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
"SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
"SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
"SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
"GEOMETRYCOLLECTION( LINESTRING (1 1, 2 2), POINT EMPTY, TRIANGLE ((0 0, 1 0, 1 1, 0 0)) )",
char *in_ewkt;
char *out_ewkt;
LWGEOM *geom_in;
LWGEOM *geom_out;

char *ewkt[] = {
"POINT(0 0.2)",
"LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
"MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
"SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
"SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
"POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
"SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
"SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
"SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
"SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
"SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
};


for ( i = 0; i < (sizeof ewkt/sizeof(char *)); i++ )
for (i = 0; i < (sizeof ewkt / sizeof(char *)); i++)
{
LWGEOM *geom_in, *geom_out;
char *in_ewkt;
char *out_ewkt;

in_ewkt = ewkt[i];
geom_in = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
geom_out = lwgeom_geos_noop(geom_in);
if ( ! geom_out ) {
// fprintf(stderr, "\nNull return from lwgeom_geos_noop with wkt: %s\n", in_ewkt);
lwgeom_free(geom_in);
continue;
}
CU_ASSERT_PTR_NOT_NULL_FATAL(geom_out);
out_ewkt = lwgeom_to_ewkt(geom_out);
if (strcmp(in_ewkt, out_ewkt))
fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
ASSERT_STRING_EQUAL(out_ewkt, in_ewkt);
lwfree(out_ewkt);
lwgeom_free(geom_out);
lwgeom_free(geom_in);
}

/* TINs become collections of Polygons */
in_ewkt = "TIN(((0 0, 1 1, 2 2, 0 0)), ((0 0, 1 1, 2 2, 0 0)))";
geom_in = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
geom_out = lwgeom_geos_noop(geom_in);
out_ewkt = lwgeom_to_ewkt(geom_out);
ASSERT_STRING_EQUAL(out_ewkt, "GEOMETRYCOLLECTION(POLYGON((0 0,1 1,2 2,0 0)),POLYGON((0 0,1 1,2 2,0 0)))");
lwfree(out_ewkt);
lwgeom_free(geom_in);
lwgeom_free(geom_out);

/* Empties disappear */
in_ewkt = "GEOMETRYCOLLECTION( LINESTRING (1 1, 2 2), POINT EMPTY, TRIANGLE ((0 0, 1 0, 1 1, 0 0)) )";
geom_in = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
geom_out = lwgeom_geos_noop(geom_in);
out_ewkt = lwgeom_to_ewkt(geom_out);
ASSERT_STRING_EQUAL(out_ewkt, "GEOMETRYCOLLECTION(LINESTRING(1 1,2 2),POLYGON((0 0,1 0,1 1,0 0)))");
lwfree(out_ewkt);
lwgeom_free(geom_in);
lwgeom_free(geom_out);
}

static void test_geos_linemerge(void)
Expand Down
16 changes: 16 additions & 0 deletions liblwgeom/lwgeom_geos.c
Expand Up @@ -454,9 +454,25 @@ LWGEOM2GEOS(const LWGEOM* lwgeom, uint8_t autofix)
}
if (!g) return NULL;
break;

case TRIANGLETYPE:
if (lwgeom_is_empty(lwgeom))
g = GEOSGeom_createEmptyPolygon();
else
{
LWTRIANGLE *lwt = (LWTRIANGLE *)lwgeom;
shell = ptarray_to_GEOSLinearRing(lwt->points, autofix);
if (!shell)
return NULL;
g = GEOSGeom_createPolygon(shell, NULL, 0);
}
if (!g)
return NULL;
break;
case MULTIPOINTTYPE:
case MULTILINETYPE:
case MULTIPOLYGONTYPE:
case TINTYPE:
case COLLECTIONTYPE:
if (lwgeom->type == MULTIPOINTTYPE)
geostype = GEOS_MULTIPOINT;
Expand Down

0 comments on commit 358dc24

Please sign in to comment.