PostGIS  3.1.6dev-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  /* Empty GeometryCollection */
193  do_svg_test(
194  "GEOMETRYCOLLECTION EMPTY",
195  "",
196  0, 0);
197 
198  /* Nested GeometryCollection */
200  "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
201  "assvg_geom_buf: 'GeometryCollection' geometry type not supported.");
202 
203  /* CircularString */
205  "CIRCULARSTRING(-2 0,0 2,2 0,0 2,2 4)",
206  "lwgeom_to_svg: 'CircularString' geometry type not supported");
207 
208  /* CompoundCurve */
210  "COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1,1 0),(1 0,0 1))",
211  "lwgeom_to_svg: 'CompoundCurve' geometry type not supported");
212 
213  /* CurvePolygon */
215  "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))",
216  "lwgeom_to_svg: 'CurvePolygon' geometry type not supported");
217 
218  /* MultiCurve */
220  "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 2))",
221  "lwgeom_to_svg: 'MultiCurve' geometry type not supported");
222 
223  /* MultiSurface */
225  "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)))",
226  "lwgeom_to_svg: 'MultiSurface' geometry type not supported");
227 }
228 
229 static void out_svg_test_relative(void)
230 {
231  /* Linestring */
232  do_svg_test(
233  "LINESTRING(0 1,2 3,4 5)",
234  "M 0 -1 l 2 -2 2 -2",
235  0, 1);
236 
237  /* Polygon */
238  do_svg_test(
239  "POLYGON((0 1,2 3,4 5,0 1))",
240  "M 0 -1 l 2 -2 2 -2 z",
241  0, 1);
242 
243  /* Polygon - with internal ring */
244  do_svg_test(
245  "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
246  "M 0 -1 l 2 -2 2 -2 z M 6 -7 l 2 -2 2 -2 z",
247  0, 1);
248 
249  /* MultiPoint */
250  do_svg_test(
251  "MULTIPOINT(0 1,2 3)",
252  "x=\"0\" y=\"-1\",x=\"2\" y=\"-3\"",
253  0, 1);
254 
255  /* MultiLine */
256  do_svg_test(
257  "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
258  "M 0 -1 l 2 -2 2 -2 M 6 -7 l 2 -2 2 -2",
259  0, 1);
260 
261  /* MultiPolygon */
262  do_svg_test(
263  "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
264  "M 0 -1 l 2 -2 2 -2 z M 6 -7 l 2 -2 2 -2 z",
265  0, 1);
266 
267  /* GeometryCollection */
268  do_svg_test(
269  "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
270  "x=\"0\" y=\"-1\";M 2 -3 l 2 -2",
271  0, 1);
272 }
273 
274 static void out_svg_test_srid(void)
275 {
276  /* SRID - with Circle point */
277  do_svg_test(
278  "SRID=4326;POINT(0 1)",
279  "cx=\"0\" cy=\"-1\"",
280  0, 0);
281 
282  /* SRID - with Point */
283  do_svg_test(
284  "SRID=4326;POINT(0 1)",
285  "x=\"0\" y=\"-1\"",
286  0, 1);
287 
288  /* SRID - with PointArray */
289  do_svg_test(
290  "SRID=4326;LINESTRING(0 1,2 3)",
291  "M 0 -1 L 2 -3",
292  0, 0);
293 
294  /* SRID - with relative PointArray */
295  do_svg_test(
296  "SRID=4326;LINESTRING(0 1,2 3)",
297  "M 0 -1 l 2 -2",
298  0, 1);
299 }
300 
301 /*
302 ** Used by test harness to register the tests in this file.
303 */
304 void out_svg_suite_setup(void);
306 {
307  CU_pSuite suite = CU_add_suite("svg_output", NULL, NULL);
313 }
static uint8_t precision
Definition: cu_in_twkb.c:25
static void out_svg_test_srid(void)
Definition: cu_out_svg.c:274
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:229
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:305
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:56
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2085
void lwfree(void *mem)
Definition: lwutil.c:242
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:905