PostGIS  2.5.7dev-r@@SVN_REVISION@@
cu_surface.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  * Copyright 2010-2012 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 "cu_surface.h"
13 
14 void triangle_parse(void)
15 {
16  LWGEOM *geom;
17  GSERIALIZED *g;
18  char *tmp;
19 
20  cu_error_msg_reset(); /* Because i don't trust that much prior tests... ;) */
21 
22  /* 2 dims */
23  geom = lwgeom_from_wkt("TRIANGLE((0 1,2 3,4 5,0 1))", LW_PARSER_CHECK_NONE);
24  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
25  CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
26  tmp = lwgeom_to_ewkt(geom);
27  CU_ASSERT_STRING_EQUAL("TRIANGLE((0 1,2 3,4 5,0 1))", tmp);
28  lwfree(tmp);
29  lwgeom_free(geom);
30  /* 3DM */
31  geom = lwgeom_from_wkt("TRIANGLEM((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE);
32  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
33  CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
34  tmp = lwgeom_to_ewkt(geom);
35  CU_ASSERT_STRING_EQUAL("TRIANGLEM((0 1 2,3 4 5,6 7 8,0 1 2))", tmp);
36  lwfree(tmp);
37  lwgeom_free(geom);
38 
39  /* ERROR: a missing Z values */
40  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7,0 1 2))", LW_PARSER_CHECK_NONE);
41  CU_ASSERT_STRING_EQUAL("can not mix dimensionality in a geometry", cu_error_msg);
43  lwgeom_free(geom);
44 
45  /* ERROR: non closed rings */
46  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 0 2))", LW_PARSER_CHECK_NONE);
47  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
49  lwgeom_free(geom);
50 
51  /* ERROR: non closed face in Z dim */
52  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 3))", LW_PARSER_CHECK_NONE);
53  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
55  lwgeom_free(geom);
56 
57  /* ERROR: non closed face in Z dim, with a 4D geom */
58  geom = lwgeom_from_wkt("TRIANGLE((0 1 2 3,4 5 6 7,8 9 10 11,0 1 3 3))", LW_PARSER_CHECK_NONE);
59  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
61  lwgeom_free(geom);
62 
63  /* ERROR: only 3 points in a face */
64  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,0 1 2))", LW_PARSER_CHECK_NONE);
65  CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg);
67  lwgeom_free(geom);
68 
69  /* ERROR: more than 4 points in a face */
70  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,9 10 11,0 1 2))", LW_PARSER_CHECK_NONE);
71  CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg);
73  lwgeom_free(geom);
74 
75  /* ERROR: no interior rings allowed */
76  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2),(9 10 11,12 13 14,15 16 17,9 10 11)", LW_PARSER_CHECK_NONE);
77  CU_ASSERT_STRING_EQUAL("parse error - invalid geometry", cu_error_msg);
79  lwgeom_free(geom);
80 
81  /* EMPTY face */
82  geom = lwgeom_from_wkt("TRIANGLE EMPTY", LW_PARSER_CHECK_NONE);
83  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
84  CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
85  tmp = lwgeom_to_wkt(geom, LW_PARSER_CHECK_NONE, 0, 0);
86  CU_ASSERT_STRING_EQUAL("TRIANGLE EMPTY", tmp);
87  lwfree(tmp);
88  lwgeom_free(geom);
89 
90  /* explicit SRID */
91  geom = lwgeom_from_wkt("SRID=4326;TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE);
92  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
93  CU_ASSERT_EQUAL(geom->type, TRIANGLETYPE);
94  CU_ASSERT_EQUAL(geom->srid, 4326);
95  tmp = lwgeom_to_ewkt(geom);
96  CU_ASSERT_STRING_EQUAL("SRID=4326;TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", tmp);
97  lwfree(tmp);
98  lwgeom_free(geom);
99 
100  /* geography support */
101  geom = lwgeom_from_wkt("TRIANGLE((0 1 2,3 4 5,6 7 8,0 1 2))", LW_PARSER_CHECK_NONE);
102  g = gserialized_from_lwgeom(geom, 0);
103  CU_ASSERT_EQUAL(gserialized_get_type(g), TRIANGLETYPE);
104  lwgeom_free(geom);
105  lwfree(g);
106 }
107 
108 
109 void tin_parse(void)
110 {
111  LWGEOM *geom;
112  GSERIALIZED *g;
113  char *tmp;
114 
115  cu_error_msg_reset(); /* Because i don't trust that much prior tests... ;) */
116 
117  /* empty */
118  geom = lwgeom_from_wkt("TIN EMPTY", LW_PARSER_CHECK_NONE);
119  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
120  CU_ASSERT_EQUAL(geom->type, TINTYPE);
121  tmp = lwgeom_to_ewkt(geom);
122  CU_ASSERT_STRING_EQUAL("TIN EMPTY", tmp);
123  lwfree(tmp);
124  lwgeom_free(geom);
125 
126  /* 2 dims */
127  geom = lwgeom_from_wkt("TIN(((0 1,2 3,4 5,0 1)))", LW_PARSER_CHECK_NONE);
128  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
129  CU_ASSERT_EQUAL(geom->type, TINTYPE);
130  tmp = lwgeom_to_ewkt(geom);
131  CU_ASSERT_STRING_EQUAL("TIN(((0 1,2 3,4 5,0 1)))", tmp);
132  lwfree(tmp);
133  lwgeom_free(geom);
134 
135  /* 3DM */
136  geom = lwgeom_from_wkt("TINM(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE);
137  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
138  CU_ASSERT_EQUAL(geom->type, TINTYPE);
139  tmp = lwgeom_to_ewkt(geom);
140  CU_ASSERT_STRING_EQUAL("TINM(((0 1 2,3 4 5,6 7 8,0 1 2)))", tmp);
141  lwfree(tmp);
142  lwgeom_free(geom);
143 
144  /* ERROR: a missing Z values */
145  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7,0 1 2)))", LW_PARSER_CHECK_NONE);
146  CU_ASSERT_STRING_EQUAL("can not mix dimensionality in a geometry", cu_error_msg);
148  lwgeom_free(geom);
149 
150  /* ERROR: non closed rings */
151  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 0 2)))", LW_PARSER_CHECK_NONE);
152  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
154  lwgeom_free(geom);
155 
156  /* ERROR: non closed face in Z dim */
157  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 1 3)))", LW_PARSER_CHECK_NONE);
158  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
160  lwgeom_free(geom);
161 
162  /* ERROR: non closed face in Z dim, with a 4D geom */
163  geom = lwgeom_from_wkt("TIN(((0 1 2 3,4 5 6 7,8 9 10 11,0 1 3 3)))", LW_PARSER_CHECK_NONE);
164  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
166  lwgeom_free(geom);
167 
168  /* ERROR: only 3 points in a face */
169  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,0 1 2)))", LW_PARSER_CHECK_NONE);
170  CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg);
172  lwgeom_free(geom);
173 
174  /* ERROR: more than 3 points in a face */
175  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,9 10 11,0 1 2)))", LW_PARSER_CHECK_NONE);
176  CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg);
178  lwgeom_free(geom);
179 
180  /* ERROR: use ring for triangle */
181  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 1 2),(9 10 11,12 13 14,15 16 17,9 10 11)))", LW_PARSER_CHECK_NONE);
182  CU_ASSERT_STRING_EQUAL("parse error - invalid geometry", cu_error_msg);
184  lwgeom_free(geom);
185 
186  /* EMPTY face */
187  geom = lwgeom_from_wkt("TIN EMPTY", LW_PARSER_CHECK_NONE);
188  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
189  CU_ASSERT_EQUAL(geom->type, TINTYPE);
190  tmp = lwgeom_to_ewkt(geom);
191  CU_ASSERT_STRING_EQUAL("TIN EMPTY", tmp);
192  lwfree(tmp);
193  lwgeom_free(geom);
194 
195  /* A simple tetrahedron */
196  geom = lwgeom_from_wkt("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", LW_PARSER_CHECK_NONE);
197  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
198  CU_ASSERT_EQUAL(geom->type, TINTYPE);
199  CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN);
200  tmp = lwgeom_to_ewkt(geom);
201  CU_ASSERT_STRING_EQUAL("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", tmp);
202  lwfree(tmp);
203  lwgeom_free(geom);
204 
205  /* A 4D tetrahedron */
206  geom = lwgeom_from_wkt("TIN(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))", LW_PARSER_CHECK_NONE);
207  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
208  CU_ASSERT_EQUAL(geom->type, TINTYPE);
209  CU_ASSERT_EQUAL(FLAGS_GET_M(geom->flags), 1);
210  CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN);
211  tmp = lwgeom_to_ewkt(geom);
212  CU_ASSERT_STRING_EQUAL("TIN(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))", tmp);
213  lwfree(tmp);
214  lwgeom_free(geom);
215 
216  /* explicit SRID */
217  geom = lwgeom_from_wkt("SRID=4326;TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", LW_PARSER_CHECK_NONE);
218  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
219  CU_ASSERT_EQUAL(geom->type, TINTYPE);
220  CU_ASSERT_EQUAL(geom->srid, 4326);
221  tmp = lwgeom_to_ewkt(geom);
222  CU_ASSERT_STRING_EQUAL("SRID=4326;TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", tmp);
223  lwfree(tmp);
224  lwgeom_free(geom);
225 
226  /* geography support */
227  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE);
228  g = gserialized_from_lwgeom(geom, 0);
229  CU_ASSERT_EQUAL(gserialized_get_type(g), TINTYPE);
230  lwgeom_free(geom);
231  lwfree(g);
232 }
233 
234 
236 {
237  LWGEOM *geom;
238  GSERIALIZED *g;
239  char *tmp;
240 
241  cu_error_msg_reset(); /* Because i don't trust that much prior tests... ;) */
242 
243  /* 2 dims */
244  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1)))", LW_PARSER_CHECK_NONE);
245  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
246  CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE);
247  tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0);
248  CU_ASSERT_STRING_EQUAL("010F00000001000000010300000001000000040000000000000000000000000000000000F03F00000000000000400000000000000840000000000000104000000000000014400000000000000000000000000000F03F", tmp);
249  lwfree(tmp);
250  tmp = lwgeom_to_ewkt(geom);
251  CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE(((0 1,2 3,4 5,0 1)))", tmp);
252  lwfree(tmp);
253  lwgeom_free(geom);
254 
255  /* 3DM */
256  geom = lwgeom_from_wkt("POLYHEDRALSURFACEM(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE);
257  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
258  CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE);
259  tmp = lwgeom_to_ewkt(geom);
260  CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACEM(((0 1 2,3 4 5,6 7 8,0 1 2)))", tmp);
261  lwfree(tmp);
262  tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0);
263  CU_ASSERT_STRING_EQUAL("010F00004001000000010300004001000000040000000000000000000000000000000000F03F000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001C4000000000000020400000000000000000000000000000F03F0000000000000040", tmp);
264  lwfree(tmp);
265  lwgeom_free(geom);
266 
267  /* ERROR: a missing Z values */
268  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7,0 1 2)))", LW_PARSER_CHECK_NONE);
269  CU_ASSERT_STRING_EQUAL("can not mix dimensionality in a geometry", cu_error_msg);
271  lwgeom_free(geom);
272 
273  /* 1 face with 1 interior ring */
274  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 2),(9 10 11,12 13 14,15 16 17,9 10 11)))", LW_PARSER_CHECK_NONE);
275  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
276  CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE);
277  tmp = lwgeom_to_ewkt(geom);
278  CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 2),(9 10 11,12 13 14,15 16 17,9 10 11)))", tmp);
279  lwfree(tmp);
280  tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0);
281  CU_ASSERT_STRING_EQUAL("010F00008001000000010300008002000000040000000000000000000000000000000000F03F000000000000004000000000000008400000000000001040000000000000144000000000000018400000000000001C4000000000000020400000000000000000000000000000F03F00000000000000400400000000000000000022400000000000002440000000000000264000000000000028400000000000002A400000000000002C400000000000002E4000000000000030400000000000003140000000000000224000000000000024400000000000002640", tmp);
282  lwfree(tmp);
283  lwgeom_free(geom);
284 
285  /* ERROR: non closed rings */
286  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 0 2)))", LW_PARSER_CHECK_ALL);
287  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
289  lwgeom_free(geom);
290 
291  /* ERROR: non closed face in Z dim */
292  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 3)))", LW_PARSER_CHECK_ALL);
293  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
295  lwgeom_free(geom);
296 
297  /* ERROR: non closed face in Z dim, with a 4D geom */
298  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2 3,4 5 6 7,8 9 10 11,0 1 3 3)))", LW_PARSER_CHECK_ALL);
299  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
301  lwgeom_free(geom);
302 
303  /* ERROR: only 3 points in a face */
304  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,0 1 2)))", LW_PARSER_CHECK_ALL);
305  CU_ASSERT_STRING_EQUAL("geometry requires more points", cu_error_msg);
307  lwgeom_free(geom);
308 
309  /* EMPTY face */
310  geom = lwgeom_from_wkt("POLYHEDRALSURFACE EMPTY", LW_PARSER_CHECK_NONE);
311  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
312  CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE);
313  tmp = (char *)lwgeom_to_wkb(geom, WKB_HEX | WKB_ISO | WKB_NDR, 0);
314  CU_ASSERT_STRING_EQUAL("010F00000000000000", tmp);
315  lwfree(tmp);
316  tmp = lwgeom_to_ewkt(geom);
317  CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE EMPTY", tmp);
318  lwfree(tmp);
319  lwgeom_free(geom);
320 
321  /* A simple tetrahedron */
322  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", LW_PARSER_CHECK_NONE);
323  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
324  CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE);
325  CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN);
326  tmp = lwgeom_to_ewkt(geom);
327  CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", tmp);
328  lwfree(tmp);
329  tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0);
330  CU_ASSERT_STRING_EQUAL("010F000080040000000103000080010000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000010300008001000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000000001030000800100000004000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000001030000800100000004000000000000000000F03F000000000000000000000000000000000000000000000000000000000000F03F000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000", tmp);
331  lwfree(tmp);
332  lwgeom_free(geom);
333 
334  /* A 4D tetrahedron */
335  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))", LW_PARSER_CHECK_NONE);
336  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
337  CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE);
338  CU_ASSERT_EQUAL(FLAGS_GET_M(geom->flags), 1);
339  CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN);
340  tmp = lwgeom_to_ewkt(geom);
341  CU_ASSERT_STRING_EQUAL("POLYHEDRALSURFACE(((0 0 0 0,0 0 1 0,0 1 0 2,0 0 0 0)),((0 0 0 0,0 1 0 0,1 0 0 4,0 0 0 0)),((0 0 0 0,1 0 0 0,0 0 1 6,0 0 0 0)),((1 0 0 0,0 1 0 0,0 0 1 0,1 0 0 0)))", tmp);
342  lwfree(tmp);
343  tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0);
344  CU_ASSERT_STRING_EQUAL("010F0000C00400000001030000C00100000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000001030000C0010000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000000000000000000000000000000000001040000000000000000000000000000000000000000000000000000000000000000001030000C001000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000001840000000000000000000000000000000000000000000000000000000000000000001030000C00100000004000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000000000000000000000000000000000000000", tmp);
345  lwfree(tmp);
346  lwgeom_free(geom);
347 
348 
349  /* explicit SRID */
350  geom = lwgeom_from_wkt("SRID=4326;POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", LW_PARSER_CHECK_NONE);
351  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
352  CU_ASSERT_EQUAL(geom->type, POLYHEDRALSURFACETYPE);
353  CU_ASSERT_EQUAL(geom->srid, 4326);
354  tmp = lwgeom_to_ewkt(geom);
355  CU_ASSERT_STRING_EQUAL("SRID=4326;POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", tmp);
356  lwfree(tmp);
357  tmp = lwgeom_to_hexwkb(geom, WKB_NDR | WKB_EXTENDED, 0);
358  CU_ASSERT_STRING_EQUAL("010F0000A0E6100000040000000103000080010000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000010300008001000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000000001030000800100000004000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000001030000800100000004000000000000000000F03F000000000000000000000000000000000000000000000000000000000000F03F000000000000000000000000000000000000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000", tmp);
359  lwfree(tmp);
360  lwgeom_free(geom);
361 
362 
363  /* geography support */
364  geom = lwgeom_from_wkt("POLYHEDRALSURFACE(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE);
365  g = gserialized_from_lwgeom(geom, 0);
366  CU_ASSERT_EQUAL(gserialized_get_type(g), POLYHEDRALSURFACETYPE);
367  lwgeom_free(geom);
368  lwfree(g);
369 }
370 
371 
372 static void
373 check_dimension(char *ewkt, int dim)
374 {
375  LWGEOM *geom;
376 
378  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
379  CU_ASSERT_EQUAL(lwgeom_dimensionality(geom), dim);
380  lwgeom_free(geom);
381 }
382 
383 void
385 {
386  /* 2D */
387  check_dimension("POLYHEDRALSURFACE(((0 0,0 1,1 1,0 0)))", 2);
388  check_dimension("TIN(((0 0,0 1,1 1,0 0)))", 2);
389 
390  /* 3D single face */
391  check_dimension("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)))", 2);
392  check_dimension("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)))", 2);
393 
394  /* Tetrahedron */
395  check_dimension("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", 3);
396  check_dimension("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", 3);
397 }
398 
399 
400 /*
401 ** Used by test harness to register the tests in this file.
402 */
403 void surface_suite_setup(void);
405 {
406  CU_pSuite suite = CU_add_suite("surface", NULL, NULL);
407  PG_ADD_TEST(suite, triangle_parse);
408  PG_ADD_TEST(suite, tin_parse);
411 }
void surface_dimension(void)
Definition: cu_surface.c:384
void triangle_parse(void)
Definition: cu_surface.c:14
static void check_dimension(char *ewkt, int dim)
Definition: cu_surface.c:373
void tin_parse(void)
Definition: cu_surface.c:109
void polyhedralsurface_parse(void)
Definition: cu_surface.c:235
void surface_suite_setup(void)
Definition: cu_surface.c:404
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: g_serialized.c:86
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
#define PG_ADD_TEST(suite, testfunc)
#define LW_PARSER_CHECK_ALL
Definition: liblwgeom.h:2006
#define WKB_ISO
Definition: liblwgeom.h:2066
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
uint8_t * lwgeom_to_wkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Convert LWGEOM to a char* in WKB format.
Definition: lwout_wkb.c:764
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:556
#define WKB_HEX
Definition: liblwgeom.h:2071
#define TINTYPE
Definition: liblwgeom.h:99
void lwfree(void *mem)
Definition: lwutil.c:244
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
#define WKB_EXTENDED
Definition: liblwgeom.h:2068
char * lwgeom_to_hexwkb(const LWGEOM *geom, uint8_t variant, size_t *size_out)
Definition: lwout_wkb.c:848
#define WKB_NDR
Definition: liblwgeom.h:2069
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:676
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define TRIANGLETYPE
Definition: liblwgeom.h:98
int lwgeom_dimensionality(const LWGEOM *geom)
Return the dimensionality (relating to point/line/poly) of an lwgeom.
Definition: lwgeom.c:1458
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
uint8_t type
Definition: liblwgeom.h:399
uint8_t flags
Definition: liblwgeom.h:400
int32_t srid
Definition: liblwgeom.h:402