From: Olivier Courtin Date: Fri, 10 May 2013 17:17:18 +0000 (+0000) Subject: cf #2318, add a optional additional version parameter in ST_ForceSFS, handle both... X-Git-Tag: 2.1.0beta2~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=629551694f2378d248457e5f27b86e22ec752cc1;p=postgis cf #2318, add a optional additional version parameter in ST_ForceSFS, handle both 1.1 and 1.2. default is 1.1 git-svn-id: http://svn.osgeo.org/postgis/trunk@11409 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/reference_editor.xml b/doc/reference_editor.xml index df4dd33c1..63ef413c0 100644 --- a/doc/reference_editor.xml +++ b/doc/reference_editor.xml @@ -547,6 +547,11 @@ GEOMETRYCOLLECTION( geometry ST_ForceSFS geometry geomA + + geometry ST_ForceSFS + geometry geomA + text version + diff --git a/liblwgeom/cunit/cu_force_sfs.c b/liblwgeom/cunit/cu_force_sfs.c index 40e940584..defdfdfe4 100644 --- a/liblwgeom/cunit/cu_force_sfs.c +++ b/liblwgeom/cunit/cu_force_sfs.c @@ -24,7 +24,7 @@ static void do_geom_test(char * in, char * out) char *tmp; g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE); - h = lwgeom_force_sfs(g); + h = lwgeom_force_sfs(g, 110); tmp = lwgeom_to_ewkt(h); if (strcmp(tmp, out)) fprintf(stderr, "\nIn: %s\nOut: %s\nExp: %s\n", @@ -40,7 +40,7 @@ static void do_type_test(char * in, int type) LWGEOM *g, *h; g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE); - h = lwgeom_force_sfs(g); + h = lwgeom_force_sfs(g, 110); if(h->type != type) fprintf(stderr, "\nIn: %s\nOut: %s\nExp: %s\n", in, lwtype_name(h->type), lwtype_name(type)); diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 886f63246..3fb60eebe 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -877,7 +877,7 @@ extern LWGEOM* lwgeom_simplify(const LWGEOM *igeom, double dist); * Force to use SFS 1.1 geometry type * (rather than SFS 1.2 and/or SQL/MM) */ -extern LWGEOM* lwgeom_force_sfs(LWGEOM *geom); +extern LWGEOM* lwgeom_force_sfs(LWGEOM *geom, int version); /*-------------------------------------------------------- diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 79ae7458f..0bff0198d 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -706,13 +706,39 @@ lwgeom_force_dims(const LWGEOM *geom, int hasz, int hasm) } LWGEOM* -lwgeom_force_sfs(LWGEOM *geom) +lwgeom_force_sfs(LWGEOM *geom, int version) { LWCOLLECTION *col; int i; LWGEOM *g; + /* SFS 1.2 version */ + if (version == 120) + { + switch(geom->type) + { + /* SQL/MM types */ + case CIRCSTRINGTYPE: + case COMPOUNDTYPE: + case CURVEPOLYTYPE: + case MULTICURVETYPE: + case MULTISURFACETYPE: + return lwgeom_segmentize(geom, 32); + + case COLLECTIONTYPE: + col = (LWCOLLECTION*)geom; + for ( i = 0; i < col->ngeoms; i++ ) + col->geoms[i] = lwgeom_force_sfs((LWGEOM*)col->geoms[i], version); + + return lwcollection_as_lwgeom((LWCOLLECTION*)geom); + + default: + return (LWGEOM *)geom; + } + } + + /* SFS 1.1 version */ switch(geom->type) { /* SQL/MM types */ @@ -748,7 +774,7 @@ lwgeom_force_sfs(LWGEOM *geom) case COLLECTIONTYPE: col = (LWCOLLECTION*)geom; for ( i = 0; i < col->ngeoms; i++ ) - col->geoms[i] = lwgeom_force_sfs((LWGEOM*)col->geoms[i]); + col->geoms[i] = lwgeom_force_sfs((LWGEOM*)col->geoms[i], version); return lwcollection_as_lwgeom((LWCOLLECTION*)geom); diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index a2f4a636d..a9de2a1f6 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -517,11 +517,24 @@ Datum LWGEOM_force_sfs(PG_FUNCTION_ARGS) GSERIALIZED *result; LWGEOM *lwgeom; LWGEOM *ogeom; + text * ver; + int version = 110; /* default version is SFS 1.1 */ POSTGIS_DEBUG(2, "LWGEOM_force_sfs called"); + /* If user specified version, respect it */ + if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) ) + { + ver = PG_GETARG_TEXT_P(1); + + if ( ! strncmp(VARDATA(ver), "1.2", 3)) + { + version = 120; + } + } + lwgeom = lwgeom_from_gserialized(geom); - ogeom = lwgeom_force_sfs(lwgeom); + ogeom = lwgeom_force_sfs(lwgeom, version); result = geometry_serialize(ogeom); diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in index 415d087ef..06313e3d4 100644 --- a/postgis/postgis.sql.in +++ b/postgis/postgis.sql.in @@ -1283,6 +1283,12 @@ CREATE OR REPLACE FUNCTION ST_ForceSFS(geometry) AS 'MODULE_PATHNAME', 'LWGEOM_force_sfs' LANGUAGE 'c' IMMUTABLE STRICT; +-- Availability: 2.1.0 +CREATE OR REPLACE FUNCTION ST_ForceSFS(geometry, version text) + RETURNS geometry + AS 'MODULE_PATHNAME', 'LWGEOM_force_sfs' + LANGUAGE 'c' IMMUTABLE STRICT; + -- Availability: 1.2.2 CREATE OR REPLACE FUNCTION ST_Expand(box3d,float8) RETURNS box3d