From a60b0c7d2e643f0f96a3dddcf0c9571e6135d92c Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 22 Feb 2011 14:25:15 +0000 Subject: [PATCH] Add LW_GML_SHORTLINE flag to prefer over tag for lines GML3 output [RT-SIGTA] git-svn-id: http://svn.osgeo.org/postgis/trunk@6850 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/liblwgeom.h | 6 +++-- liblwgeom/lwout_gml.c | 62 +++++++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/liblwgeom/liblwgeom.h b/liblwgeom/liblwgeom.h index b06e5df66..81da1db24 100644 --- a/liblwgeom/liblwgeom.h +++ b/liblwgeom/liblwgeom.h @@ -1788,9 +1788,11 @@ extern LWCOLLECTION *lwcollection_segmentize2d(LWCOLLECTION *coll, double dist); * @{ */ /** For GML3 only, include srsDimension attribute in output */ -#define LW_GML_IS_DIMS (1<<0) +#define LW_GML_IS_DIMS (1<<0) /** For GML3 only, declare that datas are lat/lon. Swaps axis order */ -#define LW_GML_IS_DEGREE (1<<1) +#define LW_GML_IS_DEGREE (1<<1) +/** For GML3, use rather than for lines */ +#define LW_GML_SHORTLINE (1<<2) #define IS_DIMS(x) ((x) & LW_GML_IS_DIMS) #define IS_DEGREE(x) ((x) & LW_GML_IS_DEGREE) diff --git a/liblwgeom/lwout_gml.c b/liblwgeom/lwout_gml.c index 025f61cc3..98e4918f7 100644 --- a/liblwgeom/lwout_gml.c +++ b/liblwgeom/lwout_gml.c @@ -650,7 +650,20 @@ asgml3_line_size(const LWLINE *line, char *srs, int precision, int opts, const c size_t prefixlen = strlen(prefix); size = pointArray_GMLsize(line->points, precision); - size += ( sizeof("/") + ( prefixlen * 4 ) ) * 2; + if ( opts & LW_GML_SHORTLINE ) + { + size += ( + sizeof("/") + + ( prefixlen * 2 ) + ) * 2; + } + else + { + size += ( + sizeof("/") + + ( prefixlen * 4 ) + ) * 2; + } if (srs) size += strlen(srs) + sizeof(" srsName=.."); if (IS_DIMS(opts)) size += sizeof(" srsDimension='x'"); return size; @@ -661,24 +674,45 @@ asgml3_line_buf(const LWLINE *line, char *srs, char *output, int precision, int { char *ptr=output; int dimension=2; + int shortline = ( opts & LW_GML_SHORTLINE ); if (FLAGS_GET_Z(line->flags)) dimension = 3; - if ( srs ) - { - ptr += sprintf(ptr, "<%sCurve srsName=\"%s\">", prefix, srs); + + if ( shortline ) { + ptr += sprintf(ptr, "<%sLineString", prefix); + } else { + ptr += sprintf(ptr, "<%sCurve", prefix); } - else - { - ptr += sprintf(ptr, "<%sCurve>", prefix); + + if ( srs ) { + ptr += sprintf(ptr, " srsName=\"%s\">", srs); + } else { + ptr += sprintf(ptr, ">"); } - ptr += sprintf(ptr, "<%ssegments>", prefix); - ptr += sprintf(ptr, "<%sLineStringSegment>", prefix); - if (IS_DIMS(opts)) ptr += sprintf(ptr, "<%sposList srsDimension=\"%d\">", prefix, dimension); - else ptr += sprintf(ptr, "<%sposList>", prefix); + + if ( ! shortline ) { + ptr += sprintf(ptr, "<%ssegments>", prefix); + ptr += sprintf(ptr, "<%sLineStringSegment>", prefix); + } + + if (IS_DIMS(opts)) { + ptr += sprintf(ptr, "<%sposList srsDimension=\"%d\">", + prefix, dimension); + } else { + ptr += sprintf(ptr, "<%sposList>", prefix); + } + ptr += pointArray_toGML3(line->points, ptr, precision, opts); - ptr += sprintf(ptr, "", prefix, prefix); - ptr += sprintf(ptr, "", prefix); - ptr += sprintf(ptr, "", prefix); + + ptr += sprintf(ptr, "", prefix); + + if ( shortline ) { + ptr += sprintf(ptr, "", prefix); + } else { + ptr += sprintf(ptr, "", prefix); + ptr += sprintf(ptr, "", prefix); + ptr += sprintf(ptr, "", prefix); + } return (ptr-output); } -- 2.50.1