PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ polyhedralsurface_parse()

void polyhedralsurface_parse ( void  )

Definition at line 235 of file cu_surface.c.

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 }
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 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
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
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#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

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().

Here is the call graph for this function:
Here is the caller graph for this function: