PostGIS  2.5.7dev-r@@SVN_REVISION@@
cu_out_gml.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright 2010 Olivier Courtin <olivier.courtin@oslandia.com>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************/
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include "CUnit/Basic.h"
17 
18 #include "liblwgeom_internal.h"
19 #include "cu_tester.h"
20 
21 static void do_gml2_test(char * in, char * out, char * srs, int precision)
22 {
23  LWGEOM *g;
24  char *h;
25 
27  h = lwgeom_to_gml2(g, srs, precision, "gml:");
28 
29  if (strcmp(h, out))
30  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
31 
32  CU_ASSERT_STRING_EQUAL(h, out);
33 
34  lwgeom_free(g);
35  lwfree(h);
36 }
37 
38 static void do_gml2_test_prefix(char * in, char * out, char * srs, int precision, const char *prefix)
39 {
40  LWGEOM *g;
41  char *h;
42 
44  h = lwgeom_to_gml2(g, srs, precision, prefix);
45 
46  if (strcmp(h, out))
47  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
48 
49  CU_ASSERT_STRING_EQUAL(h, out);
50 
51  lwgeom_free(g);
52  lwfree(h);
53 }
54 
55 static void do_gml3_test_opts(char * in, char * out, char * srs, int precision, int opts)
56 {
57  LWGEOM *g;
58  char *h;
59 
61  h = lwgeom_to_gml3(g, srs, precision, opts, "gml:", NULL);
62 
63  if (strcmp(h, out))
64  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
65 
66  CU_ASSERT_STRING_EQUAL(h, out);
67 
68  lwgeom_free(g);
69  lwfree(h);
70 }
71 
72 static void do_gml3_test(char * in, char * out, char * srs, int precision, int is_geodetic)
73 {
74  LWGEOM *g;
75  char *h;
76  int opts = LW_GML_IS_DIMS;
77  if ( is_geodetic ) opts |= LW_GML_IS_DEGREE;
78 
80  h = lwgeom_to_gml3(g, srs, precision, opts, "gml:", NULL);
81 
82  if (strcmp(h, out))
83  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
84 
85  CU_ASSERT_STRING_EQUAL(h, out);
86 
87  lwgeom_free(g);
88  lwfree(h);
89 }
90 
91 static void do_gml3_test_prefix(char * in, char * out, char * srs, int precision, int is_geodetic, const char *prefix)
92 {
93  LWGEOM *g;
94  char *h;
95  int opts = LW_GML_IS_DIMS;
96 
97  if ( is_geodetic ) opts |= LW_GML_IS_DEGREE;
98 
100  h = lwgeom_to_gml3(g, srs, precision, opts, prefix, NULL);
101 
102  if (strcmp(h, out))
103  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
104 
105  CU_ASSERT_STRING_EQUAL(h, out);
106 
107  lwgeom_free(g);
108  lwfree(h);
109 }
110 
111 static void do_gml3_test_nodims(char * in, char * out, char * srs, int precision, int is_geodetic, int is_dims, const char *prefix)
112 {
113  LWGEOM *g;
114  char *h;
115  int opts = 0;
116 
117  if ( is_geodetic ) opts |= LW_GML_IS_DEGREE;
118  if ( is_dims ) opts |= LW_GML_IS_DIMS;
119 
121  h = lwgeom_to_gml3(g, srs, precision, opts, prefix, NULL);
122 
123  if (strcmp(h, out))
124  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
125 
126  CU_ASSERT_STRING_EQUAL(h, out);
127 
128  lwgeom_free(g);
129  lwfree(h);
130 }
131 
132 static void do_gml2_unsupported(char * in, char * out)
133 {
134  LWGEOM *g;
135  char *h;
136 
138  h = lwgeom_to_gml2(g, NULL, 0, "");
139 
140  if (strcmp(cu_error_msg, out))
141  fprintf(stderr, "\nGML 2 - In: %s\nOut: %s\nTheo: %s\n",
142  in, cu_error_msg, out);
143  CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
145 
146  lwfree(h);
147  lwgeom_free(g);
148 }
149 
150 static void do_gml2_extent_test(char * in, char * out, char * srs,
151  double precision, char * prefix)
152 {
153  LWGEOM *g;
154  char *h;
155 
157  h = lwgeom_extent_to_gml2(g, srs, precision, prefix);
158  if ( ! h ) h = strdup(cu_error_msg);
159 
160  if (strcmp(h, out))
161  fprintf(stderr, "\nEXT GML 2 - In: %s\nObt: %s\nExp: %s\n",
162  in, h, out);
163  CU_ASSERT_STRING_EQUAL(out, h);
165 
166  lwfree(h);
167  lwgeom_free(g);
168 }
169 
170 static void do_gml3_extent_test(char * in, char * out, char * srs,
171  double precision, int opts, char* prefix)
172 {
173  LWGEOM *g;
174  char *h;
175 
177  h = lwgeom_extent_to_gml3(g, srs, precision, opts, prefix);
178  if ( ! h ) h = strdup(cu_error_msg);
179 
180  if (strcmp(h, out))
181  fprintf(stderr, "\nEXT GML 3 - In: %s\nObt: %s\nExp: %s\n",
182  in, h, out);
183  CU_ASSERT_STRING_EQUAL(out, h);
185 
186  lwfree(h);
187  lwgeom_free(g);
188 }
189 
190 static void out_gml_test_precision(void)
191 {
192  /* GML2 - 0 precision, i.e a round */
193  do_gml2_test(
194  "POINT(1.1111111111111 1.1111111111111)",
195  "<gml:Point><gml:coordinates>1,1</gml:coordinates></gml:Point>",
196  NULL, 0);
197 
198  /* GML3 - 0 precision, i.e a round */
199  do_gml3_test(
200  "POINT(1.1111111111111 1.1111111111111)",
201  "<gml:Point><gml:pos srsDimension=\"2\">1 1</gml:pos></gml:Point>",
202  NULL, 0, 0);
203 
204 
205  /* GML2 - 3 digits precision */
206  do_gml2_test(
207  "POINT(1.1111111111111 1.1111111111111)",
208  "<gml:Point><gml:coordinates>1.111,1.111</gml:coordinates></gml:Point>",
209  NULL, 3);
210 
211  /* GML3 - 3 digits precision */
212  do_gml3_test(
213  "POINT(1.1111111111111 1.1111111111111)",
214  "<gml:Point><gml:pos srsDimension=\"2\">1.111 1.111</gml:pos></gml:Point>",
215  NULL, 3, 0);
216 
217 
218  /* GML2 - 9 digits precision */
219  do_gml2_test(
220  "POINT(1.2345678901234 1.2345678901234)",
221  "<gml:Point><gml:coordinates>1.23456789,1.23456789</gml:coordinates></gml:Point>",
222  NULL, 9);
223 
224  /* GML3 - 9 digits precision */
225  do_gml3_test(
226  "POINT(1.2345678901234 1.2345678901234)",
227  "<gml:Point><gml:pos srsDimension=\"2\">1.23456789 1.23456789</gml:pos></gml:Point>",
228  NULL, 9, 0);
229 
230 
231  /* GML2 - huge data */
232  do_gml2_test(
233  "POINT(1E300 -1E300)",
234  "<gml:Point><gml:coordinates>1e+300,-1e+300</gml:coordinates></gml:Point>",
235  NULL, 0);
236 
237  /* GML3 - huge data */
238  do_gml3_test(
239  "POINT(1E300 -1E300)",
240  "<gml:Point><gml:pos srsDimension=\"2\">1e+300 -1e+300</gml:pos></gml:Point>",
241  NULL, 0, 0);
242 }
243 
244 static void out_gml_test_srid(void)
245 {
246  /* GML2 - Point with SRID */
247  do_gml2_test(
248  "POINT(0 1)",
249  "<gml:Point srsName=\"EPSG:4326\"><gml:coordinates>0,1</gml:coordinates></gml:Point>",
250  "EPSG:4326", 0);
251 
252  /* GML3 - Point with SRID */
253  do_gml3_test(
254  "POINT(0 1)",
255  "<gml:Point srsName=\"EPSG:4326\"><gml:pos srsDimension=\"2\">0 1</gml:pos></gml:Point>",
256  "EPSG:4326", 0, 0);
257 
258 
259  /* GML2 - Linestring with SRID */
260  do_gml2_test(
261  "LINESTRING(0 1,2 3,4 5)",
262  "<gml:LineString srsName=\"EPSG:4326\"><gml:coordinates>0,1 2,3 4,5</gml:coordinates></gml:LineString>",
263  "EPSG:4326", 0);
264 
265  /* GML3 - Linestring with SRID */
266  do_gml3_test(
267  "LINESTRING(0 1,2 3,4 5)",
268  "<gml:Curve srsName=\"EPSG:4326\"><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">0 1 2 3 4 5</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve>",
269  "EPSG:4326", 0, 0);
270 
271  /* GML3 - Linestring with SRID and short tag*/
273  "LINESTRING(0 1,2 3,4 5)",
274  "<gml:LineString srsName=\"EPSG:4326\"><gml:posList>0 1 2 3 4 5</gml:posList></gml:LineString>",
275  "EPSG:4326", 0, LW_GML_SHORTLINE);
276 
277 
278  /* GML2 Polygon with SRID */
279  do_gml2_test(
280  "POLYGON((0 1,2 3,4 5,0 1))",
281  "<gml:Polygon srsName=\"EPSG:4326\"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0,1 2,3 4,5 0,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>",
282  "EPSG:4326", 0);
283 
284  /* GML3 Polygon with SRID */
285  do_gml3_test(
286  "POLYGON((0 1,2 3,4 5,0 1))",
287  "<gml:Polygon srsName=\"EPSG:4326\"><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon>",
288  "EPSG:4326", 0, 0);
289 
290 
291  /* GML2 MultiPoint with SRID */
292  do_gml2_test(
293  "MULTIPOINT(0 1,2 3)",
294  "<gml:MultiPoint srsName=\"EPSG:4326\"><gml:pointMember><gml:Point><gml:coordinates>0,1</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>2,3</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>",
295  "EPSG:4326", 0);
296 
297  /* GML3 MultiPoint with SRID */
298  do_gml3_test(
299  "MULTIPOINT(0 1,2 3)",
300  "<gml:MultiPoint srsName=\"EPSG:4326\"><gml:pointMember><gml:Point><gml:pos srsDimension=\"2\">0 1</gml:pos></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:pos srsDimension=\"2\">2 3</gml:pos></gml:Point></gml:pointMember></gml:MultiPoint>",
301  "EPSG:4326", 0, 0);
302 
303 
304  /* GML2 Multiline with SRID */
305  do_gml2_test(
306  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
307  "<gml:MultiLineString srsName=\"EPSG:4326\"><gml:lineStringMember><gml:LineString><gml:coordinates>0,1 2,3 4,5</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>6,7 8,9 10,11</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>",
308  "EPSG:4326", 0);
309 
310 
311  /* GML3 Multiline with SRID */
312  do_gml3_test(
313  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
314  "<gml:MultiCurve srsName=\"EPSG:4326\"><gml:curveMember><gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">0 1 2 3 4 5</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve></gml:curveMember><gml:curveMember><gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">6 7 8 9 10 11</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve></gml:curveMember></gml:MultiCurve>",
315  "EPSG:4326", 0, 0);
316 
317  /* GML3 Multiline with SRID and LineString tag */
319  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
320  "<gml:MultiCurve srsName=\"EPSG:4326\"><gml:curveMember><gml:LineString><gml:posList>0 1 2 3 4 5</gml:posList></gml:LineString></gml:curveMember><gml:curveMember><gml:LineString><gml:posList>6 7 8 9 10 11</gml:posList></gml:LineString></gml:curveMember></gml:MultiCurve>",
321  "EPSG:4326", 0, LW_GML_SHORTLINE);
322 
323 
324  /* GML2 MultiPolygon with SRID */
325  do_gml2_test(
326  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
327  "<gml:MultiPolygon srsName=\"EPSG:4326\"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0,1 2,3 4,5 0,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,7 8,9 10,11 6,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon>",
328  "EPSG:4326", 0);
329 
330  /* GML3 MultiPolygon with SRID */
331  do_gml3_test(
332  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
333  "<gml:MultiSurface srsName=\"EPSG:4326\"><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">6 7 8 9 10 11 6 7</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface>",
334  "EPSG:4326", 0, 0);
335 
336  /* GML3 PolyhedralSurface with SRID */
337  do_gml3_test(
338  "POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
339  "<gml:PolyhedralSurface srsName=\"EPSG:4326\"><gml:polygonPatches><gml:PolygonPatch><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</gml:posList></gml:LinearRing></gml:exterior></gml:PolygonPatch><gml:PolygonPatch><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">6 7 8 9 10 11 6 7</gml:posList></gml:LinearRing></gml:exterior></gml:PolygonPatch></gml:polygonPatches></gml:PolyhedralSurface>",
340  "EPSG:4326", 0, 0);
341 
342  /* GML3 Tin with SRID */
343  do_gml3_test(
344  "TIN(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
345  "<gml:Tin srsName=\"EPSG:4326\"><gml:trianglePatches><gml:Triangle><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</gml:posList></gml:LinearRing></gml:exterior></gml:Triangle><gml:Triangle><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">6 7 8 9 10 11 6 7</gml:posList></gml:LinearRing></gml:exterior></gml:Triangle></gml:trianglePatches></gml:Tin>",
346  "EPSG:4326", 0, 0);
347 
348 
349  /* GML2 GeometryCollection with SRID */
350  do_gml2_test(
351  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
352  "<gml:MultiGeometry srsName=\"EPSG:4326\"><gml:geometryMember><gml:Point><gml:coordinates>0,1</gml:coordinates></gml:Point></gml:geometryMember><gml:geometryMember><gml:LineString><gml:coordinates>2,3 4,5</gml:coordinates></gml:LineString></gml:geometryMember></gml:MultiGeometry>",
353  "EPSG:4326", 0);
354 
355  /* GML3 GeometryCollection with SRID */
356  do_gml3_test(
357  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
358  "<gml:MultiGeometry srsName=\"EPSG:4326\"><gml:geometryMember><gml:Point><gml:pos srsDimension=\"2\">0 1</gml:pos></gml:Point></gml:geometryMember><gml:geometryMember><gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">2 3 4 5</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve></gml:geometryMember></gml:MultiGeometry>",
359  "EPSG:4326", 0, 0);
360 }
361 
362 
363 static void out_gml_test_geodetic(void)
364 {
365  /* GML3 - Geodetic Point */
366  do_gml3_test(
367  "POINT(0 1)",
368  "<gml:Point srsName=\"urn:ogc:def:crs:EPSG::4326\"><gml:pos srsDimension=\"2\">1 0</gml:pos></gml:Point>",
369  "urn:ogc:def:crs:EPSG::4326", 0, 1);
370 
371  /* GML3 - 3D Geodetic Point */
372  do_gml3_test(
373  "POINT(0 1 2)",
374  "<gml:Point srsName=\"urn:ogc:def:crs:EPSG::4326\"><gml:pos srsDimension=\"3\">1 0 2</gml:pos></gml:Point>",
375  "urn:ogc:def:crs:EPSG::4326", 0, 1);
376 }
377 
378 
379 static void out_gml_test_dims(void)
380 {
381  /* GML2 - 3D */
382  do_gml2_test(
383  "POINT(0 1 2)",
384  "<gml:Point><gml:coordinates>0,1,2</gml:coordinates></gml:Point>",
385  NULL, 0);
386 
387  /* GML3 - 3D */
388  do_gml3_test(
389  "POINT(0 1 2)",
390  "<gml:Point><gml:pos srsDimension=\"3\">0 1 2</gml:pos></gml:Point>",
391  NULL, 0, 0);
392 
393 
394  /* GML2 - 3DM */
395  do_gml2_test(
396  "POINTM(0 1 2)",
397  "<gml:Point><gml:coordinates>0,1</gml:coordinates></gml:Point>",
398  NULL, 0);
399 
400  /* GML3 - 3DM */
401  do_gml3_test(
402  "POINTM(0 1 2)",
403  "<gml:Point><gml:pos srsDimension=\"2\">0 1</gml:pos></gml:Point>",
404  NULL, 0, 0);
405 
406 
407  /* GML2 - 4D */
408  do_gml2_test(
409  "POINT(0 1 2 3)",
410  "<gml:Point><gml:coordinates>0,1,2</gml:coordinates></gml:Point>",
411  NULL, 0);
412 
413  /* GML3 - 4D */
414  do_gml3_test(
415  "POINT(0 1 2 3)",
416  "<gml:Point><gml:pos srsDimension=\"3\">0 1 2</gml:pos></gml:Point>",
417  NULL, 0, 0);
418 }
419 
420 
421 static void out_gml_test_geoms(void)
422 {
423  /* GML2 - Linestring */
424  do_gml2_test(
425  "LINESTRING(0 1,2 3,4 5)",
426  "<gml:LineString><gml:coordinates>0,1 2,3 4,5</gml:coordinates></gml:LineString>",
427  NULL, 0);
428 
429  /* GML3 - Linestring */
430  do_gml3_test(
431  "LINESTRING(0 1,2 3,4 5)",
432  "<gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">0 1 2 3 4 5</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve>",
433  NULL, 0, 0);
434 
435 
436  /* GML2 Polygon */
437  do_gml2_test(
438  "POLYGON((0 1,2 3,4 5,0 1))",
439  "<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0,1 2,3 4,5 0,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon>",
440  NULL, 0);
441 
442  /* GML3 Polygon */
443  do_gml3_test(
444  "POLYGON((0 1,2 3,4 5,0 1))",
445  "<gml:Polygon><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon>",
446  NULL, 0, 0);
447 
448  /* GML2 Polygon - with internal ring */
449  do_gml2_test(
450  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
451  "<gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0,1 2,3 4,5 0,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>6,7 8,9 10,11 6,7</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon>",
452  NULL, 0);
453 
454  /* GML3 Polygon - with internal ring */
455  do_gml3_test(
456  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
457  "<gml:Polygon><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</gml:posList></gml:LinearRing></gml:exterior><gml:interior><gml:LinearRing><gml:posList srsDimension=\"2\">6 7 8 9 10 11 6 7</gml:posList></gml:LinearRing></gml:interior></gml:Polygon>",
458  NULL, 0, 0);
459 
460 
461  /* GML3 Triangle */
462  do_gml3_test(
463  "TRIANGLE((0 1,2 3,4 5,0 1))",
464  "<gml:Triangle><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</gml:posList></gml:LinearRing></gml:exterior></gml:Triangle>",
465  NULL, 0, 0);
466 
467 
468  /* GML2 MultiPoint */
469  do_gml2_test(
470  "MULTIPOINT(0 1,2 3)",
471  "<gml:MultiPoint><gml:pointMember><gml:Point><gml:coordinates>0,1</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>2,3</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint>",
472  NULL, 0);
473 
474  /* GML3 MultiPoint */
475  do_gml3_test(
476  "MULTIPOINT(0 1,2 3)",
477  "<gml:MultiPoint><gml:pointMember><gml:Point><gml:pos srsDimension=\"2\">0 1</gml:pos></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:pos srsDimension=\"2\">2 3</gml:pos></gml:Point></gml:pointMember></gml:MultiPoint>",
478  NULL, 0, 0);
479 
480 
481  /* GML2 Multiline */
482  do_gml2_test(
483  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
484  "<gml:MultiLineString><gml:lineStringMember><gml:LineString><gml:coordinates>0,1 2,3 4,5</gml:coordinates></gml:LineString></gml:lineStringMember><gml:lineStringMember><gml:LineString><gml:coordinates>6,7 8,9 10,11</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString>",
485  NULL, 0);
486 
487  /* GML3 Multiline */
488  do_gml3_test(
489  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
490  "<gml:MultiCurve><gml:curveMember><gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">0 1 2 3 4 5</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve></gml:curveMember><gml:curveMember><gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">6 7 8 9 10 11</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve></gml:curveMember></gml:MultiCurve>",
491  NULL, 0, 0);
492 
493 
494  /* GML2 MultiPolygon */
495  do_gml2_test(
496  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
497  "<gml:MultiPolygon><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0,1 2,3 4,5 0,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,7 8,9 10,11 6,7</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon>",
498  NULL, 0);
499 
500  /* GML3 MultiPolygon */
501  do_gml3_test(
502  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
503  "<gml:MultiSurface><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember><gml:surfaceMember><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">6 7 8 9 10 11 6 7</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface>",
504  NULL, 0, 0);
505 
506 
507  /* GML2 - GeometryCollection */
508  do_gml2_test(
509  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
510  "<gml:MultiGeometry><gml:geometryMember><gml:Point><gml:coordinates>0,1</gml:coordinates></gml:Point></gml:geometryMember><gml:geometryMember><gml:LineString><gml:coordinates>2,3 4,5</gml:coordinates></gml:LineString></gml:geometryMember></gml:MultiGeometry>",
511  NULL, 0);
512 
513  /* GML3 - GeometryCollection */
514  do_gml3_test(
515  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
516  "<gml:MultiGeometry><gml:geometryMember><gml:Point><gml:pos srsDimension=\"2\">0 1</gml:pos></gml:Point></gml:geometryMember><gml:geometryMember><gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">2 3 4 5</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve></gml:geometryMember></gml:MultiGeometry>",
517  NULL, 0, 0);
518 
519 
520  /* GML2 - Nested GeometryCollection */
521  do_gml2_test(
522  "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
523  "<gml:MultiGeometry><gml:geometryMember><gml:Point><gml:coordinates>0,1</gml:coordinates></gml:Point></gml:geometryMember><gml:geometryMember><gml:MultiGeometry><gml:geometryMember><gml:LineString><gml:coordinates>2,3 4,5</gml:coordinates></gml:LineString></gml:geometryMember></gml:MultiGeometry></gml:geometryMember></gml:MultiGeometry>",
524  NULL, 0);
525 
526  /* GML3 - Nested GeometryCollection */
527  do_gml3_test(
528  "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
529  "<gml:MultiGeometry><gml:geometryMember><gml:Point><gml:pos srsDimension=\"2\">0 1</gml:pos></gml:Point></gml:geometryMember><gml:geometryMember><gml:MultiGeometry><gml:geometryMember><gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">2 3 4 5</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve></gml:geometryMember></gml:MultiGeometry></gml:geometryMember></gml:MultiGeometry>",
530  NULL, 0, 0);
531 
532  /* GML2 - CircularString */
534  "CIRCULARSTRING(-2 0,0 2,2 0,0 2,2 4)",
535  "lwgeom_to_gml2: 'CircularString' geometry type not supported");
536  /* GML3 - CircularString */
537  do_gml3_test(
538  "CIRCULARSTRING(-2 0,0 2,2 0,0 2,2 4)",
539  "<gml:Curve><gml:segments><gml:ArcString><gml:posList srsDimension=\"2\">-2 0 0 2 2 0 0 2 2 4</gml:posList></gml:ArcString></gml:segments></gml:Curve>",
540  NULL, 0, 0 );
541 
542  /* GML2 - CompoundCurve */
544  "COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1,1 0),(1 0,0 1))",
545  "lwgeom_to_gml2: 'CompoundCurve' geometry type not supported");
546  /* GML3 - CompoundCurve */
547 
548  do_gml3_test(
549  "COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1,1 0),(1 0,0 1))",
550  "<gml:Curve><gml:segments><gml:ArcString><gml:posList srsDimension=\"2\">0 0 1 1 1 0</gml:posList></gml:ArcString><gml:LineStringSegment><gml:posList srsDimension=\"2\">1 0 0 1</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve>",
551  NULL, 0, 0 );
552 
553  /* GML2 - CurvePolygon */
555  "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))",
556  "lwgeom_to_gml2: 'CurvePolygon' geometry type not supported");
557 
558  /* GML3 - CurvePolygon */
559  do_gml3_test(
560  "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))",
561  "<gml:Polygon><gml:exterior><gml:Ring><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:Ring></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>",
562  NULL, 1, 0 );
563  do_gml3_test(
564  "CURVEPOLYGON(COMPOUNDCURVE((763650.600000001 189057.100000001,7636.35 189045.199999999, 763650.548999999 189057.844000001,763650.600000001 189057.100000001)))",
565  "<gml:Polygon><gml:exterior><gml:Ring><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:Ring></gml:exterior></gml:Polygon>",
566  NULL, 7, 0 );
567 
568  /* GML2 - MultiCurve */
570  "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 2))",
571  "lwgeom_to_gml2: 'MultiCurve' geometry type not supported");
572 
573  /* GML3 - MultiCurve */
574  do_gml3_test(
575  "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 2))",
576  "<gml:MultiCurve><gml:curveMember><gml:Curve><gml:segments><gml:LineStringSegment><gml:posList srsDimension=\"2\">5 5 3 5 3 3 0 3</gml:posList></gml:LineStringSegment></gml:segments></gml:Curve></gml:curveMember><gml:curveMember><gml:Curve><gml:segments><gml:ArcString><gml:posList srsDimension=\"2\">0 0 2 1 2 2</gml:posList></gml:ArcString></gml:segments></gml:Curve></gml:curveMember></gml:MultiCurve>",
577  NULL, 0, 0 );
578 
579  /* GML2 - MultiSurface */
581  "MULTISURFACE(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)),((7 8,10 10,6 14,4 11,7 8)))",
582  "lwgeom_to_gml2: 'MultiSurface' geometry type not supported");
583 
584  /* GML3 - MultiSurface */
585  do_gml3_test(
586  "MULTISURFACE(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)),((7 8,10 10,6 14,4 11,7 8)))",
587  "<gml:MultiSurface><gml:Polygon><gml:exterior><gml:Ring><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:Ring></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><gml:Polygon><gml:exterior><gml:LinearRing><gml:posList srsDimension=\"2\">7 8 10 10 6 14 4 11 7 8</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:MultiSurface>",
588  NULL, 1, 0 );
589 
590  /* GML2 - PolyhedralSurface */
592  "POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1)))",
593  "Cannot convert PolyhedralSurface to GML2. Try ST_AsGML(3, <geometry>) to generate GML3.");
594 
595  /* GML2 - Tin */
597  "TIN(((0 1,2 3,4 5,0 1)))",
598  "Cannot convert Tin to GML2. Try ST_AsGML(3, <geometry>) to generate GML3.");
599 }
600 
601 static void out_gml_test_geoms_prefix(void)
602 {
603  /* GML2 - Linestring */
605  "LINESTRING(0 1,2 3,4 5)",
606  "<custom:LineString><custom:coordinates>0,1 2,3 4,5</custom:coordinates></custom:LineString>",
607  NULL, 0, "custom:");
608 
609  /* GML3 - Linestring */
611  "LINESTRING(0 1,2 3,4 5)",
612  "<custom:Curve><custom:segments><custom:LineStringSegment><custom:posList srsDimension=\"2\">0 1 2 3 4 5</custom:posList></custom:LineStringSegment></custom:segments></custom:Curve>",
613  NULL, 0, 0, "custom:");
614 
615 
616  /* GML2 Polygon */
618  "POLYGON((0 1,2 3,4 5,0 1))",
619  "<custom:Polygon><custom:outerBoundaryIs><custom:LinearRing><custom:coordinates>0,1 2,3 4,5 0,1</custom:coordinates></custom:LinearRing></custom:outerBoundaryIs></custom:Polygon>",
620  NULL, 0, "custom:");
621 
622  /* GML3 Polygon */
624  "POLYGON((0 1,2 3,4 5,0 1))",
625  "<custom:Polygon><custom:exterior><custom:LinearRing><custom:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</custom:posList></custom:LinearRing></custom:exterior></custom:Polygon>",
626  NULL, 0, 0, "custom:");
627 
628 
629  /* GML2 Polygon - with internal ring */
631  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
632  "<custom:Polygon><custom:outerBoundaryIs><custom:LinearRing><custom:coordinates>0,1 2,3 4,5 0,1</custom:coordinates></custom:LinearRing></custom:outerBoundaryIs><custom:innerBoundaryIs><custom:LinearRing><custom:coordinates>6,7 8,9 10,11 6,7</custom:coordinates></custom:LinearRing></custom:innerBoundaryIs></custom:Polygon>",
633  NULL, 0, "custom:");
634 
635  /* GML3 Polygon - with internal ring */
637  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
638  "<custom:Polygon><custom:exterior><custom:LinearRing><custom:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</custom:posList></custom:LinearRing></custom:exterior><custom:interior><custom:LinearRing><custom:posList srsDimension=\"2\">6 7 8 9 10 11 6 7</custom:posList></custom:LinearRing></custom:interior></custom:Polygon>",
639  NULL, 0, 0, "custom:");
640 
641  /* GML3 Triangle */
643  "TRIANGLE((0 1,2 3,4 5,0 1))",
644  "<custom:Triangle><custom:exterior><custom:LinearRing><custom:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</custom:posList></custom:LinearRing></custom:exterior></custom:Triangle>",
645  NULL, 0, 0, "custom:");
646 
647 
648  /* GML2 MultiPoint */
650  "MULTIPOINT(0 1,2 3)",
651  "<custom:MultiPoint><custom:pointMember><custom:Point><custom:coordinates>0,1</custom:coordinates></custom:Point></custom:pointMember><custom:pointMember><custom:Point><custom:coordinates>2,3</custom:coordinates></custom:Point></custom:pointMember></custom:MultiPoint>",
652  NULL, 0, "custom:");
653 
654  /* GML3 MultiPoint */
656  "MULTIPOINT(0 1,2 3)",
657  "<custom:MultiPoint><custom:pointMember><custom:Point><custom:pos srsDimension=\"2\">0 1</custom:pos></custom:Point></custom:pointMember><custom:pointMember><custom:Point><custom:pos srsDimension=\"2\">2 3</custom:pos></custom:Point></custom:pointMember></custom:MultiPoint>",
658  NULL, 0, 0, "custom:");
659 
660 
661  /* GML2 Multiline */
663  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
664  "<custom:MultiLineString><custom:lineStringMember><custom:LineString><custom:coordinates>0,1 2,3 4,5</custom:coordinates></custom:LineString></custom:lineStringMember><custom:lineStringMember><custom:LineString><custom:coordinates>6,7 8,9 10,11</custom:coordinates></custom:LineString></custom:lineStringMember></custom:MultiLineString>",
665  NULL, 0, "custom:");
666 
667  /* GML3 Multiline */
669  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
670  "<custom:MultiCurve><custom:curveMember><custom:Curve><custom:segments><custom:LineStringSegment><custom:posList srsDimension=\"2\">0 1 2 3 4 5</custom:posList></custom:LineStringSegment></custom:segments></custom:Curve></custom:curveMember><custom:curveMember><custom:Curve><custom:segments><custom:LineStringSegment><custom:posList srsDimension=\"2\">6 7 8 9 10 11</custom:posList></custom:LineStringSegment></custom:segments></custom:Curve></custom:curveMember></custom:MultiCurve>",
671  NULL, 0, 0, "custom:");
672 
673 
674  /* GML2 MultiPolygon */
676  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
677  "<custom:MultiPolygon><custom:polygonMember><custom:Polygon><custom:outerBoundaryIs><custom:LinearRing><custom:coordinates>0,1 2,3 4,5 0,1</custom:coordinates></custom:LinearRing></custom:outerBoundaryIs></custom:Polygon></custom:polygonMember><custom:polygonMember><custom:Polygon><custom:outerBoundaryIs><custom:LinearRing><custom:coordinates>6,7 8,9 10,11 6,7</custom:coordinates></custom:LinearRing></custom:outerBoundaryIs></custom:Polygon></custom:polygonMember></custom:MultiPolygon>",
678  NULL, 0, "custom:");
679 
680  /* GML3 MultiPolygon */
682  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
683  "<custom:MultiSurface><custom:surfaceMember><custom:Polygon><custom:exterior><custom:LinearRing><custom:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</custom:posList></custom:LinearRing></custom:exterior></custom:Polygon></custom:surfaceMember><custom:surfaceMember><custom:Polygon><custom:exterior><custom:LinearRing><custom:posList srsDimension=\"2\">6 7 8 9 10 11 6 7</custom:posList></custom:LinearRing></custom:exterior></custom:Polygon></custom:surfaceMember></custom:MultiSurface>",
684  NULL, 0, 0, "custom:");
685 
686  /* GML3 PolyhedralSurface */
688  "POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
689  "<custom:PolyhedralSurface><custom:polygonPatches><custom:PolygonPatch><custom:exterior><custom:LinearRing><custom:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</custom:posList></custom:LinearRing></custom:exterior></custom:PolygonPatch><custom:PolygonPatch><custom:exterior><custom:LinearRing><custom:posList srsDimension=\"2\">6 7 8 9 10 11 6 7</custom:posList></custom:LinearRing></custom:exterior></custom:PolygonPatch></custom:polygonPatches></custom:PolyhedralSurface>",
690  NULL, 0, 0, "custom:");
691 
692  /* GML3 Tin */
694  "TIN(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
695  "<custom:Tin><custom:trianglePatches><custom:Triangle><custom:exterior><custom:LinearRing><custom:posList srsDimension=\"2\">0 1 2 3 4 5 0 1</custom:posList></custom:LinearRing></custom:exterior></custom:Triangle><custom:Triangle><custom:exterior><custom:LinearRing><custom:posList srsDimension=\"2\">6 7 8 9 10 11 6 7</custom:posList></custom:LinearRing></custom:exterior></custom:Triangle></custom:trianglePatches></custom:Tin>",
696  NULL, 0, 0, "custom:");
697 
698  /* GML2 - GeometryCollection */
700  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
701  "<custom:MultiGeometry><custom:geometryMember><custom:Point><custom:coordinates>0,1</custom:coordinates></custom:Point></custom:geometryMember><custom:geometryMember><custom:LineString><custom:coordinates>2,3 4,5</custom:coordinates></custom:LineString></custom:geometryMember></custom:MultiGeometry>",
702  NULL, 0, "custom:");
703 
704  /* GML3 - GeometryCollection */
706  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
707  "<custom:MultiGeometry><custom:geometryMember><custom:Point><custom:pos srsDimension=\"2\">0 1</custom:pos></custom:Point></custom:geometryMember><custom:geometryMember><custom:Curve><custom:segments><custom:LineStringSegment><custom:posList srsDimension=\"2\">2 3 4 5</custom:posList></custom:LineStringSegment></custom:segments></custom:Curve></custom:geometryMember></custom:MultiGeometry>",
708  NULL, 0, 0, "custom:");
709 
710  /* GML2 - Nested GeometryCollection */
712  "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
713  "<custom:MultiGeometry><custom:geometryMember><custom:Point><custom:coordinates>0,1</custom:coordinates></custom:Point></custom:geometryMember><custom:geometryMember><custom:MultiGeometry><custom:geometryMember><custom:LineString><custom:coordinates>2,3 4,5</custom:coordinates></custom:LineString></custom:geometryMember></custom:MultiGeometry></custom:geometryMember></custom:MultiGeometry>",
714  NULL, 0, "custom:");
715 
716  /* GML3 - Nested GeometryCollection */
718  "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
719  "<custom:MultiGeometry><custom:geometryMember><custom:Point><custom:pos srsDimension=\"2\">0 1</custom:pos></custom:Point></custom:geometryMember><custom:geometryMember><custom:MultiGeometry><custom:geometryMember><custom:Curve><custom:segments><custom:LineStringSegment><custom:posList srsDimension=\"2\">2 3 4 5</custom:posList></custom:LineStringSegment></custom:segments></custom:Curve></custom:geometryMember></custom:MultiGeometry></custom:geometryMember></custom:MultiGeometry>",
720  NULL, 0, 0, "custom:");
721 
722  /*------------- empty prefixes below ------------------------ */
723 
724  /* GML2 - Linestring */
726  "LINESTRING(0 1,2 3,4 5)",
727  "<LineString><coordinates>0,1 2,3 4,5</coordinates></LineString>",
728  NULL, 0, "");
729 
730  /* GML3 - Linestring */
732  "LINESTRING(0 1,2 3,4 5)",
733  "<Curve><segments><LineStringSegment><posList srsDimension=\"2\">0 1 2 3 4 5</posList></LineStringSegment></segments></Curve>",
734  NULL, 0, 0, "");
735 
736 
737  /* GML2 Polygon */
739  "POLYGON((0 1,2 3,4 5,0 1))",
740  "<Polygon><outerBoundaryIs><LinearRing><coordinates>0,1 2,3 4,5 0,1</coordinates></LinearRing></outerBoundaryIs></Polygon>",
741  NULL, 0, "");
742 
743  /* GML3 Polygon */
745  "POLYGON((0 1,2 3,4 5,0 1))",
746  "<Polygon><exterior><LinearRing><posList srsDimension=\"2\">0 1 2 3 4 5 0 1</posList></LinearRing></exterior></Polygon>",
747  NULL, 0, 0, "");
748 
749 
750  /* GML2 Polygon - with internal ring */
752  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
753  "<Polygon><outerBoundaryIs><LinearRing><coordinates>0,1 2,3 4,5 0,1</coordinates></LinearRing></outerBoundaryIs><innerBoundaryIs><LinearRing><coordinates>6,7 8,9 10,11 6,7</coordinates></LinearRing></innerBoundaryIs></Polygon>",
754  NULL, 0, "");
755 
756  /* GML3 Polygon - with internal ring */
758  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
759  "<Polygon><exterior><LinearRing><posList srsDimension=\"2\">0 1 2 3 4 5 0 1</posList></LinearRing></exterior><interior><LinearRing><posList srsDimension=\"2\">6 7 8 9 10 11 6 7</posList></LinearRing></interior></Polygon>",
760  NULL, 0, 0, "");
761 
762  /* GML3 Triangle */
764  "TRIANGLE((0 1,2 3,4 5,0 1))",
765  "<Triangle><exterior><LinearRing><posList srsDimension=\"2\">0 1 2 3 4 5 0 1</posList></LinearRing></exterior></Triangle>",
766  NULL, 0, 0, "");
767 
768 
769  /* GML2 MultiPoint */
771  "MULTIPOINT(0 1,2 3)",
772  "<MultiPoint><pointMember><Point><coordinates>0,1</coordinates></Point></pointMember><pointMember><Point><coordinates>2,3</coordinates></Point></pointMember></MultiPoint>",
773  NULL, 0, "");
774 
775  /* GML3 MultiPoint */
777  "MULTIPOINT(0 1,2 3)",
778  "<MultiPoint><pointMember><Point><pos srsDimension=\"2\">0 1</pos></Point></pointMember><pointMember><Point><pos srsDimension=\"2\">2 3</pos></Point></pointMember></MultiPoint>",
779  NULL, 0, 0, "");
780 
781 
782  /* GML2 Multiline */
784  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
785  "<MultiLineString><lineStringMember><LineString><coordinates>0,1 2,3 4,5</coordinates></LineString></lineStringMember><lineStringMember><LineString><coordinates>6,7 8,9 10,11</coordinates></LineString></lineStringMember></MultiLineString>",
786  NULL, 0, "");
787 
788  /* GML3 Multiline */
790  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
791  "<MultiCurve><curveMember><Curve><segments><LineStringSegment><posList srsDimension=\"2\">0 1 2 3 4 5</posList></LineStringSegment></segments></Curve></curveMember><curveMember><Curve><segments><LineStringSegment><posList srsDimension=\"2\">6 7 8 9 10 11</posList></LineStringSegment></segments></Curve></curveMember></MultiCurve>",
792  NULL, 0, 0, "");
793 
794 
795  /* GML2 MultiPolygon */
797  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
798  "<MultiPolygon><polygonMember><Polygon><outerBoundaryIs><LinearRing><coordinates>0,1 2,3 4,5 0,1</coordinates></LinearRing></outerBoundaryIs></Polygon></polygonMember><polygonMember><Polygon><outerBoundaryIs><LinearRing><coordinates>6,7 8,9 10,11 6,7</coordinates></LinearRing></outerBoundaryIs></Polygon></polygonMember></MultiPolygon>",
799  NULL, 0, "");
800 
801  /* GML3 MultiPolygon */
803  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
804  "<MultiSurface><surfaceMember><Polygon><exterior><LinearRing><posList srsDimension=\"2\">0 1 2 3 4 5 0 1</posList></LinearRing></exterior></Polygon></surfaceMember><surfaceMember><Polygon><exterior><LinearRing><posList srsDimension=\"2\">6 7 8 9 10 11 6 7</posList></LinearRing></exterior></Polygon></surfaceMember></MultiSurface>",
805  NULL, 0, 0, "");
806 
807  /* GML3 PolyhedralSurface */
809  "POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
810  "<PolyhedralSurface><polygonPatches><PolygonPatch><exterior><LinearRing><posList srsDimension=\"2\">0 1 2 3 4 5 0 1</posList></LinearRing></exterior></PolygonPatch><PolygonPatch><exterior><LinearRing><posList srsDimension=\"2\">6 7 8 9 10 11 6 7</posList></LinearRing></exterior></PolygonPatch></polygonPatches></PolyhedralSurface>",
811  NULL, 0, 0, "");
812 
813  /* GML3 PolyhedralSurface */
815  "TIN(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
816  "<Tin><trianglePatches><Triangle><exterior><LinearRing><posList srsDimension=\"2\">0 1 2 3 4 5 0 1</posList></LinearRing></exterior></Triangle><Triangle><exterior><LinearRing><posList srsDimension=\"2\">6 7 8 9 10 11 6 7</posList></LinearRing></exterior></Triangle></trianglePatches></Tin>",
817  NULL, 0, 0, "");
818 
819  /* GML2 - GeometryCollection */
821  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
822  "<MultiGeometry><geometryMember><Point><coordinates>0,1</coordinates></Point></geometryMember><geometryMember><LineString><coordinates>2,3 4,5</coordinates></LineString></geometryMember></MultiGeometry>",
823  NULL, 0, "");
824 
825  /* GML3 - GeometryCollection */
827  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
828  "<MultiGeometry><geometryMember><Point><pos srsDimension=\"2\">0 1</pos></Point></geometryMember><geometryMember><Curve><segments><LineStringSegment><posList srsDimension=\"2\">2 3 4 5</posList></LineStringSegment></segments></Curve></geometryMember></MultiGeometry>",
829  NULL, 0, 0, "");
830 
831  /* GML2 - Nested GeometryCollection */
833  "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
834  "<MultiGeometry><geometryMember><Point><coordinates>0,1</coordinates></Point></geometryMember><geometryMember><MultiGeometry><geometryMember><LineString><coordinates>2,3 4,5</coordinates></LineString></geometryMember></MultiGeometry></geometryMember></MultiGeometry>",
835  NULL, 0, "");
836 
837  /* GML3 - Nested GeometryCollection */
839  "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
840  "<MultiGeometry><geometryMember><Point><pos srsDimension=\"2\">0 1</pos></Point></geometryMember><geometryMember><MultiGeometry><geometryMember><Curve><segments><LineStringSegment><posList srsDimension=\"2\">2 3 4 5</posList></LineStringSegment></segments></Curve></geometryMember></MultiGeometry></geometryMember></MultiGeometry>",
841  NULL, 0, 0, "");
842 
843 
844 
845 }
846 
847 
848 static void out_gml_test_geoms_nodims(void)
849 {
850  /* GML3 - Linestring */
852  "LINESTRING(0 1,2 3,4 5)",
853  "<Curve><segments><LineStringSegment><posList>0 1 2 3 4 5</posList></LineStringSegment></segments></Curve>",
854  NULL, 0, 0, 0, "");
855 
856 
857  /* GML3 Polygon */
859  "POLYGON((0 1,2 3,4 5,0 1))",
860  "<Polygon><exterior><LinearRing><posList>0 1 2 3 4 5 0 1</posList></LinearRing></exterior></Polygon>",
861  NULL, 0, 0, 0, "");
862 
863 
864  /* GML3 Polygon - with internal ring */
866  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
867  "<Polygon><exterior><LinearRing><posList>0 1 2 3 4 5 0 1</posList></LinearRing></exterior><interior><LinearRing><posList>6 7 8 9 10 11 6 7</posList></LinearRing></interior></Polygon>",
868  NULL, 0, 0, 0, "");
869 
870  /* GML3 Triangle */
872  "TRIANGLE((0 1,2 3,4 5,0 1))",
873  "<Triangle><exterior><LinearRing><posList>0 1 2 3 4 5 0 1</posList></LinearRing></exterior></Triangle>",
874  NULL, 0, 0, 0, "");
875 
876 
877  /* GML3 MultiPoint */
879  "MULTIPOINT(0 1,2 3)",
880  "<MultiPoint><pointMember><Point><pos>0 1</pos></Point></pointMember><pointMember><Point><pos>2 3</pos></Point></pointMember></MultiPoint>",
881  NULL, 0, 0, 0, "");
882 
883 
884  /* GML3 Multiline */
886  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
887  "<MultiCurve><curveMember><Curve><segments><LineStringSegment><posList>0 1 2 3 4 5</posList></LineStringSegment></segments></Curve></curveMember><curveMember><Curve><segments><LineStringSegment><posList>6 7 8 9 10 11</posList></LineStringSegment></segments></Curve></curveMember></MultiCurve>",
888  NULL, 0, 0, 0, "");
889 
890 
891  /* GML3 MultiPolygon */
893  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
894  "<MultiSurface><surfaceMember><Polygon><exterior><LinearRing><posList>0 1 2 3 4 5 0 1</posList></LinearRing></exterior></Polygon></surfaceMember><surfaceMember><Polygon><exterior><LinearRing><posList>6 7 8 9 10 11 6 7</posList></LinearRing></exterior></Polygon></surfaceMember></MultiSurface>",
895  NULL, 0, 0, 0, "");
896 
897  /* GML3 PolyhedralSurface */
899  "POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
900  "<PolyhedralSurface><polygonPatches><PolygonPatch><exterior><LinearRing><posList>0 1 2 3 4 5 0 1</posList></LinearRing></exterior></PolygonPatch><PolygonPatch><exterior><LinearRing><posList>6 7 8 9 10 11 6 7</posList></LinearRing></exterior></PolygonPatch></polygonPatches></PolyhedralSurface>",
901  NULL, 0, 0, 0, "");
902 
903  /* GML3 Tin */
905  "TIN(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
906  "<Tin><trianglePatches><Triangle><exterior><LinearRing><posList>0 1 2 3 4 5 0 1</posList></LinearRing></exterior></Triangle><Triangle><exterior><LinearRing><posList>6 7 8 9 10 11 6 7</posList></LinearRing></exterior></Triangle></trianglePatches></Tin>",
907  NULL, 0, 0, 0, "");
908 
909  /* GML3 - GeometryCollection */
911  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
912  "<MultiGeometry><geometryMember><Point><pos>0 1</pos></Point></geometryMember><geometryMember><Curve><segments><LineStringSegment><posList>2 3 4 5</posList></LineStringSegment></segments></Curve></geometryMember></MultiGeometry>",
913  NULL, 0, 0, 0, "");
914 
915  /* GML3 - Nested GeometryCollection */
917  "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
918  "<MultiGeometry><geometryMember><Point><pos>0 1</pos></Point></geometryMember><geometryMember><MultiGeometry><geometryMember><Curve><segments><LineStringSegment><posList>2 3 4 5</posList></LineStringSegment></segments></Curve></geometryMember></MultiGeometry></geometryMember></MultiGeometry>",
919  NULL, 0, 0, 0, "");
920 }
921 
922 static void out_gml2_extent(void)
923 {
924  /* GML2: Point */
926  "POINT(-15 60)",
927  "<Box><coordinates>-15,60 -15,60</coordinates></Box>",
928  NULL, 15, "");
930  "POINT(-15 60)",
931  "<gml:Box><gml:coordinates>-15,60 -15,60</gml:coordinates></gml:Box>",
932  NULL, 15, "gml:");
934  "POINT(-15 60)",
935  "<Box srsName=\"urn:ogc:def:crs:EPSG::4326\"><coordinates>-15,60 -15,60</coordinates></Box>",
936  "urn:ogc:def:crs:EPSG::4326", 15, "");
937 
938  /* GML2: Multipoint */
940  "MULTIPOINT(2 3, -5 -6)",
941  "<Box><coordinates>-5,-6 2,3</coordinates></Box>",
942  NULL, 15, "");
943 
944  /* GML2: Linestring */
946  "LINESTRING(0 1,2 3,4 5)",
947  "<Box><coordinates>0,1 4,5</coordinates></Box>",
948  NULL, 15, "");
949 
950  /* GML2: MultiLinestring */
952  "MULTILINESTRING((0 1,2 3),(4 5, 10 6))",
953  "<Box><coordinates>0,1 10,6</coordinates></Box>",
954  NULL, 15, "");
955 
956  /* GML2: Polygon */
958  "POLYGON((1 7,7 14, 14 7, 1 7))",
959  "<Box><coordinates>1,7 14,14</coordinates></Box>",
960  NULL, 15, "");
961 
962  /* GML2: MultiPolygon */
964  "MULTIPOLYGON(((1 7,7 14, 14 7, 1 7)),((-4 -6, -15 3, 0 0, -4 -6)))",
965  "<Box><coordinates>-15,-6 14,14</coordinates></Box>",
966  NULL, 15, "");
967 
968  /* GML2: MultiSurface */
970  "MULTISURFACE(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)),((7 8,10 10,6 14,4 11,7 8)))",
971  "<Box><coordinates>-2,-1 10,14</coordinates></Box>",
972  NULL, 15, "");
973 
974  /* GML2: empty */
976  "GEOMETRYCOLLECTION EMPTY",
977  "<Box/>",
978  NULL, 15, "");
979 
980  /* GML2: empty with srsName */
982  "GEOMETRYCOLLECTION EMPTY",
983  "<Box srsName=\"urn:ogc:def:crs:EPSG::4326\"/>",
984  "urn:ogc:def:crs:EPSG::4326", 15, "");
985 
986 }
987 
988 static void out_gml3_extent(void)
989 {
990  /* GML3: Point */
992  "POINT(-15 60)",
993  "<Envelope><lowerCorner>-15 60</lowerCorner><upperCorner>-15 60</upperCorner></Envelope>",
994  NULL, 15, 0, "");
996  "POINT(-15 60)",
997  "<gml:Envelope><gml:lowerCorner>-15 60</gml:lowerCorner><gml:upperCorner>-15 60</gml:upperCorner></gml:Envelope>",
998  NULL, 15, 0, "gml:");
1000  "POINT(-15 60)",
1001  "<Envelope srsName=\"urn:ogc:def:crs:EPSG::4326\"><lowerCorner>-15 60</lowerCorner><upperCorner>-15 60</upperCorner></Envelope>",
1002  "urn:ogc:def:crs:EPSG::4326", 15, 0, "");
1003 
1004  /* GML3: Multipoint */
1006  "MULTIPOINT(2 3, -5 -6)",
1007  "<Envelope><lowerCorner>-5 -6</lowerCorner><upperCorner>2 3</upperCorner></Envelope>",
1008  NULL, 15, 0, "");
1009 
1010  /* GML3: Linestring */
1012  "LINESTRING(0 1,2 3,4 5)",
1013  "<Envelope><lowerCorner>0 1</lowerCorner><upperCorner>4 5</upperCorner></Envelope>",
1014  NULL, 15, 0, "");
1015 
1016  /* GML3: MultiLinestring */
1018  "MULTILINESTRING((0 1,2 3),(4 5, 10 6))",
1019  "<Envelope><lowerCorner>0 1</lowerCorner><upperCorner>10 6</upperCorner></Envelope>",
1020  NULL, 15, 0, "");
1022  "MULTILINESTRING((0 1,2 3),(4 5, 10 6))",
1023  "<Envelope><lowerCorner>1 0</lowerCorner><upperCorner>6 10</upperCorner></Envelope>",
1024  NULL, 15, LW_GML_IS_DEGREE, "");
1026  "MULTILINESTRING((0 1,2 3),(4 5, 10 6))",
1027  "<Envelope srsDimension=\"2\"><lowerCorner>1 0</lowerCorner><upperCorner>6 10</upperCorner></Envelope>",
1028  NULL, 15, LW_GML_IS_DEGREE|LW_GML_IS_DIMS, "");
1030  "MULTILINESTRING((0 1 10,2 3 30),(4 5 50, 10 6 -70))",
1031  "<Envelope srsDimension=\"3\"><lowerCorner>1 0 -70</lowerCorner><upperCorner>6 10 50</upperCorner></Envelope>",
1032  NULL, 15, LW_GML_IS_DEGREE|LW_GML_IS_DIMS, "");
1033 
1034  /* GML3: Polygon */
1036  "POLYGON((1 7,7 14, 14 7, 1 7))",
1037  "<Envelope><lowerCorner>1 7</lowerCorner><upperCorner>14 14</upperCorner></Envelope>",
1038  NULL, 15, 0, "");
1039 
1040  /* GML3: MultiPolygon */
1042  "MULTIPOLYGON(((1 7,7 14, 14 7, 1 7)),((-4 -6, -15 3, 0 0, -4 -6)))",
1043  "<Envelope><lowerCorner>-15 -6</lowerCorner><upperCorner>14 14</upperCorner></Envelope>",
1044  NULL, 15, 0, "");
1045 
1046  /* GML3: MultiSurface */
1048  "MULTISURFACE(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)),((7 8,10 10,6 14,4 11,7 8)))",
1049  "<Envelope><lowerCorner>-2 -1</lowerCorner><upperCorner>10 14</upperCorner></Envelope>",
1050  NULL, 15, 0, "");
1051 
1052  /* GML3: empty */
1054  "GEOMETRYCOLLECTION EMPTY",
1055  "<Envelope/>",
1056  NULL, 15, 0, "");
1057 
1058  /* GML3: empty with srsName */
1060  "GEOMETRYCOLLECTION EMPTY",
1061  "<Envelope srsName=\"urn:ogc:def:crs:EPSG::4326\"/>",
1062  "urn:ogc:def:crs:EPSG::4326", 15, 0, "");
1063 
1064 }
1065 
1066 /*
1067 ** Used by test harness to register the tests in this file.
1068 */
1069 void out_gml_suite_setup(void);
1071 {
1072  CU_pSuite suite = CU_add_suite("gml_output", NULL, NULL);
1080  PG_ADD_TEST(suite, out_gml2_extent);
1081  PG_ADD_TEST(suite, out_gml3_extent);
1082 }
static uint8_t precision
Definition: cu_in_twkb.c:25
static void do_gml3_test(char *in, char *out, char *srs, int precision, int is_geodetic)
Definition: cu_out_gml.c:72
static void out_gml_test_srid(void)
Definition: cu_out_gml.c:244
static void out_gml2_extent(void)
Definition: cu_out_gml.c:922
static void do_gml2_extent_test(char *in, char *out, char *srs, double precision, char *prefix)
Definition: cu_out_gml.c:150
static void out_gml_test_geoms_nodims(void)
Definition: cu_out_gml.c:848
static void out_gml_test_geodetic(void)
Definition: cu_out_gml.c:363
static void out_gml3_extent(void)
Definition: cu_out_gml.c:988
static void do_gml2_test_prefix(char *in, char *out, char *srs, int precision, const char *prefix)
Definition: cu_out_gml.c:38
static void do_gml2_unsupported(char *in, char *out)
Definition: cu_out_gml.c:132
void out_gml_suite_setup(void)
Definition: cu_out_gml.c:1070
static void out_gml_test_dims(void)
Definition: cu_out_gml.c:379
static void do_gml3_test_opts(char *in, char *out, char *srs, int precision, int opts)
Definition: cu_out_gml.c:55
static void out_gml_test_precision(void)
Definition: cu_out_gml.c:190
static void do_gml3_extent_test(char *in, char *out, char *srs, double precision, int opts, char *prefix)
Definition: cu_out_gml.c:170
static void out_gml_test_geoms(void)
Definition: cu_out_gml.c:421
static void out_gml_test_geoms_prefix(void)
Definition: cu_out_gml.c:601
static void do_gml3_test_prefix(char *in, char *out, char *srs, int precision, int is_geodetic, const char *prefix)
Definition: cu_out_gml.c:91
static void do_gml2_test(char *in, char *out, char *srs, int precision)
Definition: cu_out_gml.c:21
static void do_gml3_test_nodims(char *in, char *out, char *srs, int precision, int is_geodetic, int is_dims, const char *prefix)
Definition: cu_out_gml.c:111
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
#define PG_ADD_TEST(suite, testfunc)
#define LW_GML_IS_DEGREE
For GML3 only, declare that datas are lat/lon.
Definition: liblwgeom.h:1544
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
#define LW_GML_SHORTLINE
For GML3, use <LineString> rather than <Curve> for lines.
Definition: liblwgeom.h:1546
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
Definition: lwout_gml.c:717
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
Definition: lwout_gml.c:213
void lwfree(void *mem)
Definition: lwutil.c:244
#define LW_GML_IS_DIMS
Macros for specifying GML options.
Definition: liblwgeom.h:1542
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
Definition: lwout_gml.c:198
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
char * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
VERSION GML 2 takes a GEOMETRY and returns a GML2 representation.
Definition: lwout_gml.c:231
opts
Definition: ovdump.py:44