PostGIS  2.1.10dev-r@@SVN_REVISION@@
void polyhedralsurface_parse ( void  )

Definition at line 236 of file cu_surface.c.

References cu_error_msg, cu_error_msg_reset(), LWGEOM::flags, FLAGS_GET_M, gserialized_from_lwgeom(), gserialized_get_type(), LW_PARSER_CHECK_ALL, LW_PARSER_CHECK_NONE, lwfree(), lwgeom_free(), lwgeom_from_wkt(), lwgeom_to_ewkt(), lwgeom_to_hexwkb(), lwgeom_to_wkb(), POLYHEDRALSURFACETYPE, LWGEOM::srid, SRID_UNKNOWN, LWGEOM::type, WKB_EXTENDED, WKB_HEX, WKB_ISO, and WKB_NDR.

Referenced by surface_suite_setup().

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 }
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
void lwfree(void *mem)
Definition: lwutil.c:190
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
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:72
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
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()
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
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
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
uint8_t type
Definition: liblwgeom.h:352
#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

Here is the call graph for this function:

Here is the caller graph for this function: