PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_lwgeom_from_gserialized ( void  )
static

Definition at line 245 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().

246 {
247  LWGEOM *geom;
248  GSERIALIZED *g;
249  char *in_ewkt;
250  char *out_ewkt;
251  int i = 0;
252 
253  char ewkt[][512] =
254  {
255  "POINT EMPTY",
256  "POINT(0 0.2)",
257  "LINESTRING EMPTY",
258  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
259  "MULTIPOINT EMPTY",
260  "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)",
261  "SRID=1;MULTILINESTRING EMPTY",
262  "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))",
263  "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))",
264  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
265  "POLYGON EMPTY",
266  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
267  "SRID=4326;POLYGON EMPTY",
268  "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))",
269  "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))",
270  "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)))",
271  "SRID=4326;MULTIPOLYGON EMPTY",
272  "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))))",
273  "SRID=4326;GEOMETRYCOLLECTION EMPTY",
274  "SRID=4326;GEOMETRYCOLLECTION(POINT EMPTY, MULTIPOLYGON EMPTY)",
275  "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))",
276  "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)))",
277  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING EMPTY))",
278  };
279 
280  for ( i = 0; i < 13; i++ )
281  {
282  LWGEOM* geom2;
283 
284  in_ewkt = ewkt[i];
285  geom = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
286  lwgeom_add_bbox(geom);
287  if ( geom->bbox ) gbox_float_round(geom->bbox);
288  g = gserialized_from_lwgeom(geom, 0, 0);
289 
290  geom2 = lwgeom_from_gserialized(g);
291  out_ewkt = lwgeom_to_ewkt(geom2);
292 
293  /* printf("\n in = %s\nout = %s\n", in_ewkt, out_ewkt); */
294  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
295 
296  /* either both or none of the bboxes are null */
297  CU_ASSERT( (geom->bbox != NULL) || (geom2->bbox == NULL) );
298 
299  /* either both are null or they are the same */
300  CU_ASSERT(geom->bbox == NULL || gbox_same(geom->bbox, geom2->bbox));
301 
302  lwgeom_free(geom);
303  lwgeom_free(geom2);
304  lwfree(g);
305  lwfree(out_ewkt);
306  }
307 
308 }
GBOX * bbox
Definition: liblwgeom.h:354
void lwfree(void *mem)
Definition: lwutil.c:190
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:425
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:641
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, int is_geodetic, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
Definition: g_serialized.c:908
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:555
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:139

Here is the call graph for this function:

Here is the caller graph for this function: