]> granicus.if.org Git - postgis/commitdiff
#2938 gml export of curvepolygons fix
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 31 Oct 2014 00:01:52 +0000 (00:01 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 31 Oct 2014 00:01:52 +0000 (00:01 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13115 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_out_gml.c
liblwgeom/lwout_gml.c

index 547532389982d9d31a9e8f2e3681c962d0969874..56665679bd1d7f181dc325a1bc3a654795efa343 100644 (file)
@@ -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))",
                 "<gml:Polygon><gml:exterior><gml:curveMember><gml:Curve><gml:segments><gml:ArcString><gml:posList srsDimension=\"2\">-2 0 -1 -1 0 0 1 -1 2 0 0 2 -2 0</gml:posList></gml:ArcString></gml:segments></gml:Curve></gml:curveMember></gml:exterior><gml:interior><gml:LinearRing><gml:posList srsDimension=\"2\">-1 0 0 0.5 1 0 0 1 -1 0</gml:posList></gml:LinearRing></gml:interior></gml:Polygon>",
                 NULL, 1, 0 );
-
+       do_gml3_test(
+               "CURVEPOLYGON(COMPOUNDCURVE((763650.600000001 189057.100000001,7636.35 189045.199999999, 763650.548999999 189057.844000001,763650.600000001 189057.100000001)))","<gml:Polygon><gml:exterior><gml:curveMember><gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">763650.6 189057.1 7636.35 189045.2 763650.549 189057.844 763650.6 189057.1</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve></gml:curveMember></gml:exterior></gml:Polygon>",
+                               NULL, 7, 0 );
 
        /* GML2 - MultiCurve */
        do_gml2_unsupported(
index 47366b68a6160460dfbbd2859dbf15ab7cbc05d9..cfd35b88cb7a5bdc5cfc8b161febcf5cfd059197 100644 (file)
@@ -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( "<Curve></Curve>" ) + 2 * prefixlen );
+
+       if (srs) size += strlen(srs) + sizeof(" srsName=..");
+       if (id)  size += strlen(id) + strlen(prefix) + sizeof(" id=..");
+
+       size += ( sizeof("<segments></segments>") + 2 * prefixlen );
+
+       for(i= 0; i < col->ngeoms; ++i )
+       {
+               subgeom = col->geoms[i];
+               if ( subgeom->type == LINETYPE )
+               {
+
+                       size += sizeof( "<LineStringSegment></LineStringSegment" ) + 2 * prefixlen;
+                       size += sizeof( "<posList></posList" ) + 2 * prefixlen;
+                       size += pointArray_GMLsize( ((LWLINE*)subgeom)->points, precision );
+               }
+               else if( subgeom->type == CIRCSTRINGTYPE )
+               {
+                       size += sizeof( "<ArcString><posList></ArcString></posList>") + 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, "</%sposList></%sLineStringSegment>", 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, "</%sposList></%sArcString>", prefix, prefix );
+               }
+       }
+
+       ptr += sprintf( ptr, "</%ssegments>", prefix );
+       ptr += sprintf( ptr, "</%sCurve>", 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("<CurveMember></CurveMember>") + 2 * prefixlen;
                        size += asgml3_circstring_size((LWCIRCSTRING*)subgeom, srs, precision, opts, prefix, id);
                }
+               else if( subgeom->type == COMPOUNDTYPE )
+               {
+                       size += sizeof("<curveMember></curveMember>") + 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, "</%scurveMember>", 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, "</%scurveMember>", 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( "<Curve></Curve>" ) + 2 * prefixlen );
-
-       if (srs) size += strlen(srs) + sizeof(" srsName=..");
-       if (id)  size += strlen(id) + strlen(prefix) + sizeof(" id=..");
-
-       size += ( sizeof("<segments></segments>") + 2 * prefixlen );
-
-       for(i= 0; i < col->ngeoms; ++i )
-       {
-               subgeom = col->geoms[i];
-               if ( subgeom->type == LINETYPE )
-               {
-
-                       size += sizeof( "<LineStringSegment></LineStringSegment" ) + 2 * prefixlen;
-                       size += sizeof( "<posList></posList" ) + 2 * prefixlen;
-                       size += pointArray_GMLsize( ((LWLINE*)subgeom)->points, precision );
-               }
-               else if( subgeom->type == CIRCSTRINGTYPE )
-               {
-                       size += sizeof( "<ArcString><posList></ArcString></posList>") + 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, "</%sposList></%sLineStringSegment>", 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, "</%sposList></%sArcString>", prefix, prefix );
-               }
-       }
-
-       ptr += sprintf( ptr, "</%ssegments>", prefix );
-       ptr += sprintf( ptr, "</%sCurve>", 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);