PostGIS  2.5.7dev-r@@SVN_REVISION@@
cu_out_kml.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  * Copyright 2010 Olivier Courtin <olivier.courtin@oslandia.com>
6  *
7  * This is free software; you can redistribute and/or modify it under
8  * the terms of the GNU General Public Licence. See the COPYING file.
9  *
10  **********************************************************************/
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include "CUnit/Basic.h"
16 
17 #include "liblwgeom_internal.h"
18 #include "cu_tester.h"
19 
20 static void do_kml_test(char * in, char * out, int precision)
21 {
22  LWGEOM *g;
23  char * h;
24 
26  h = lwgeom_to_kml2(g, precision, "");
27 
28  if (strcmp(h, out))
29  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
30 
31  CU_ASSERT_STRING_EQUAL(h, out);
32 
33  lwgeom_free(g);
34  lwfree(h);
35 }
36 
37 
38 static void do_kml_unsupported(char * in, char * out)
39 {
40  LWGEOM *g;
41  char *h;
42 
44  h = lwgeom_to_kml2(g, 0, "");
45 
46  if (strcmp(cu_error_msg, out))
47  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n",
48  in, cu_error_msg, out);
49 
50  CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
52 
53  lwfree(h);
54  lwgeom_free(g);
55 }
56 
57 
58 static void do_kml_test_prefix(char * in, char * out, int precision, const char *prefix)
59 {
60  LWGEOM *g;
61  char * h;
62 
64  h = lwgeom_to_kml2(g, precision, prefix);
65 
66  if (strcmp(h, out))
67  fprintf(stderr, "\nPrefix: %s\nIn: %s\nOut: %s\nTheo: %s\n",
68  prefix, in, h, out);
69 
70  CU_ASSERT_STRING_EQUAL(h, out);
71 
72  lwgeom_free(g);
73  lwfree(h);
74 }
75 
76 
77 static void out_kml_test_precision(void)
78 {
79  /* 0 precision, i.e a round */
81  "POINT(1.1111111111111 1.1111111111111)",
82  "<Point><coordinates>1,1</coordinates></Point>",
83  0);
84 
85  /* 3 digits precision */
87  "POINT(1.1111111111111 1.1111111111111)",
88  "<Point><coordinates>1.111,1.111</coordinates></Point>",
89  3);
90 
91  /* 9 digits precision */
93  "POINT(1.2345678901234 1.2345678901234)",
94  "<Point><coordinates>1.23456789,1.23456789</coordinates></Point>",
95  8);
96 
97  /* huge data */
99  "POINT(1E300 -1E300)",
100  "<Point><coordinates>1e+300,-1e+300</coordinates></Point>",
101  0);
102 }
103 
104 
105 static void out_kml_test_dims(void)
106 {
107  /* 3D */
108  do_kml_test(
109  "POINT(0 1 2)",
110  "<Point><coordinates>0,1,2</coordinates></Point>",
111  0);
112 
113  /* 3DM */
114  do_kml_test(
115  "POINTM(0 1 2)",
116  "<Point><coordinates>0,1</coordinates></Point>",
117  0);
118 
119  /* 4D */
120  do_kml_test(
121  "POINT(0 1 2 3)",
122  "<Point><coordinates>0,1,2</coordinates></Point>",
123  0);
124 }
125 
126 
127 static void out_kml_test_geoms(void)
128 {
129  /* Linestring */
130  do_kml_test(
131  "LINESTRING(0 1,2 3,4 5)",
132  "<LineString><coordinates>0,1 2,3 4,5</coordinates></LineString>",
133  0);
134 
135  /* Polygon */
136  do_kml_test(
137  "POLYGON((0 1,2 3,4 5,0 1))",
138  "<Polygon><outerBoundaryIs><LinearRing><coordinates>0,1 2,3 4,5 0,1</coordinates></LinearRing></outerBoundaryIs></Polygon>",
139  0);
140 
141  /* Polygon - with internal ring */
142  do_kml_test(
143  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
144  "<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>",
145  0);
146 
147  /* MultiPoint */
148  do_kml_test(
149  "MULTIPOINT(0 1,2 3)",
150  "<MultiGeometry><Point><coordinates>0,1</coordinates></Point><Point><coordinates>2,3</coordinates></Point></MultiGeometry>",
151  0);
152 
153  /* MultiLine */
154  do_kml_test(
155  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
156  "<MultiGeometry><LineString><coordinates>0,1 2,3 4,5</coordinates></LineString><LineString><coordinates>6,7 8,9 10,11</coordinates></LineString></MultiGeometry>",
157  0);
158 
159  /* MultiPolygon */
160  do_kml_test(
161  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
162  "<MultiGeometry><Polygon><outerBoundaryIs><LinearRing><coordinates>0,1 2,3 4,5 0,1</coordinates></LinearRing></outerBoundaryIs></Polygon><Polygon><outerBoundaryIs><LinearRing><coordinates>6,7 8,9 10,11 6,7</coordinates></LinearRing></outerBoundaryIs></Polygon></MultiGeometry>",
163  0);
164 
165  /* GeometryCollection */
167  "GEOMETRYCOLLECTION(POINT(0 1))",
168  "lwgeom_to_kml2: 'GeometryCollection' geometry type not supported");
169 
170  /* CircularString */
172  "CIRCULARSTRING(-2 0,0 2,2 0,0 2,2 4)",
173  "lwgeom_to_kml2: 'CircularString' geometry type not supported");
174 
175  /* CompoundCurve */
177  "COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1,1 0),(1 0,0 1))",
178  "lwgeom_to_kml2: 'CompoundCurve' geometry type not supported");
179 
180  /* CurvePolygon */
182  "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))",
183  "lwgeom_to_kml2: 'CurvePolygon' geometry type not supported");
184 
185  /* MultiCurve */
187  "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 2))",
188  "lwgeom_to_kml2: 'MultiCurve' geometry type not supported");
189 
190  /* MultiSurface */
192  "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)))",
193  "lwgeom_to_kml2: 'MultiSurface' geometry type not supported");
194 }
195 
196 static void out_kml_test_prefix(void)
197 {
198  /* Linestring */
200  "LINESTRING(0 1,2 3,4 5)",
201  "<kml:LineString><kml:coordinates>0,1 2,3 4,5</kml:coordinates></kml:LineString>",
202  0, "kml:");
203 
204  /* Polygon */
206  "POLYGON((0 1,2 3,4 5,0 1))",
207  "<kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>0,1 2,3 4,5 0,1</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs></kml:Polygon>",
208  0, "kml:");
209 
210  /* Polygon - with internal ring */
212  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
213  "<kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>0,1 2,3 4,5 0,1</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs><kml:innerBoundaryIs><kml:LinearRing><kml:coordinates>6,7 8,9 10,11 6,7</kml:coordinates></kml:LinearRing></kml:innerBoundaryIs></kml:Polygon>",
214  0, "kml:");
215 
216  /* MultiPoint */
218  "MULTIPOINT(0 1,2 3)",
219  "<kml:MultiGeometry><kml:Point><kml:coordinates>0,1</kml:coordinates></kml:Point><kml:Point><kml:coordinates>2,3</kml:coordinates></kml:Point></kml:MultiGeometry>",
220  0, "kml:");
221 
222  /* MultiLine */
224  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
225  "<kml:MultiGeometry><kml:LineString><kml:coordinates>0,1 2,3 4,5</kml:coordinates></kml:LineString><kml:LineString><kml:coordinates>6,7 8,9 10,11</kml:coordinates></kml:LineString></kml:MultiGeometry>",
226  0, "kml:");
227 
228  /* MultiPolygon */
230  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
231  "<kml:MultiGeometry><kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>0,1 2,3 4,5 0,1</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs></kml:Polygon><kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>6,7 8,9 10,11 6,7</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs></kml:Polygon></kml:MultiGeometry>",
232  0, "kml:");
233 
234 }
235 /*
236 ** Used by test harness to register the tests in this file.
237 */
238 void out_kml_suite_setup(void);
240 {
241  CU_pSuite suite = CU_add_suite("kml_output", NULL, NULL);
246 }
static uint8_t precision
Definition: cu_in_twkb.c:25
static void out_kml_test_dims(void)
Definition: cu_out_kml.c:105
static void out_kml_test_prefix(void)
Definition: cu_out_kml.c:196
static void do_kml_test(char *in, char *out, int precision)
Definition: cu_out_kml.c:20
static void out_kml_test_precision(void)
Definition: cu_out_kml.c:77
void out_kml_suite_setup(void)
Definition: cu_out_kml.c:239
static void do_kml_test_prefix(char *in, char *out, int precision, const char *prefix)
Definition: cu_out_kml.c:58
static void out_kml_test_geoms(void)
Definition: cu_out_kml.c:127
static void do_kml_unsupported(char *in, char *out)
Definition: cu_out_kml.c:38
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
#define PG_ADD_TEST(suite, testfunc)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:43
void lwfree(void *mem)
Definition: lwutil.c:244
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904