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

Definition at line 15 of file cu_surface.c.

References cu_error_msg, cu_error_msg_reset(), gserialized_from_lwgeom(), gserialized_get_type(), LW_PARSER_CHECK_NONE, lwfree(), lwgeom_free(), lwgeom_from_wkt(), lwgeom_to_ewkt(), lwgeom_to_wkt(), LWGEOM::srid, TRIANGLETYPE, and LWGEOM::type.

Referenced by surface_suite_setup().

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 }
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_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
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:425
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
#define TRIANGLETYPE
Definition: liblwgeom.h:73
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
void cu_error_msg_reset()
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, int is_geodetic, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
Definition: g_serialized.c:908
uint8_t type
Definition: liblwgeom.h:352
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]

Here is the call graph for this function:

Here is the caller graph for this function: