From f283252a45ebcb2a304f1dd667163cda5befbd1b Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 31 Oct 2014 00:01:52 +0000 Subject: [PATCH] #2938 gml export of curvepolygons fix git-svn-id: http://svn.osgeo.org/postgis/trunk@13115 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/cunit/cu_out_gml.c | 4 +- liblwgeom/lwout_gml.c | 240 ++++++++++++++++++----------------- 2 files changed, 130 insertions(+), 114 deletions(-) diff --git a/liblwgeom/cunit/cu_out_gml.c b/liblwgeom/cunit/cu_out_gml.c index 547532389..56665679b 100644 --- a/liblwgeom/cunit/cu_out_gml.c +++ b/liblwgeom/cunit/cu_out_gml.c @@ -561,7 +561,9 @@ static void out_gml_test_geoms(void) "CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0))", "-2 0 -1 -1 0 0 1 -1 2 0 0 2 -2 0-1 0 0 0.5 1 0 0 1 -1 0", NULL, 1, 0 ); - + do_gml3_test( + "CURVEPOLYGON(COMPOUNDCURVE((763650.600000001 189057.100000001,7636.35 189045.199999999, 763650.548999999 189057.844000001,763650.600000001 189057.100000001)))","763650.6 189057.1 7636.35 189045.2 763650.549 189057.844 763650.6 189057.1", + NULL, 7, 0 ); /* GML2 - MultiCurve */ do_gml2_unsupported( diff --git a/liblwgeom/lwout_gml.c b/liblwgeom/lwout_gml.c index 47366b68a..cfd35b88c 100644 --- a/liblwgeom/lwout_gml.c +++ b/liblwgeom/lwout_gml.c @@ -1080,6 +1080,122 @@ asgml3_poly(const LWPOLY *poly, const char *srs, int precision, int opts, int is return output; } +static size_t +asgml3_compound_size(const LWCOMPOUND *col, const char *srs, int precision, int opts, const char *prefix, const char *id ) +{ + int i; + size_t size; + LWGEOM *subgeom; + size_t prefixlen = strlen(prefix); + + size = ( sizeof( "" ) + 2 * prefixlen ); + + if (srs) size += strlen(srs) + sizeof(" srsName=.."); + if (id) size += strlen(id) + strlen(prefix) + sizeof(" id=.."); + + size += ( sizeof("") + 2 * prefixlen ); + + for(i= 0; i < col->ngeoms; ++i ) + { + subgeom = col->geoms[i]; + if ( subgeom->type == LINETYPE ) + { + + size += sizeof( "points, precision ); + } + else if( subgeom->type == CIRCSTRINGTYPE ) + { + size += sizeof( "") + 4 * prefixlen; + size += pointArray_GMLsize( ((LWCIRCSTRING*)subgeom)->points, precision ); + } + else + { + continue; + } + if (IS_DIMS(opts)) + { + size += sizeof(" srsDimension='x'"); + } + } + return size; +} + +static size_t +asgml3_compound_buf(const LWCOMPOUND *col, const char *srs, char *output, int precision, int opts, const char *prefix, const char *id) +{ + LWGEOM *subgeom; + int i; + char* ptr = output; + int dimension=2; + + if (FLAGS_GET_Z(col->flags)) + { + dimension = 3; + } + + ptr += sprintf( ptr, "<%sCurve", prefix ); + if (srs) + { + ptr += sprintf(ptr, " srsName=\"%s\"", srs); + } + if (id) + { + ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id ); + } + ptr += sprintf( ptr, ">" ); + ptr += sprintf( ptr, "<%ssegments>", prefix ); + + for( i = 0; i < col->ngeoms; ++i ) + { + subgeom = col->geoms[i]; + if( subgeom->type != LINETYPE && subgeom->type != CIRCSTRINGTYPE ) + { + continue; + } + + if ( subgeom->type == LINETYPE ) + { + ptr += sprintf( ptr, "<%sLineStringSegment><%sposList", prefix, prefix ); + if (IS_DIMS(opts)) + { + ptr += sprintf(ptr, " srsDimension=\"%d\"", dimension); + } + ptr += sprintf(ptr, ">"); + ptr += pointArray_toGML3(((LWCIRCSTRING*)subgeom)->points, ptr, precision, opts); + ptr += sprintf( ptr, "", prefix, prefix ); + } + else if( subgeom->type == CIRCSTRINGTYPE ) + { + ptr += sprintf( ptr, "<%sArcString><%sposList" , prefix, prefix ); + if (IS_DIMS(opts)) + { + ptr += sprintf(ptr, " srsDimension=\"%d\"", dimension); + } + ptr += sprintf(ptr, ">"); + ptr += pointArray_toGML3(((LWLINE*)subgeom)->points, ptr, precision, opts); + ptr += sprintf( ptr, "", prefix, prefix ); + } + } + + ptr += sprintf( ptr, "", prefix ); + ptr += sprintf( ptr, "", prefix ); + return ( ptr - output ); +} + +static char * +asgml3_compound(const LWCOMPOUND *col, const char *srs, int precision, int opts, const char *prefix, const char *id ) +{ + char* gml; + size_t size; + + size = asgml3_compound_size( col, srs, precision, opts, prefix, id ); + gml = lwalloc( size ); + asgml3_compound_buf( col, srs, gml, precision, opts, prefix, id ); + return gml; +} + static size_t asgml3_curvepoly_size(const LWCURVEPOLY* poly, const char *srs, int precision, int opts, const char *prefix, const char *id) { size_t prefixlen = strlen(prefix); @@ -1116,6 +1232,11 @@ static size_t asgml3_curvepoly_size(const LWCURVEPOLY* poly, const char *srs, in size += sizeof("") + 2 * prefixlen; size += asgml3_circstring_size((LWCIRCSTRING*)subgeom, srs, precision, opts, prefix, id); } + else if( subgeom->type == COMPOUNDTYPE ) + { + size += sizeof("") + 2 * prefixlen; + size += asgml3_compound_size( (LWCOMPOUND*)subgeom, srs, precision, opts, prefix, id ); + } } return size; } @@ -1174,6 +1295,12 @@ static size_t asgml3_curvepoly_buf(const LWCURVEPOLY* poly, const char *srs, cha ptr += asgml3_circstring_buf( (LWCIRCSTRING*)subgeom, srs, ptr, precision, opts, prefix, id ); ptr += sprintf( ptr, "", prefix ); } + else if( subgeom->type == COMPOUNDTYPE ) + { + ptr += sprintf( ptr, "<%scurveMember>", prefix ); + ptr += asgml3_compound_buf( (LWCOMPOUND*)subgeom, srs, ptr, precision, opts, prefix, id ); + ptr += sprintf( ptr, "", prefix ); + } if( i == 0 ) { @@ -1613,119 +1740,6 @@ asgml3_collection(const LWCOLLECTION *col, const char *srs, int precision, int o return gml; } -static size_t asgml3_compound_size(const LWCOMPOUND *col, const char *srs, int precision, int opts, const char *prefix, const char *id ) -{ - int i; - size_t size; - LWGEOM *subgeom; - size_t prefixlen = strlen(prefix); - - size = ( sizeof( "" ) + 2 * prefixlen ); - - if (srs) size += strlen(srs) + sizeof(" srsName=.."); - if (id) size += strlen(id) + strlen(prefix) + sizeof(" id=.."); - - size += ( sizeof("") + 2 * prefixlen ); - - for(i= 0; i < col->ngeoms; ++i ) - { - subgeom = col->geoms[i]; - if ( subgeom->type == LINETYPE ) - { - - size += sizeof( "points, precision ); - } - else if( subgeom->type == CIRCSTRINGTYPE ) - { - size += sizeof( "") + 4 * prefixlen; - size += pointArray_GMLsize( ((LWCIRCSTRING*)subgeom)->points, precision ); - } - else - { - continue; - } - if (IS_DIMS(opts)) - { - size += sizeof(" srsDimension='x'"); - } - } - return size; -} - -static size_t asgml3_compound_buf(const LWCOMPOUND *col, const char *srs, char *output, int precision, int opts, const char *prefix, const char *id) -{ - LWGEOM *subgeom; - int i; - char* ptr = output; - int dimension=2; - - if (FLAGS_GET_Z(col->flags)) - { - dimension = 3; - } - - ptr += sprintf( ptr, "<%sCurve", prefix ); - if (srs) - { - ptr += sprintf(ptr, " srsName=\"%s\"", srs); - } - if (id) - { - ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id ); - } - ptr += sprintf( ptr, ">" ); - ptr += sprintf( ptr, "<%ssegments>", prefix ); - - for( i = 0; i < col->ngeoms; ++i ) - { - subgeom = col->geoms[i]; - if( subgeom->type != LINETYPE && subgeom->type != CIRCSTRINGTYPE ) - { - continue; - } - - if ( subgeom->type == LINETYPE ) - { - ptr += sprintf( ptr, "<%sLineStringSegment><%sposList", prefix, prefix ); - if (IS_DIMS(opts)) - { - ptr += sprintf(ptr, " srsDimension=\"%d\"", dimension); - } - ptr += sprintf(ptr, ">"); - ptr += pointArray_toGML3(((LWCIRCSTRING*)subgeom)->points, ptr, precision, opts); - ptr += sprintf( ptr, "", prefix, prefix ); - } - else if( subgeom->type == CIRCSTRINGTYPE ) - { - ptr += sprintf( ptr, "<%sArcString><%sposList" , prefix, prefix ); - if (IS_DIMS(opts)) - { - ptr += sprintf(ptr, " srsDimension=\"%d\"", dimension); - } - ptr += sprintf(ptr, ">"); - ptr += pointArray_toGML3(((LWLINE*)subgeom)->points, ptr, precision, opts); - ptr += sprintf( ptr, "", prefix, prefix ); - } - } - - ptr += sprintf( ptr, "", prefix ); - ptr += sprintf( ptr, "", prefix ); - return ( ptr - output ); -} - -static char *asgml3_compound(const LWCOMPOUND *col, const char *srs, int precision, int opts, const char *prefix, const char *id ) -{ - char* gml; - size_t size; - - size = asgml3_compound_size( col, srs, precision, opts, prefix, id ); - gml = lwalloc( size ); - asgml3_compound_buf( col, srs, gml, precision, opts, prefix, id ); - return gml; -} - static size_t asgml3_multicurve_size( const LWMCURVE* cur, const char *srs, int precision, int opts, const char *prefix, const char *id ) { size_t prefixlen = strlen(prefix); -- 2.40.0