PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ tin_parse()

void tin_parse ( void  )

Definition at line 109 of file cu_surface.c.

110 {
111  LWGEOM *geom;
112  GSERIALIZED *g;
113  char *tmp;
114 
115  cu_error_msg_reset(); /* Because i don't trust that much prior tests... ;) */
116 
117  /* empty */
118  geom = lwgeom_from_wkt("TIN EMPTY", LW_PARSER_CHECK_NONE);
119  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
120  CU_ASSERT_EQUAL(geom->type, TINTYPE);
121  tmp = lwgeom_to_ewkt(geom);
122  CU_ASSERT_STRING_EQUAL("TIN EMPTY", tmp);
123  lwfree(tmp);
124  lwgeom_free(geom);
125 
126  /* 2 dims */
127  geom = lwgeom_from_wkt("TIN(((0 1,2 3,4 5,0 1)))", LW_PARSER_CHECK_NONE);
128  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
129  CU_ASSERT_EQUAL(geom->type, TINTYPE);
130  tmp = lwgeom_to_ewkt(geom);
131  CU_ASSERT_STRING_EQUAL("TIN(((0 1,2 3,4 5,0 1)))", tmp);
132  lwfree(tmp);
133  lwgeom_free(geom);
134 
135  /* 3DM */
136  geom = lwgeom_from_wkt("TINM(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE);
137  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
138  CU_ASSERT_EQUAL(geom->type, TINTYPE);
139  tmp = lwgeom_to_ewkt(geom);
140  CU_ASSERT_STRING_EQUAL("TINM(((0 1 2,3 4 5,6 7 8,0 1 2)))", tmp);
141  lwfree(tmp);
142  lwgeom_free(geom);
143 
144  /* ERROR: a missing Z values */
145  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7,0 1 2)))", LW_PARSER_CHECK_NONE);
146  CU_ASSERT_STRING_EQUAL("can not mix dimensionality in a geometry", cu_error_msg);
148  lwgeom_free(geom);
149 
150  /* ERROR: non closed rings */
151  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 0 2)))", LW_PARSER_CHECK_NONE);
152  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
154  lwgeom_free(geom);
155 
156  /* ERROR: non closed face in Z dim */
157  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 1 3)))", LW_PARSER_CHECK_NONE);
158  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
160  lwgeom_free(geom);
161 
162  /* ERROR: non closed face in Z dim, with a 4D geom */
163  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);
164  CU_ASSERT_STRING_EQUAL("geometry contains non-closed rings", cu_error_msg);
166  lwgeom_free(geom);
167 
168  /* ERROR: only 3 points in a face */
169  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,0 1 2)))", LW_PARSER_CHECK_NONE);
170  CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg);
172  lwgeom_free(geom);
173 
174  /* ERROR: more than 3 points in a face */
175  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,9 10 11,0 1 2)))", LW_PARSER_CHECK_NONE);
176  CU_ASSERT_STRING_EQUAL("triangle must have exactly 4 points", cu_error_msg);
178  lwgeom_free(geom);
179 
180  /* ERROR: use ring for triangle */
181  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);
182  CU_ASSERT_STRING_EQUAL("parse error - invalid geometry", cu_error_msg);
184  lwgeom_free(geom);
185 
186  /* EMPTY face */
187  geom = lwgeom_from_wkt("TIN EMPTY", LW_PARSER_CHECK_NONE);
188  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
189  CU_ASSERT_EQUAL(geom->type, TINTYPE);
190  tmp = lwgeom_to_ewkt(geom);
191  CU_ASSERT_STRING_EQUAL("TIN EMPTY", tmp);
192  lwfree(tmp);
193  lwgeom_free(geom);
194 
195  /* A simple tetrahedron */
196  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);
197  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
198  CU_ASSERT_EQUAL(geom->type, TINTYPE);
199  CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN);
200  tmp = lwgeom_to_ewkt(geom);
201  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);
202  lwfree(tmp);
203  lwgeom_free(geom);
204 
205  /* A 4D tetrahedron */
206  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);
207  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
208  CU_ASSERT_EQUAL(geom->type, TINTYPE);
209  CU_ASSERT_EQUAL(FLAGS_GET_M(geom->flags), 1);
210  CU_ASSERT_EQUAL(geom->srid, SRID_UNKNOWN);
211  tmp = lwgeom_to_ewkt(geom);
212  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);
213  lwfree(tmp);
214  lwgeom_free(geom);
215 
216  /* explicit SRID */
217  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);
218  CU_ASSERT_EQUAL(strlen(cu_error_msg), 0);
219  CU_ASSERT_EQUAL(geom->type, TINTYPE);
220  CU_ASSERT_EQUAL(geom->srid, 4326);
221  tmp = lwgeom_to_ewkt(geom);
222  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);
223  lwfree(tmp);
224  lwgeom_free(geom);
225 
226  /* geography support */
227  geom = lwgeom_from_wkt("TIN(((0 1 2,3 4 5,6 7 8,0 1 2)))", LW_PARSER_CHECK_NONE);
228  g = gserialized_from_lwgeom(geom, 0);
229  CU_ASSERT_EQUAL(gserialized_get_type(g), TINTYPE);
230  lwgeom_free(geom);
231  lwfree(g);
232 }
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]
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:556
#define TINTYPE
Definition: liblwgeom.h:99
void lwfree(void *mem)
Definition: lwutil.c:244
#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_NONE, lwfree(), lwgeom_free(), lwgeom_from_wkt(), lwgeom_to_ewkt(), LWGEOM::srid, SRID_UNKNOWN, TINTYPE, and LWGEOM::type.

Referenced by surface_suite_setup().

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