PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_lwgeom_from_gserialized()

static void test_lwgeom_from_gserialized ( void  )
static

Definition at line 254 of file cu_libgeom.c.

255 {
256  LWGEOM *geom;
257  GSERIALIZED *g;
258  char *in_ewkt;
259  char *out_ewkt;
260  size_t i = 0;
261 
262  char *ewkt[] =
263  {
264  "POINT EMPTY",
265  "POINT(0 0.2)",
266  "LINESTRING EMPTY",
267  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
268  "MULTIPOINT EMPTY",
269  "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)",
270  "SRID=1;MULTILINESTRING EMPTY",
271  "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
272  "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))",
273  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
274  "POLYGON EMPTY",
275  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
276  "SRID=4326;POLYGON EMPTY",
277  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))",
278  "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))",
279  "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))",
280  "SRID=4326;MULTIPOLYGON EMPTY",
281  "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))",
282  "SRID=4326;GEOMETRYCOLLECTION EMPTY",
283  "SRID=4326;GEOMETRYCOLLECTION(POINT EMPTY,MULTIPOLYGON EMPTY)",
284  "MULTICURVE((5 5 1 3,3 5 2 2,3 3 3 1,0 3 1 1),CIRCULARSTRING(0 0 0 0,0.26794 1 3 -2,0.5857864 1.414213 1 2))",
285  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0)),((7 8,10 10,6 14,4 11,7 8)))",
286  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING EMPTY))",
287  };
288 
289  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
290  {
291  LWGEOM* geom2;
292 
293  in_ewkt = ewkt[i];
294  geom = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
295  lwgeom_add_bbox(geom);
296  if ( geom->bbox ) gbox_float_round(geom->bbox);
297  g = gserialized_from_lwgeom(geom, 0);
298 
299  geom2 = lwgeom_from_gserialized(g);
300  out_ewkt = lwgeom_to_ewkt(geom2);
301 
302  /* printf("\n in = %s\nout = %s\n", in_ewkt, out_ewkt); */
303  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
304 
305  /* either both or none of the bboxes are null */
306  CU_ASSERT( (geom->bbox != NULL) || (geom2->bbox == NULL) );
307 
308  /* either both are null or they are the same */
309  CU_ASSERT(geom->bbox == NULL || gbox_same(geom->bbox, geom2->bbox));
310 
311  lwgeom_free(geom);
312  lwgeom_free(geom2);
313  lwfree(g);
314  lwfree(out_ewkt);
315  }
316 
317 }
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:171
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:712
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
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
void lwfree(void *mem)
Definition: lwutil.c:244
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:686
GBOX * bbox
Definition: liblwgeom.h:401

References LWGEOM::bbox, gbox_float_round(), gbox_same(), gserialized_from_lwgeom(), LW_PARSER_CHECK_NONE, lwfree(), lwgeom_add_bbox(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_from_wkt(), and lwgeom_to_ewkt().

Referenced by libgeom_suite_setup().

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