PostGIS  3.4.0dev-r@@SVN_REVISION@@
cu_out_svg.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_svg_test(char * in, char * out, int precision, int relative)
21 {
23  lwvarlena_t *v = lwgeom_to_svg(g, precision, relative);
24 
25  ASSERT_VARLENA_EQUAL(v, out);
26 
27  lwgeom_free(g);
28  lwfree(v);
29 }
30 
31 
32 static void do_svg_unsupported(char * in, char * out)
33 {
35  lwvarlena_t *v = lwgeom_to_svg(g, 0, 0);
36 
39 
40  lwgeom_free(g);
41  lwfree(v);
42 }
43 
44 
45 static void out_svg_test_precision(void)
46 {
47  /* 0 precision, i.e a round - with Circle point */
49  "POINT(1.1111111111111 1.1111111111111)",
50  "cx=\"1\" cy=\"-1\"",
51  0, 0);
52 
53  /* 0 precision, i.e a round - with Point */
55  "POINT(1.1111111111111 1.1111111111111)",
56  "x=\"1\" y=\"-1\"",
57  0, 1);
58 
59  /* 0 precision, i.e a round - with PointArray */
61  "LINESTRING(1.1111111111111 1.1111111111111,1.1111111111111 1.1111111111111)",
62  "M 1 -1 L 1 -1",
63  0, 0);
64 
65  /* 0 precision, i.e a round - with relative PointArray */
67  "LINESTRING(1.1111111111111 1.1111111111111,1.1111111111111 1.1111111111111)",
68  "M 1 -1 l 0 0",
69  0, 1);
70 
71 
72  /* 9 digits precision - with Circle point */
74  "POINT(1.2345678901234 1.2345678901234)",
75  "cx=\"1.23456789\" cy=\"-1.23456789\"",
76  9, 0);
77 
78  /* 9 digits precision - with Point */
80  "POINT(1.2345678901234 1.2345678901234)",
81  "x=\"1.23456789\" y=\"-1.23456789\"",
82  9, 1);
83 
84  /* 9 digits precision - with PointArray */
86  "LINESTRING(1.2345678901234 1.2345678901234,2.3456789012345 2.3456789012345)",
87  "M 1.23456789 -1.23456789 L 2.345678901 -2.345678901",
88  9, 0);
89 
90  /* 9 digits precision - with relative PointArray */
92  "LINESTRING(1.2345678901234 1.2345678901234,2.3456789012345 2.3456789012345)",
93  "M 1.23456789 -1.23456789 l 1.111111011 -1.111111011",
94  9, 1);
95 
96 
97  /* huge data - with Circle point */
99  "POINT(1E300 -1E300)",
100  "cx=\"1e+300\" cy=\"1e+300\"",
101  0, 0);
102 
103  /* huge data - with Point */
104  do_svg_test(
105  "POINT(1E300 -1E300)",
106  "x=\"1e+300\" y=\"1e+300\"",
107  0, 1);
108 
109  /* huge data - with PointArray */
110  do_svg_test(
111  "LINESTRING(1E300 -1E300,1E301 -1E301)",
112  "M 1e+300 1e+300 L 1e+301 1e+301",
113  0, 0);
114 
115  /* huge data - with relative PointArray */
116  do_svg_test("LINESTRING(1E300 -1E300,1E301 -1E301)", "M 1e+300 1e+300 l 9e+300 9e+300", 0, 1);
117 }
118 
119 
120 static void out_svg_test_dims(void)
121 {
122  /* 4D - with Circle point */
123  do_svg_test(
124  "POINT(0 1 2 3)",
125  "cx=\"0\" cy=\"-1\"",
126  0, 0);
127 
128  /* 4D - with Point */
129  do_svg_test(
130  "POINT(0 1 2 3)",
131  "x=\"0\" y=\"-1\"",
132  0, 1);
133 
134  /* 4D - with PointArray */
135  do_svg_test(
136  "LINESTRING(0 1 2 3,4 5 6 7)",
137  "M 0 -1 L 4 -5",
138  0, 0);
139 
140  /* 4D - with relative PointArray */
141  do_svg_test(
142  "LINESTRING(0 1 2 3,4 5 6 7)",
143  "M 0 -1 l 4 -4",
144  0, 1);
145 }
146 
147 
148 static void out_svg_test_geoms(void)
149 {
150  /* Linestring */
151  do_svg_test(
152  "LINESTRING(0 1,2 3,4 5)",
153  "M 0 -1 L 2 -3 4 -5",
154  0, 0);
155 
156  /* Polygon */
157  do_svg_test(
158  "POLYGON((0 1,2 3,4 5,0 1))",
159  "M 0 -1 L 2 -3 4 -5 Z",
160  0, 0);
161 
162  /* Polygon - with internal ring */
163  do_svg_test(
164  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
165  "M 0 -1 L 2 -3 4 -5 Z M 6 -7 L 8 -9 10 -11 Z",
166  0, 0);
167 
168  /* MultiPoint */
169  do_svg_test(
170  "MULTIPOINT(0 1,2 3)",
171  "cx=\"0\" cy=\"-1\",cx=\"2\" cy=\"-3\"",
172  0, 0);
173 
174  /* MultiLine */
175  do_svg_test(
176  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
177  "M 0 -1 L 2 -3 4 -5 M 6 -7 L 8 -9 10 -11",
178  0, 0);
179 
180  /* MultiPolygon */
181  do_svg_test(
182  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
183  "M 0 -1 L 2 -3 4 -5 Z M 6 -7 L 8 -9 10 -11 Z",
184  0, 0);
185 
186  /* GeometryCollection */
187  do_svg_test(
188  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
189  "cx=\"0\" cy=\"-1\";M 2 -3 L 4 -5",
190  0, 0);
191 
192  /* CircularString */
193  do_svg_test(
194  "CIRCULARSTRING(-2 0,0 2,2 0,0 2,2 4)",
195  "M -2 0 A 2 2 0 0 1 2 0 A 2 2 0 0 1 2 -4",
196  0, 0);
197 
198  /* : Circle */
199  do_svg_test(
200  "CIRCULARSTRING(4 2,-2 2,4 2)",
201  "M 1 -2 m 3 0 a 3 3 0 1 0 -6 0 a 3 3 0 1 0 6 0",
202  0, 0);
203 
204  /* CompoundCurve */
205  do_svg_test(
206  "COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1,1 0),(1 0,0 1))",
207  "M 0 0 A 1 1 0 1 1 1 0 L 0 -1", 0, 0);
208 
209  /* MultiCurve */
210  do_svg_test(
211  "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 2))",
212  "M 5 -5 L 3 -5 3 -3 0 -3 M 0 0 A 2 2 0 0 0 2 -2", 0, 0);
213 
214  /* CurvePolygon */
215  do_svg_test(
216  "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))",
217  "M -2 0 A 1 1 0 0 0 0 0 A 1 1 0 0 0 2 0 A 2 2 0 0 0 -2 0 Z M -1 0 L 0 0 1 0 0 -1 -1 0 Z", 0, 0);
218 
219  /* MultiSurface */
220  do_svg_test(
221  "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)))",
222  "M -2 0 A 1 1 0 0 0 0 0 A 1 1 0 0 0 2 0 A 2 2 0 0 0 -2 0 Z M -1 0 L 0 0 1 0 0 -1 -1 0 Z M 7 -8 L 10 -10 6 -14 4 -11 Z", 0, 0);
223 
224  /* Empty GeometryCollection */
225  do_svg_test(
226  "GEOMETRYCOLLECTION EMPTY",
227  "",
228  0, 0);
229 
230  /* Nested GeometryCollection */
232  "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
233  "assvg_geom_buf: 'GeometryCollection' geometry type not supported.");
234 
235 }
236 
237 static void out_svg_test_relative(void)
238 {
239  /* Linestring */
240  do_svg_test(
241  "LINESTRING(0 1,2 3,4 5)",
242  "M 0 -1 l 2 -2 2 -2",
243  0, 1);
244 
245  /* Polygon */
246  do_svg_test(
247  "POLYGON((0 1,2 3,4 5,0 1))",
248  "M 0 -1 l 2 -2 2 -2 z",
249  0, 1);
250 
251  /* Polygon - with internal ring */
252  do_svg_test(
253  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
254  "M 0 -1 l 2 -2 2 -2 z M 6 -7 l 2 -2 2 -2 z",
255  0, 1);
256 
257  /* MultiPoint */
258  do_svg_test(
259  "MULTIPOINT(0 1,2 3)",
260  "x=\"0\" y=\"-1\",x=\"2\" y=\"-3\"",
261  0, 1);
262 
263  /* MultiLine */
264  do_svg_test(
265  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
266  "M 0 -1 l 2 -2 2 -2 M 6 -7 l 2 -2 2 -2",
267  0, 1);
268 
269  /* MultiPolygon */
270  do_svg_test(
271  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
272  "M 0 -1 l 2 -2 2 -2 z M 6 -7 l 2 -2 2 -2 z",
273  0, 1);
274 
275  /* GeometryCollection */
276  do_svg_test(
277  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
278  "x=\"0\" y=\"-1\";M 2 -3 l 2 -2",
279  0, 1);
280 }
281 
282 static void out_svg_test_srid(void)
283 {
284  /* SRID - with Circle point */
285  do_svg_test(
286  "SRID=4326;POINT(0 1)",
287  "cx=\"0\" cy=\"-1\"",
288  0, 0);
289 
290  /* SRID - with Point */
291  do_svg_test(
292  "SRID=4326;POINT(0 1)",
293  "x=\"0\" y=\"-1\"",
294  0, 1);
295 
296  /* SRID - with PointArray */
297  do_svg_test(
298  "SRID=4326;LINESTRING(0 1,2 3)",
299  "M 0 -1 L 2 -3",
300  0, 0);
301 
302  /* SRID - with relative PointArray */
303  do_svg_test(
304  "SRID=4326;LINESTRING(0 1,2 3)",
305  "M 0 -1 l 2 -2",
306  0, 1);
307 }
308 
309 /*
310 ** Used by test harness to register the tests in this file.
311 */
312 void out_svg_suite_setup(void);
314 {
315  CU_pSuite suite = CU_add_suite("svg_output", NULL, NULL);
321 }
static uint8_t precision
Definition: cu_in_twkb.c:25
static void out_svg_test_srid(void)
Definition: cu_out_svg.c:282
static void out_svg_test_geoms(void)
Definition: cu_out_svg.c:148
static void out_svg_test_relative(void)
Definition: cu_out_svg.c:237
static void do_svg_unsupported(char *in, char *out)
Definition: cu_out_svg.c:32
void out_svg_suite_setup(void)
Definition: cu_out_svg.c:313
static void out_svg_test_dims(void)
Definition: cu_out_svg.c:120
static void do_svg_test(char *in, char *out, int precision, int relative)
Definition: cu_out_svg.c:20
static void out_svg_test_precision(void)
Definition: cu_out_svg.c:45
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
#define ASSERT_VARLENA_EQUAL(v, s)
#define PG_ADD_TEST(suite, testfunc)
#define ASSERT_STRING_EQUAL(o, e)
lwvarlena_t * lwgeom_to_svg(const LWGEOM *geom, int precision, int relative)
Takes a GEOMETRY and returns a SVG representation.
Definition: lwout_svg.c:559
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2114
void lwfree(void *mem)
Definition: lwutil.c:242
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:905