static char *asgml3_point(const LWPOINT *point, const char *srs, int precision, int opts, const char *prefix, const char *id);
static size_t asgml3_line_size(const LWLINE *line, const char *srs, int precision, int opts, const char *prefix, const char *id);
static char *asgml3_line(const LWLINE *line, const char *srs, int precision, int opts, const char *prefix, const char *id);
+static char *asgml3_circstring( const LWCIRCSTRING *circ, const char *srs, int precision, int opts, const char *prefix, const char *id );
static size_t asgml3_poly_size(const LWPOLY *poly, const char *srs, int precision, int opts, const char *prefix, const char *id);
static char *asgml3_poly(const LWPOLY *poly, const char *srs, int precision, int opts, int is_patch, const char *prefix, const char *id);
+static char * asgml3_curvepoly(const LWCURVEPOLY* poly, const char *srs, int precision, int opts, const char *prefix, const char *id);
static size_t asgml3_triangle_size(const LWTRIANGLE *triangle, const char *srs, int precision, int opts, const char *prefix, const char *id);
static char *asgml3_triangle(const LWTRIANGLE *triangle, const char *srs, int precision, int opts, const char *prefix, const char *id);
static size_t asgml3_multi_size(const LWCOLLECTION *col, const char *srs, int precision, int opts, const char *prefix, const char *id);
static char *asgml3_tin(const LWTIN *tin, const char *srs, int precision, int opts, const char *prefix, const char *id);
static size_t asgml3_collection_size(const LWCOLLECTION *col, const char *srs, int precision, int opts, const char *prefix, const char *id);
static char *asgml3_collection(const LWCOLLECTION *col, const char *srs, int precision, int opts, const char *prefix, const char *id);
+static char *asgml3_compound(const LWCOMPOUND *col, const char *srs, int precision, int opts, const char *prefix, const char *id );
+static char *asgml3_multicurve( const LWMCURVE* cur, const char *srs, int precision, int opts, const char *prefix, const char *id );
+static char *asgml3_multisurface(const LWMSURFACE *sur, const char *srs, int precision, int opts, const char *prefix, const char *id);
static size_t pointArray_toGML3(POINTARRAY *pa, char *buf, int precision, int opts);
+
static size_t pointArray_GMLsize(POINTARRAY *pa, int precision);
static char *
gbox_to_gml2(const GBOX *bbox, const char *srs, int precision, const char *prefix)
{
int size;
- POINT4D pt;
- POINTARRAY *pa;
+ POINT4D pt;
+ POINTARRAY *pa;
char *ptr, *output;
size_t prefixlen = strlen(prefix);
- if ( ! bbox ) {
+ if ( ! bbox )
+ {
size = ( sizeof("<Box>/") + (prefixlen*2) ) * 2;
if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
return output;
}
- pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 2);
+ pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 2);
+
+ pt.x = bbox->xmin;
+ pt.y = bbox->ymin;
+ if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmin;
+ ptarray_append_point(pa, &pt, LW_TRUE);
- pt.x = bbox->xmin;
- pt.y = bbox->ymin;
- if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmin;
- ptarray_append_point(pa, &pt, LW_TRUE);
-
- pt.x = bbox->xmax;
- pt.y = bbox->ymax;
- if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmax;
- ptarray_append_point(pa, &pt, LW_TRUE);
+ pt.x = bbox->xmax;
+ pt.y = bbox->ymax;
+ if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmax;
+ ptarray_append_point(pa, &pt, LW_TRUE);
size = pointArray_GMLsize(pa, precision);
size += ( sizeof("<Box><coordinates>/") + (prefixlen*2) ) * 2;
ptr += pointArray_toGML2(pa, ptr, precision);
ptr += sprintf(ptr, "</%scoordinates></%sBox>", prefix, prefix);
- ptarray_free(pa);
+ ptarray_free(pa);
return output;
}
gbox_to_gml3(const GBOX *bbox, const char *srs, int precision, int opts, const char *prefix)
{
int size;
- POINT4D pt;
- POINTARRAY *pa;
+ POINT4D pt;
+ POINTARRAY *pa;
char *ptr, *output;
size_t prefixlen = strlen(prefix);
int dimension = 2;
- if ( ! bbox ) {
+ if ( ! bbox )
+ {
size = ( sizeof("<Envelope>/") + (prefixlen*2) ) * 2;
if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
return output;
}
- if (FLAGS_GET_Z(bbox->flags)) dimension = 3;
+ if (FLAGS_GET_Z(bbox->flags)) dimension = 3;
- pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 1);
+ pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 1);
- pt.x = bbox->xmin;
- pt.y = bbox->ymin;
- if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmin;
- ptarray_append_point(pa, &pt, LW_TRUE);
+ pt.x = bbox->xmin;
+ pt.y = bbox->ymin;
+ if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmin;
+ ptarray_append_point(pa, &pt, LW_TRUE);
size = pointArray_GMLsize(pa, precision) * 2;
size += ( sizeof("<Envelope><lowerCorner><upperCorner>//") + (prefixlen*3) ) * 2;
ptr += pointArray_toGML3(pa, ptr, precision, opts);
ptr += sprintf(ptr, "</%slowerCorner>", prefix);
- ptarray_remove_point(pa, 0);
- pt.x = bbox->xmax;
- pt.y = bbox->ymax;
- if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmax;
- ptarray_append_point(pa, &pt, LW_TRUE);
+ ptarray_remove_point(pa, 0);
+ pt.x = bbox->xmax;
+ pt.y = bbox->ymax;
+ if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmax;
+ ptarray_append_point(pa, &pt, LW_TRUE);
ptr += sprintf(ptr, "<%supperCorner>", prefix);
ptr += pointArray_toGML3(pa, ptr, precision, opts);
ptr += sprintf(ptr, "</%sEnvelope>", prefix);
- ptarray_free(pa);
+ ptarray_free(pa);
return output;
}
lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
{
const GBOX* bbox = lwgeom_get_bbox(geom);
-/*
- if ( ! bbox ) {
- lwerror("lwgeom_extent_to_gml2: empty geometry doesn't have a bounding box");
- return NULL;
- }
-*/
+ /*
+ if ( ! bbox ) {
+ lwerror("lwgeom_extent_to_gml2: empty geometry doesn't have a bounding box");
+ return NULL;
+ }
+ */
char *ret = gbox_to_gml2(bbox, srs, precision, prefix);
return ret;
}
-
+
extern char *
lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
{
const GBOX* bbox = lwgeom_get_bbox(geom);
-/*
- if ( ! bbox ) {
- lwerror("lwgeom_extent_to_gml3: empty geometry doesn't have a bounding box");
- return NULL;
- }
-*/
+ /*
+ if ( ! bbox ) {
+ lwerror("lwgeom_extent_to_gml3: empty geometry doesn't have a bounding box");
+ return NULL;
+ }
+ */
return gbox_to_gml3(bbox, srs, precision, opts, prefix);
}
-
-
+
+
/**
* @brief VERSION GML 2
* takes a GEOMETRY and returns a GML2 representation
case TINTYPE:
lwerror("Cannot convert %s to GML2. Try ST_AsGML(3, <geometry>) to generate GML3.", lwtype_name(type));
return NULL;
-
+
default:
lwerror("lwgeom_to_gml2: '%s' geometry type not supported", lwtype_name(type));
return NULL;
ptr += sprintf(ptr, "<%sPoint", prefix);
if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
- if ( lwpoint_is_empty(point) ) {
+ if ( lwpoint_is_empty(point) )
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
ptr += sprintf(ptr, "<%sLineString", prefix);
if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
- if ( lwline_is_empty(line) ) {
+ if ( lwline_is_empty(line) )
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
size = sizeof("<polygon></polygon>") + prefixlen*2;
if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
- if ( lwpoly_is_empty(poly) )
+ if ( lwpoly_is_empty(poly) )
return size;
size += ( sizeof("<outerboundaryis><linearring><coordinates>/") + ( prefixlen*3) ) * 2;
size += ( sizeof("<innerboundaryis><linearring><coordinates>/") + ( prefixlen*2) ) * 2 * poly->nrings;
ptr += sprintf(ptr, "<%sPolygon", prefix);
if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
- if ( lwpoly_is_empty(poly) ) {
+ if ( lwpoly_is_empty(poly) )
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
ptr += sprintf(ptr, ">");
ptr += sprintf(ptr, "<%souterBoundaryIs><%sLinearRing><%scoordinates>",
- prefix, prefix, prefix);
+ prefix, prefix, prefix);
ptr += pointArray_toGML2(poly->rings[0], ptr, precision);
ptr += sprintf(ptr, "</%scoordinates></%sLinearRing></%souterBoundaryIs>", prefix, prefix, prefix);
for (i=1; i<poly->nrings; i++)
ptr += sprintf(ptr, "<%s%s", prefix, gmltype);
if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
- if (!col->ngeoms) {
+ if (!col->ngeoms)
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
for (i=0; i<col->ngeoms; i++)
{
subgeom = col->geoms[i];
-
+
size += ( sizeof("<geometryMember>/") + prefixlen ) * 2;
if ( subgeom->type == POINTTYPE)
{
char *ptr;
int i;
LWGEOM *subgeom;
-
+
ptr = output;
/* Open outmost tag */
ptr += sprintf(ptr, "<%sMultiGeometry", prefix);
if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
- if (!col->ngeoms) {
+ if (!col->ngeoms)
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
for (i=0; i<col->ngeoms; i++)
{
- subgeom = col->geoms[i];
+ subgeom = col->geoms[i];
ptr += sprintf(ptr, "<%sgeometryMember>", prefix);
if (subgeom->type == POINTTYPE)
case LINETYPE:
return asgml3_line((LWLINE*)geom, srs, precision, opts, prefix, id);
+ case CIRCSTRINGTYPE:
+ return asgml3_circstring((LWCIRCSTRING*)geom, srs, precision, opts, prefix, id );
+
case POLYGONTYPE:
return asgml3_poly((LWPOLY*)geom, srs, precision, opts, 0, prefix, id);
+ case CURVEPOLYTYPE:
+ return asgml3_curvepoly((LWCURVEPOLY*)geom, srs, precision, opts, prefix, id);
+
case TRIANGLETYPE:
return asgml3_triangle((LWTRIANGLE*)geom, srs, precision, opts, prefix, id);
case COLLECTIONTYPE:
return asgml3_collection((LWCOLLECTION*)geom, srs, precision, opts, prefix, id);
+ case COMPOUNDTYPE:
+ return asgml3_compound( (LWCOMPOUND*)geom, srs, precision, opts, prefix, id );
+
+ case MULTICURVETYPE:
+ return asgml3_multicurve( (LWMCURVE*)geom, srs, precision, opts, prefix, id );
+
+ case MULTISURFACETYPE:
+ return asgml3_multisurface( (LWMSURFACE*)geom, srs, precision, opts, prefix, id );
+
default:
lwerror("lwgeom_to_gml3: '%s' geometry type not supported", lwtype_name(type));
return NULL;
ptr += sprintf(ptr, "<%sPoint", prefix);
if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
if ( id ) ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id);
- if ( lwpoint_is_empty(point) ) {
+ if ( lwpoint_is_empty(point) )
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
if ( opts & LW_GML_SHORTLINE )
{
size += (
- sizeof("<LineString><posList>/") +
- ( prefixlen * 2 )
- ) * 2;
+ sizeof("<LineString><posList>/") +
+ ( prefixlen * 2 )
+ ) * 2;
}
else
{
size += (
- sizeof("<Curve><segments><LineStringSegment><posList>/") +
- ( prefixlen * 4 )
- ) * 2;
+ sizeof("<Curve><segments><LineStringSegment><posList>/") +
+ ( prefixlen * 4 )
+ ) * 2;
}
if (srs) size += strlen(srs) + sizeof(" srsName=..");
if (id) size += strlen(id) + strlen(prefix) + sizeof(" id=..");
if (FLAGS_GET_Z(line->flags)) dimension = 3;
- if ( shortline ) {
+ if ( shortline )
+ {
ptr += sprintf(ptr, "<%sLineString", prefix);
- } else {
+ }
+ else
+ {
ptr += sprintf(ptr, "<%sCurve", prefix);
}
if (srs) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
if (id) ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id);
- if ( lwline_is_empty(line) ) {
+ if ( lwline_is_empty(line) )
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
ptr += sprintf(ptr, ">");
- if ( ! shortline ) {
+ if ( ! shortline )
+ {
ptr += sprintf(ptr, "<%ssegments>", prefix);
ptr += sprintf(ptr, "<%sLineStringSegment>", prefix);
}
- if (IS_DIMS(opts)) {
+ if (IS_DIMS(opts))
+ {
ptr += sprintf(ptr, "<%sposList srsDimension=\"%d\">",
- prefix, dimension);
- } else {
+ prefix, dimension);
+ }
+ else
+ {
ptr += sprintf(ptr, "<%sposList>", prefix);
}
ptr += sprintf(ptr, "</%sposList>", prefix);
- if ( shortline ) {
+ if ( shortline )
+ {
ptr += sprintf(ptr, "</%sLineString>", prefix);
- } else {
+ }
+ else
+ {
ptr += sprintf(ptr, "</%sLineStringSegment>", prefix);
ptr += sprintf(ptr, "</%ssegments>", prefix);
ptr += sprintf(ptr, "</%sCurve>", prefix);
}
+static size_t
+asgml3_circstring_size(const LWCIRCSTRING *circ, const char *srs, int precision, int opts, const char *prefix, const char *id)
+{
+ int size = pointArray_GMLsize( circ->points, precision );
+ size_t prefixlen = strlen(prefix);
+ size += 2 * ( sizeof( "<Curve><segments>/" ) + 2 * prefixlen );
+ size += 2 * ( sizeof( "<ArcString><posList>/" ) + 2 * prefixlen );
+ if (srs) size += strlen(srs) + sizeof(" srsName=..");
+ if (id) size += strlen(id) + strlen(prefix) + sizeof(" id=..");
+ if (IS_DIMS(opts)) size += sizeof(" srsDimension='x'");
+ return size;
+}
+
+static size_t
+asgml3_circstring_buf(const LWCIRCSTRING *circ, const char *srs, char *output, int precision, int opts, const char *prefix, const char *id)
+{
+ char* ptr = output;
+ int dimension=2;
+
+ if (FLAGS_GET_Z(circ->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);
+ ptr += sprintf(ptr, "<%sArcString>", prefix);
+ ptr += sprintf(ptr, "<%sposList", prefix);
+
+ if (IS_DIMS(opts))
+ {
+ ptr += sprintf(ptr, " srsDimension=\"%d\"", dimension);
+ }
+ ptr += sprintf(ptr, ">");
+
+ ptr += pointArray_toGML3(circ->points, ptr, precision, opts);
+ ptr += sprintf(ptr, "</%sposList>", prefix);
+ ptr += sprintf(ptr, "</%sArcString>", prefix);
+ ptr += sprintf(ptr, "</%ssegments>", prefix);
+ ptr += sprintf(ptr, "</%sCurve>", prefix);
+ return (ptr-output);
+}
+
+static char *
+asgml3_circstring( const LWCIRCSTRING *circ, const char *srs, int precision, int opts, const char *prefix, const char *id )
+{
+ char *output;
+ int size;
+
+ size = asgml3_circstring_size(circ, srs, precision, opts, prefix, id);
+ output = lwalloc( size );
+ asgml3_circstring_buf(circ, srs, output, precision, opts, prefix, id);
+ return output;
+}
+
+
static size_t
asgml3_poly_size(const LWPOLY *poly, const char *srs, int precision, int opts, const char *prefix, const char *id)
{
if (srs) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
if (id) ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id);
- if ( lwpoly_is_empty(poly) ) {
+ if ( lwpoly_is_empty(poly) )
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
return output;
}
+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);
+ LWGEOM* subgeom;
+ size_t size = sizeof( "<Polygon></Polygon" ) + 2 * prefixlen;
+ if (srs) size += strlen(srs) + sizeof(" srsName=..");
+ if (id) size += strlen(id) + strlen(prefix) + sizeof(" id=..");
+ int i;
+
+ for( i = 0; i < poly->nrings; ++i )
+ {
+ if( i == 0 )
+ {
+ size += sizeof( "<exterior></exterior>" ) + 2 * prefixlen;
+ }
+ else
+ {
+ size += sizeof( "<interior></interior>" ) + 2 * prefixlen;
+ }
+ subgeom = poly->rings[i];
+
+ if ( subgeom->type == LINETYPE )
+ {
+ size += sizeof("<LinearRing></LinearRing>") + 2 * prefixlen;
+ size += sizeof("<posList></posList") + 2 * prefixlen;
+ if (IS_DIMS(opts))
+ {
+ size += sizeof(" srsDimension='x'");
+ }
+ size += pointArray_GMLsize( ((LWLINE*)subgeom)->points, precision );
+ }
+ else if( subgeom->type == CIRCSTRINGTYPE )
+ {
+ size += sizeof("<CurveMember></CurveMember>") + 2 * prefixlen;
+ size += asgml3_circstring_size((LWCIRCSTRING*)subgeom, srs, precision, opts, prefix, id);
+ }
+ }
+ return size;
+}
+
+static size_t asgml3_curvepoly_buf(const LWCURVEPOLY* poly, const char *srs, char *output, int precision, int opts, const char *prefix, const char *id)
+{
+ int i;
+ LWGEOM* subgeom;
+ char *ptr=output;
+ int dimension=2;
+
+ if (FLAGS_GET_Z(poly->flags))
+ {
+ dimension = 3;
+ }
+
+ ptr += sprintf( ptr, "<%sPolygon", prefix );
+ if (srs)
+ {
+ ptr += sprintf(ptr, " srsName=\"%s\"", srs);
+ }
+ if (id)
+ {
+ ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id );
+ }
+ ptr += sprintf(ptr, ">");
+
+ for( i = 0; i < poly->nrings; ++i )
+ {
+ if( i == 0 )
+ {
+ ptr += sprintf( ptr, "<%sexterior>", prefix);
+ }
+ else
+ {
+ ptr += sprintf( ptr, "<%sinterior>", prefix);
+ }
+
+ subgeom = poly->rings[i];
+ if ( subgeom->type == LINETYPE )
+ {
+ ptr += sprintf( ptr, "<%sLinearRing>", prefix );
+ ptr += sprintf( ptr, "<%sposList", 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>", prefix );
+ ptr += sprintf( ptr, "</%sLinearRing>", prefix );
+ }
+ else if( subgeom->type == CIRCSTRINGTYPE )
+ {
+ ptr += sprintf( ptr, "<%scurveMember>", prefix );
+ ptr += asgml3_circstring_buf( (LWCIRCSTRING*)subgeom, srs, ptr, precision, opts, prefix, id );
+ ptr += sprintf( ptr, "</%scurveMember>", prefix );
+ }
+
+ if( i == 0 )
+ {
+ ptr += sprintf( ptr, "</%sexterior>", prefix);
+ }
+ else
+ {
+ ptr += sprintf( ptr, "</%sinterior>", prefix);
+ }
+ }
+
+ ptr += sprintf( ptr, "</%sPolygon>", prefix );
+ return (ptr - output);
+}
+
+static char* asgml3_curvepoly(const LWCURVEPOLY* poly, const char *srs, int precision, int opts, const char *prefix, const char *id)
+{
+ char* gml;
+ size_t size;
+
+ size = asgml3_curvepoly_size( poly, srs, precision, opts, prefix, id );
+ gml = lwalloc( size );
+ asgml3_curvepoly_buf( poly, srs, gml, precision, opts, prefix, id );
+ return gml;
+}
+
static size_t
asgml3_triangle_size(const LWTRIANGLE *triangle, const char *srs, int precision, int opts, const char *prefix, const char *id)
if (srs) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
if (id) ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id);
- if (!col->ngeoms) {
+ if (!col->ngeoms)
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
if (srs) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
if (id) ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id);
- if (!col->ngeoms) {
+ if (!col->ngeoms)
+ {
ptr += sprintf(ptr, "/>");
return (ptr-output);
}
else
ptr += asgml3_multi_buf((LWCOLLECTION*)subgeom, 0, ptr, precision, opts, prefix, id);
}
- else
+ else
lwerror("asgml3_collection_buf: unknown geometry type");
-
+
ptr += sprintf(ptr, "</%sgeometryMember>", prefix);
}
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);
+ size_t size = sizeof( "<MultiCurve></MultiCurve>" ) + 2 * prefixlen;
+ if (srs) size += strlen(srs) + sizeof(" srsName=..");
+ if (id) size += strlen(id) + strlen(prefix) + sizeof(" id=..");
+ LWGEOM* subgeom;
+ int i;
+
+ for( i = 0; i < cur->ngeoms; ++i )
+ {
+ size += sizeof( "<curveMember></curveMember>" ) + 2 * prefixlen;
+ subgeom = cur->geoms[i];
+ if ( subgeom->type == LINETYPE )
+ {
+ size += asgml3_line_size( (LWLINE*)subgeom, srs, precision, opts, prefix, id );
+ }
+ else if( subgeom->type == CIRCSTRINGTYPE )
+ {
+ size += asgml3_circstring_size( (LWCIRCSTRING*)subgeom, srs, precision, opts, prefix, id );
+ }
+ else if( subgeom->type == COMPOUNDTYPE )
+ {
+ size += asgml3_compound_size( (LWCOMPOUND*)subgeom, srs, precision, opts, prefix, id );
+ }
+ }
+ return size;
+}
+
+static size_t asgml3_multicurve_buf( const LWMCURVE* cur, const char *srs, char *output, int precision, int opts, const char *prefix, const char *id )
+{
+ char* ptr = output;
+ LWGEOM* subgeom;
+ int i;
+
+ ptr += sprintf(ptr, "<%sMultiCurve", prefix );
+ if (srs)
+ {
+ ptr += sprintf(ptr, " srsName=\"%s\"", srs);
+ }
+ if (id)
+ {
+ ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id );
+ }
+ ptr += sprintf( ptr, ">");
+
+ for( i = 0; i < cur->ngeoms; ++i )
+ {
+ ptr += sprintf(ptr, "<%scurveMember>", prefix );
+ subgeom = cur->geoms[i];
+ if ( subgeom->type == LINETYPE )
+ {
+ ptr += asgml3_line_buf( (LWLINE*)subgeom, srs, ptr, precision, opts, prefix, id );
+ }
+ else if( subgeom->type == CIRCSTRINGTYPE )
+ {
+ ptr += asgml3_circstring_buf( (LWCIRCSTRING*)subgeom, srs, ptr, precision, opts, prefix, id );
+ }
+ else if( subgeom->type == COMPOUNDTYPE )
+ {
+ ptr += asgml3_compound_buf( (LWCOMPOUND*)subgeom, srs, ptr, precision, opts, prefix, id );
+ }
+ ptr += sprintf(ptr, "</%scurveMember>", prefix );
+ }
+ ptr += sprintf(ptr, "</%sMultiCurve>", prefix );
+ return (ptr - output);
+}
+
+static char *asgml3_multicurve( const LWMCURVE* cur, const char *srs, int precision, int opts, const char *prefix, const char *id )
+{
+ char* gml;
+ size_t size =asgml3_multicurve_size( cur, srs, precision, opts, prefix, id );
+ gml = lwalloc( size );
+ asgml3_multicurve_buf( cur, srs, gml, precision, opts, prefix, id );
+ return gml;
+}
+
+static size_t asgml3_multisurface_size(const LWMSURFACE *sur, const char *srs, int precision, int opts, const char *prefix, const char *id)
+{
+ size_t prefixlen = strlen(prefix);
+ size_t size = sizeof( "<MultiSurface></MultiSurface>" ) + 2 * prefixlen;
+ if (srs) size += strlen(srs) + sizeof(" srsName=..");
+ if (id) size += strlen(id) + strlen(prefix) + sizeof(" id=..");
+ LWGEOM* subgeom;
+ int i;
+
+ for( i = 0; i < sur->ngeoms; ++i )
+ {
+ subgeom = sur->geoms[i];
+ if( subgeom->type == POLYGONTYPE )
+ {
+ size += asgml3_poly_size( (LWPOLY*)sur->geoms[i], srs, precision, opts, prefix, id );
+ }
+ else if( subgeom->type == CURVEPOLYTYPE )
+ {
+ size += asgml3_curvepoly_size( (LWCURVEPOLY*)sur->geoms[i], srs, precision, opts, prefix, id );
+ }
+ }
+ return size;
+}
+
+static size_t asgml3_multisurface_buf(const LWMSURFACE *sur, const char *srs, char *output, int precision, int opts, const char *prefix, const char *id)
+{
+ char* ptr = output;
+ int i;
+ LWGEOM* subgeom;
+
+ ptr += sprintf( ptr, "<%sMultiSurface", prefix );
+ if (srs)
+ {
+ ptr += sprintf(ptr, " srsName=\"%s\"", srs);
+ }
+ if (id)
+ {
+ ptr += sprintf(ptr, " %sid=\"%s\"", prefix, id );
+ }
+ ptr += sprintf( ptr, ">" );
+
+ for( i = 0; i < sur->ngeoms; ++i )
+ {
+ subgeom = sur->geoms[i];
+ if( subgeom->type == POLYGONTYPE )
+ {
+ ptr += asgml3_poly_buf( (LWPOLY*)sur->geoms[i], srs, ptr, precision, opts, 0, prefix, id );
+ }
+ else if( subgeom->type == CURVEPOLYTYPE )
+ {
+ ptr += asgml3_curvepoly_buf( (LWCURVEPOLY*)sur->geoms[i], srs, ptr, precision, opts, prefix, id );
+ }
+ }
+ ptr += sprintf( ptr, "</%sMultiSurface>", prefix );
+ return ptr - output;
+}
+
+static char *asgml3_multisurface(const LWMSURFACE *sur, const char *srs, int precision, int opts, const char *prefix, const char *id)
+{
+ char* gml;
+ size_t size = asgml3_multisurface_size( sur, srs, precision, opts, prefix, id );
+ gml = lwalloc( size );
+ asgml3_multisurface_buf( sur, srs, gml, precision, opts, prefix, id );
+ return gml;
+}
+
/* In GML3, inside <posList> or <pos>, coordinates are separated by a space separator
* In GML3 also, lat/lon are reversed for geocentric data