PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ test_lwgeom_from_gserialized()

static void test_lwgeom_from_gserialized ( void  )
static

Definition at line 253 of file cu_libgeom.c.

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

254 {
255  LWGEOM *geom;
256  GSERIALIZED *g;
257  char *in_ewkt;
258  char *out_ewkt;
259  int i = 0;
260 
261  char *ewkt[] =
262  {
263  "POINT EMPTY",
264  "POINT(0 0.2)",
265  "LINESTRING EMPTY",
266  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
267  "MULTIPOINT EMPTY",
268  "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)",
269  "SRID=1;MULTILINESTRING EMPTY",
270  "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))",
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  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
273  "POLYGON EMPTY",
274  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
275  "SRID=4326;POLYGON EMPTY",
276  "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))",
277  "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))",
278  "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)))",
279  "SRID=4326;MULTIPOLYGON EMPTY",
280  "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))))",
281  "SRID=4326;GEOMETRYCOLLECTION EMPTY",
282  "SRID=4326;GEOMETRYCOLLECTION(POINT EMPTY,MULTIPOLYGON EMPTY)",
283  "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))",
284  "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)))",
285  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING EMPTY))",
286  };
287 
288  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
289  {
290  LWGEOM* geom2;
291 
292  in_ewkt = ewkt[i];
293  geom = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
294  lwgeom_add_bbox(geom);
295  if ( geom->bbox ) gbox_float_round(geom->bbox);
296  g = gserialized_from_lwgeom(geom, 0, 0);
297 
298  geom2 = lwgeom_from_gserialized(g);
299  out_ewkt = lwgeom_to_ewkt(geom2);
300 
301  /* printf("\n in = %s\nout = %s\n", in_ewkt, out_ewkt); */
302  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
303 
304  /* either both or none of the bboxes are null */
305  CU_ASSERT( (geom->bbox != NULL) || (geom2->bbox == NULL) );
306 
307  /* either both are null or they are the same */
308  CU_ASSERT(geom->bbox == NULL || gbox_same(geom->bbox, geom2->bbox));
309 
310  lwgeom_free(geom);
311  lwgeom_free(geom2);
312  lwfree(g);
313  lwfree(out_ewkt);
314  }
315 
316 }
GBOX * bbox
Definition: liblwgeom.h:382
void lwfree(void *mem)
Definition: lwutil.c:214
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:469
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:890
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1869
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:682
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, int is_geodetic, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
Definition: g_serialized.c:906
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:141
Here is the call graph for this function:
Here is the caller graph for this function: