PostGIS  2.1.10dev-r@@SVN_REVISION@@
cu_out_kml.c
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: cu_out_kml.c 13242 2015-02-19 00:22:22Z pramsey $
3  *
4  * PostGIS - Spatial Types for PostgreSQL
5  * http://postgis.net
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_kml_test(char * in, char * out, int precision)
22 {
23  LWGEOM *g;
24  char * h;
25 
27  h = lwgeom_to_kml2(g, precision, "");
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 
39 static void do_kml_unsupported(char * in, char * out)
40 {
41  LWGEOM *g;
42  char *h;
43 
45  h = lwgeom_to_kml2(g, 0, "");
46 
47  if (strcmp(cu_error_msg, out))
48  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n",
49  in, cu_error_msg, out);
50 
51  CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
53 
54  lwfree(h);
55  lwgeom_free(g);
56 }
57 
58 
59 static void do_kml_test_prefix(char * in, char * out, int precision, const char *prefix)
60 {
61  LWGEOM *g;
62  char * h;
63 
65  h = lwgeom_to_kml2(g, precision, prefix);
66 
67  if (strcmp(h, out))
68  fprintf(stderr, "\nPrefix: %s\nIn: %s\nOut: %s\nTheo: %s\n",
69  prefix, in, h, out);
70 
71  CU_ASSERT_STRING_EQUAL(h, out);
72 
73  lwgeom_free(g);
74  lwfree(h);
75 }
76 
77 
78 static void out_kml_test_precision(void)
79 {
80  /* 0 precision, i.e a round */
82  "POINT(1.1111111111111 1.1111111111111)",
83  "<Point><coordinates>1,1</coordinates></Point>",
84  0);
85 
86  /* 3 digits precision */
88  "POINT(1.1111111111111 1.1111111111111)",
89  "<Point><coordinates>1.111,1.111</coordinates></Point>",
90  3);
91 
92  /* 9 digits precision */
94  "POINT(1.2345678901234 1.2345678901234)",
95  "<Point><coordinates>1.23456789,1.23456789</coordinates></Point>",
96  8);
97 
98  /* huge data */
100  "POINT(1E300 -1E300)",
101  "<Point><coordinates>1e+300,-1e+300</coordinates></Point>",
102  0);
103 }
104 
105 
106 static void out_kml_test_dims(void)
107 {
108  /* 3D */
109  do_kml_test(
110  "POINT(0 1 2)",
111  "<Point><coordinates>0,1,2</coordinates></Point>",
112  0);
113 
114  /* 3DM */
115  do_kml_test(
116  "POINTM(0 1 2)",
117  "<Point><coordinates>0,1</coordinates></Point>",
118  0);
119 
120  /* 4D */
121  do_kml_test(
122  "POINT(0 1 2 3)",
123  "<Point><coordinates>0,1,2</coordinates></Point>",
124  0);
125 }
126 
127 
128 static void out_kml_test_geoms(void)
129 {
130  /* Linestring */
131  do_kml_test(
132  "LINESTRING(0 1,2 3,4 5)",
133  "<LineString><coordinates>0,1 2,3 4,5</coordinates></LineString>",
134  0);
135 
136  /* Polygon */
137  do_kml_test(
138  "POLYGON((0 1,2 3,4 5,0 1))",
139  "<Polygon><outerBoundaryIs><LinearRing><coordinates>0,1 2,3 4,5 0,1</coordinates></LinearRing></outerBoundaryIs></Polygon>",
140  0);
141 
142  /* Polygon - with internal ring */
143  do_kml_test(
144  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
145  "<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>",
146  0);
147 
148  /* MultiPoint */
149  do_kml_test(
150  "MULTIPOINT(0 1,2 3)",
151  "<MultiGeometry><Point><coordinates>0,1</coordinates></Point><Point><coordinates>2,3</coordinates></Point></MultiGeometry>",
152  0);
153 
154  /* MultiLine */
155  do_kml_test(
156  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
157  "<MultiGeometry><LineString><coordinates>0,1 2,3 4,5</coordinates></LineString><LineString><coordinates>6,7 8,9 10,11</coordinates></LineString></MultiGeometry>",
158  0);
159 
160  /* MultiPolygon */
161  do_kml_test(
162  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
163  "<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>",
164  0);
165 
166  /* GeometryCollection */
168  "GEOMETRYCOLLECTION(POINT(0 1))",
169  "lwgeom_to_kml2: 'GeometryCollection' geometry type not supported");
170 
171  /* CircularString */
173  "CIRCULARSTRING(-2 0,0 2,2 0,0 2,2 4)",
174  "lwgeom_to_kml2: 'CircularString' geometry type not supported");
175 
176  /* CompoundCurve */
178  "COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1,1 0),(1 0,0 1))",
179  "lwgeom_to_kml2: 'CompoundCurve' geometry type not supported");
180 
181  /* CurvePolygon */
183  "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))",
184  "lwgeom_to_kml2: 'CurvePolygon' geometry type not supported");
185 
186  /* MultiCurve */
188  "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 2))",
189  "lwgeom_to_kml2: 'MultiCurve' geometry type not supported");
190 
191  /* MultiSurface */
193  "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)))",
194  "lwgeom_to_kml2: 'MultiSurface' geometry type not supported");
195 }
196 
197 static void out_kml_test_prefix(void)
198 {
199  /* Linestring */
201  "LINESTRING(0 1,2 3,4 5)",
202  "<kml:LineString><kml:coordinates>0,1 2,3 4,5</kml:coordinates></kml:LineString>",
203  0, "kml:");
204 
205  /* Polygon */
207  "POLYGON((0 1,2 3,4 5,0 1))",
208  "<kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>0,1 2,3 4,5 0,1</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs></kml:Polygon>",
209  0, "kml:");
210 
211  /* Polygon - with internal ring */
213  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
214  "<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>",
215  0, "kml:");
216 
217  /* MultiPoint */
219  "MULTIPOINT(0 1,2 3)",
220  "<kml:MultiGeometry><kml:Point><kml:coordinates>0,1</kml:coordinates></kml:Point><kml:Point><kml:coordinates>2,3</kml:coordinates></kml:Point></kml:MultiGeometry>",
221  0, "kml:");
222 
223  /* MultiLine */
225  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
226  "<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>",
227  0, "kml:");
228 
229  /* MultiPolygon */
231  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
232  "<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>",
233  0, "kml:");
234 
235 }
236 /*
237 ** Used by test harness to register the tests in this file.
238 */
239 void out_kml_suite_setup(void);
241 {
242  CU_pSuite suite = CU_add_suite("KML Output", NULL, NULL);
247 }
void out_kml_suite_setup(void)
Definition: cu_out_kml.c:240
void lwfree(void *mem)
Definition: lwutil.c:190
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
static void do_kml_test_prefix(char *in, char *out, int precision, const char *prefix)
Definition: cu_out_kml.c:59
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
void cu_error_msg_reset()
#define PG_ADD_TEST(suite, testfunc)
static void out_kml_test_precision(void)
Definition: cu_out_kml.c:78
static void out_kml_test_dims(void)
Definition: cu_out_kml.c:106
static void out_kml_test_geoms(void)
Definition: cu_out_kml.c:128
static void do_kml_unsupported(char *in, char *out)
Definition: cu_out_kml.c:39
static void do_kml_test(char *in, char *out, int precision)
Definition: cu_out_kml.c:21
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
char * lwgeom_to_kml2(const LWGEOM *geom, int precision, const char *prefix)
Definition: lwout_kml.c:32
static void out_kml_test_prefix(void)
Definition: cu_out_kml.c:197