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