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

Definition at line 110 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_NONE, lwfree(), lwgeom_free(), lwgeom_from_wkt(), lwgeom_to_ewkt(), LWGEOM::srid, SRID_UNKNOWN, TINTYPE, and LWGEOM::type.

Referenced by surface_suite_setup().

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 }
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
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
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()
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
#define TINTYPE
Definition: liblwgeom.h:74
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 FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
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: