PostGIS  2.4.9dev-r@@SVN_REVISION@@
cu_libgeom.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  * Copyright 2009 Paul Ramsey <pramsey@cleverelephant.ca>
6  *
7  * This is free software; you can redistribute and/or modify it under
8  * the terms of the GNU General Public Licence. See the COPYING file.
9  *
10  **********************************************************************/
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include "CUnit/Basic.h"
16 
17 #include "liblwgeom_internal.h"
18 #include "g_serialized.c" /* for gserialized_peek_gbox_p */
19 #include "cu_tester.h"
20 
21 static void test_typmod_macros(void)
22 {
23  int32_t typmod = 0;
24  int srid = 4326;
25  int type = 6;
26  int z = 1;
27  int rv;
28 
29  TYPMOD_SET_SRID(typmod,srid);
30  rv = TYPMOD_GET_SRID(typmod);
31  CU_ASSERT_EQUAL(rv, srid);
32 
33  srid = -5005;
34  TYPMOD_SET_SRID(typmod,srid);
35  rv = TYPMOD_GET_SRID(typmod);
36  CU_ASSERT_EQUAL(rv, srid);
37 
38  srid = 999999;
39  TYPMOD_SET_SRID(typmod,srid);
40  rv = TYPMOD_GET_SRID(typmod);
41  CU_ASSERT_EQUAL(rv, srid);
42 
43  srid = -999999;
44  TYPMOD_SET_SRID(typmod,srid);
45  rv = TYPMOD_GET_SRID(typmod);
46  CU_ASSERT_EQUAL(rv, srid);
47 
48  srid = SRID_UNKNOWN;
49  TYPMOD_SET_SRID(typmod,srid);
50  rv = TYPMOD_GET_SRID(typmod);
51  CU_ASSERT_EQUAL(rv, srid);
52 
53  srid = 0;
54  TYPMOD_SET_SRID(typmod,srid);
55  rv = TYPMOD_GET_SRID(typmod);
56  CU_ASSERT_EQUAL(rv, srid);
57 
58  srid = 1;
59  TYPMOD_SET_SRID(typmod,srid);
60  rv = TYPMOD_GET_SRID(typmod);
61  CU_ASSERT_EQUAL(rv, srid);
62 
63  TYPMOD_SET_TYPE(typmod,type);
64  rv = TYPMOD_GET_TYPE(typmod);
65  CU_ASSERT_EQUAL(rv,type);
66 
67  TYPMOD_SET_Z(typmod);
68  rv = TYPMOD_GET_Z(typmod);
69  CU_ASSERT_EQUAL(rv,z);
70 
71  rv = TYPMOD_GET_M(typmod);
72  CU_ASSERT_EQUAL(rv,0);
73 
74 }
75 
76 static void test_flags_macros(void)
77 {
78  uint8_t flags = 0;
79 
80  CU_ASSERT_EQUAL(0, FLAGS_GET_Z(flags));
81  FLAGS_SET_Z(flags, 1);
82  CU_ASSERT_EQUAL(1, FLAGS_GET_Z(flags));
83  FLAGS_SET_Z(flags, 0);
84  CU_ASSERT_EQUAL(0, FLAGS_GET_Z(flags));
85  CU_ASSERT_EQUAL(0, FLAGS_GET_BBOX(flags));
86 
87  CU_ASSERT_EQUAL(0, FLAGS_GET_M(flags));
88  FLAGS_SET_M(flags, 1);
89  CU_ASSERT_EQUAL(1, FLAGS_GET_M(flags));
90 
91  CU_ASSERT_EQUAL(0, FLAGS_GET_BBOX(flags));
92  FLAGS_SET_BBOX(flags, 1);
93  CU_ASSERT_EQUAL(1, FLAGS_GET_BBOX(flags));
94  CU_ASSERT_EQUAL(0, FLAGS_GET_READONLY(flags));
95 
96  FLAGS_SET_READONLY(flags, 1);
97  CU_ASSERT_EQUAL(1, FLAGS_GET_READONLY(flags));
98  FLAGS_SET_READONLY(flags, 0);
99  CU_ASSERT_EQUAL(0, FLAGS_GET_READONLY(flags));
100 
101  CU_ASSERT_EQUAL(0, FLAGS_GET_GEODETIC(flags));
102  FLAGS_SET_GEODETIC(flags, 1);
103  CU_ASSERT_EQUAL(1, FLAGS_GET_GEODETIC(flags));
104 
105  flags = gflags(1, 0, 1); /* z=1, m=0, geodetic=1 */
106 
107  CU_ASSERT_EQUAL(1, FLAGS_GET_GEODETIC(flags));
108  CU_ASSERT_EQUAL(1, FLAGS_GET_Z(flags));
109  CU_ASSERT_EQUAL(0, FLAGS_GET_M(flags));
110  CU_ASSERT_EQUAL(2, FLAGS_GET_ZM(flags));
111 
112  flags = gflags(1, 1, 1); /* z=1, m=1, geodetic=1 */
113 
114  CU_ASSERT_EQUAL(1, FLAGS_GET_GEODETIC(flags));
115  CU_ASSERT_EQUAL(1, FLAGS_GET_Z(flags));
116  CU_ASSERT_EQUAL(1, FLAGS_GET_M(flags));
117  CU_ASSERT_EQUAL(3, FLAGS_GET_ZM(flags));
118 
119  flags = gflags(0, 1, 0); /* z=0, m=1, geodetic=0 */
120 
121  CU_ASSERT_EQUAL(0, FLAGS_GET_GEODETIC(flags));
122  CU_ASSERT_EQUAL(0, FLAGS_GET_Z(flags));
123  CU_ASSERT_EQUAL(1, FLAGS_GET_M(flags));
124  CU_ASSERT_EQUAL(1, FLAGS_GET_ZM(flags));
125 }
126 
127 static void test_serialized_srid(void)
128 {
129  GSERIALIZED s;
130  int32_t srid, rv;
131 
132  srid = 4326;
133  gserialized_set_srid(&s, srid);
134  rv = gserialized_get_srid(&s);
135  CU_ASSERT_EQUAL(rv, srid);
136 
137  srid = -3005;
138  gserialized_set_srid(&s, srid);
139  rv = gserialized_get_srid(&s);
140  //printf("srid=%d rv=%d\n",srid,rv);
141  CU_ASSERT_EQUAL(rv, SRID_UNKNOWN);
142 
143  srid = SRID_UNKNOWN;
144  gserialized_set_srid(&s, srid);
145  rv = gserialized_get_srid(&s);
146  CU_ASSERT_EQUAL(rv, srid);
147 
148  srid = SRID_UNKNOWN;
149  gserialized_set_srid(&s, srid);
150  rv = gserialized_get_srid(&s);
151  CU_ASSERT_EQUAL(rv, srid);
152 
153  srid = 100000;
154  gserialized_set_srid(&s, srid);
155  rv = gserialized_get_srid(&s);
156  CU_ASSERT_EQUAL(rv, srid);
157 }
158 
160 {
161  LWGEOM *g;
162  size_t size = 0;
163 
164  g = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
166  CU_ASSERT_EQUAL( size, 32 );
167  lwgeom_free(g);
168 
169  g = lwgeom_from_wkt("POINT(0 0 0)", LW_PARSER_CHECK_NONE);
171  CU_ASSERT_EQUAL( size, 40 );
172  lwgeom_free(g);
173 
174  g = lwgeom_from_wkt("MULTIPOINT(0 0 0, 1 1 1)", LW_PARSER_CHECK_NONE);
176  CU_ASSERT_EQUAL( size, 80 );
177  lwgeom_free(g);
178 
179  g = lwgeom_from_wkt("LINESTRING(0 0, 1 1)", LW_PARSER_CHECK_NONE);
181  CU_ASSERT_EQUAL( size, 48 );
182  lwgeom_free(g);
183 
184  g = lwgeom_from_wkt("MULTILINESTRING((0 0, 1 1),(0 0, 1 1))", LW_PARSER_CHECK_NONE);
186  CU_ASSERT_EQUAL( size, 96 );
187  lwgeom_free(g);
188 
189  g = lwgeom_from_wkt("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
191  CU_ASSERT_EQUAL( size, 104 );
192  lwgeom_free(g);
193 
194  g = lwgeom_from_wkt("POLYGON((-1 -1, -1 2, 2 2, 2 -1, -1 -1), (0 0, 0 1, 1 1, 1 0, 0 0))", LW_PARSER_CHECK_NONE);
196  CU_ASSERT_EQUAL( size, 184 );
197  lwgeom_free(g);
198 
199 }
200 
201 static void test_lwgeom_calculate_gbox(void)
202 {
203  LWGEOM *g;
204  GBOX b;
205 
206  g = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
208  CU_ASSERT_DOUBLE_EQUAL(b.xmin, 0.0, 0.0000001);
209  lwgeom_free(g);
210 
211  /* Inf = 0x7FF0000000000000 */
212  /* POINT(0 0) = 00 00000001 0000000000000000 0000000000000000 */
213  /* POINT(0 Inf) = 00 00000001 0000000000000000 7FF0000000000000 */
214  g = lwgeom_from_hexwkb("000000000100000000000000007FF0000000000000", LW_PARSER_CHECK_NONE);
216  CU_ASSERT_DOUBLE_EQUAL(b.xmin, 0.0, 0.0000001);
217  CU_ASSERT(isinf(b.ymax));
218  lwgeom_free(g);
219 
220  /* LINESTRING(0 0, 0 Inf) = 00 00000002 00000002 0000000000000000 7FF0000000000000 0000000000000000 0000000000000000 */
221  /* Inf should show up in bbox */
222  g = lwgeom_from_hexwkb("00000000020000000200000000000000007FF000000000000000000000000000000000000000000000", LW_PARSER_CHECK_NONE);
224  CU_ASSERT_DOUBLE_EQUAL(b.xmin, 0.0, 0.0000001);
225  CU_ASSERT(isinf(b.ymax));
226  lwgeom_free(g);
227 
228  /* Geometry with NaN 0101000020E8640000000000000000F8FF000000000000F8FF */
229  /* NaN should show up in bbox for "SRID=4326;POINT(0 NaN)" */
230  g = lwgeom_from_hexwkb("0101000020E86400000000000000000000000000000000F8FF", LW_PARSER_CHECK_NONE);
232  CU_ASSERT(isnan(b.ymax));
233  lwgeom_free(g);
234 
235 }
236 
237 static void test_gbox_serialized_size(void)
238 {
239  uint8_t flags = gflags(0, 0, 0);
240  CU_ASSERT_EQUAL(gbox_serialized_size(flags),16);
241  FLAGS_SET_BBOX(flags, 1);
242  CU_ASSERT_EQUAL(gbox_serialized_size(flags),16);
243  FLAGS_SET_Z(flags, 1);
244  CU_ASSERT_EQUAL(gbox_serialized_size(flags),24);
245  FLAGS_SET_M(flags, 1);
246  CU_ASSERT_EQUAL(gbox_serialized_size(flags),32);
247  FLAGS_SET_GEODETIC(flags, 1);
248  CU_ASSERT_EQUAL(gbox_serialized_size(flags),24);
249 
250 }
251 
252 
253 
255 {
256  LWGEOM *geom;
257  GSERIALIZED *g;
258  char *in_ewkt;
259  char *out_ewkt;
260  int 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 }
318 
319 
320 static void test_gserialized_is_empty(void)
321 {
322  int i = 0;
323  struct gserialized_empty_cases {
324  const char* wkt;
325  int isempty;
326  };
327 
328  struct gserialized_empty_cases cases[] = {
329  { "POINT EMPTY", 1 },
330  { "POINT(1 1)", 0 },
331  { "LINESTRING EMPTY", 1 },
332  { "MULTILINESTRING EMPTY", 1 },
333  { "MULTILINESTRING(EMPTY)", 1 },
334  { "MULTILINESTRING(EMPTY,EMPTY)", 1 },
335  { "MULTILINESTRING(EMPTY,(0 0,1 1))", 0 },
336  { "MULTILINESTRING((0 0,1 1),EMPTY)", 0 },
337  { "MULTILINESTRING(EMPTY,(0 0,1 1),EMPTY)", 0 },
338  { "MULTILINESTRING(EMPTY,EMPTY,EMPTY)", 1 },
339  { "GEOMETRYCOLLECTION(POINT EMPTY,MULTILINESTRING(EMPTY,EMPTY,EMPTY))", 1 },
340  { "GEOMETRYCOLLECTION(POINT EMPTY,MULTILINESTRING(EMPTY),POINT(1 1))", 0 },
341  { "GEOMETRYCOLLECTION(POINT EMPTY,MULTILINESTRING(EMPTY, (0 0)),POINT EMPTY)", 0 },
342  { "GEOMETRYCOLLECTION(POLYGON EMPTY,POINT EMPTY,MULTILINESTRING(EMPTY,EMPTY),POINT EMPTY)", 1 },
343  { "GEOMETRYCOLLECTION(POLYGON EMPTY,GEOMETRYCOLLECTION(POINT EMPTY),MULTILINESTRING(EMPTY,EMPTY),POINT EMPTY)", 1 },
344  { NULL, 0 }
345  };
346 
347  while( cases[i].wkt )
348  {
349  // i = 11;
350  LWGEOM *lw = lwgeom_from_wkt(cases[i].wkt, LW_PARSER_CHECK_NONE);
352  int ie = gserialized_is_empty(g);
353  // printf("%s: we say %d, they say %d\n", cases[i].wkt, cases[i].isempty, ie);
354  CU_ASSERT_EQUAL(ie, cases[i].isempty);
355  lwgeom_free(lw);
356  lwfree(g);
357  i++;
358  }
359 }
360 
361 
363 {
364  int rv;
365  uint8_t type = 0;
366  int z = 0, m = 0;
367  char *str;
368 
369  str = " POINTZ";
370  rv = geometry_type_from_string(str, &type, &z, &m);
371  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
372  CU_ASSERT_EQUAL(rv, LW_SUCCESS);
373  CU_ASSERT_EQUAL(type, POINTTYPE);
374  CU_ASSERT_EQUAL(z, 1);
375  CU_ASSERT_EQUAL(m, 0);
376 
377  str = "LINESTRINGM ";
378  rv = geometry_type_from_string(str, &type, &z, &m);
379  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
380  CU_ASSERT_EQUAL(rv, LW_SUCCESS);
381  CU_ASSERT_EQUAL(type, LINETYPE);
382  CU_ASSERT_EQUAL(z, 0);
383  CU_ASSERT_EQUAL(m, 1);
384 
385  str = "MULTIPOLYGONZM";
386  rv = geometry_type_from_string(str, &type, &z, &m);
387  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
388  CU_ASSERT_EQUAL(rv, LW_SUCCESS);
389  CU_ASSERT_EQUAL(type, MULTIPOLYGONTYPE);
390  CU_ASSERT_EQUAL(z, 1);
391  CU_ASSERT_EQUAL(m, 1);
392 
393  str = " GEOMETRYCOLLECTIONZM ";
394  rv = geometry_type_from_string(str, &type, &z, &m);
395  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
396  CU_ASSERT_EQUAL(rv, LW_SUCCESS);
397  CU_ASSERT_EQUAL(type, COLLECTIONTYPE);
398  CU_ASSERT_EQUAL(z, 1);
399  CU_ASSERT_EQUAL(m, 1);
400 
401  str = " GEOMERYCOLLECTIONZM ";
402  rv = geometry_type_from_string(str, &type, &z, &m);
403  //printf("\n in type: %s\nout type: %d\n out z: %d\n out m: %d", str, type, z, m);
404  CU_ASSERT_EQUAL(rv, LW_FAILURE);
405 
406 }
407 
408 static void test_lwgeom_count_vertices(void)
409 {
410  LWGEOM *geom;
411 
412  geom = lwgeom_from_wkt("MULTIPOINT(-1 -1,-1 2.5,2 2,2 -1)", LW_PARSER_CHECK_NONE);
413  CU_ASSERT_EQUAL(lwgeom_count_vertices(geom),4);
414  lwgeom_free(geom);
415 
416  geom = lwgeom_from_wkt("SRID=1;MULTILINESTRING((-1 -131,-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))", LW_PARSER_CHECK_NONE);
417  CU_ASSERT_EQUAL(lwgeom_count_vertices(geom),16);
418  lwgeom_free(geom);
419 
420  geom = lwgeom_from_wkt("SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,211 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)))", LW_PARSER_CHECK_NONE);
421  CU_ASSERT_EQUAL(lwgeom_count_vertices(geom),30);
422  lwgeom_free(geom);
423 
424 }
425 
427 {
428  LWGEOM *lwgeom;
429  GSERIALIZED *g_ser1;
430  size_t ret_size;
431 
432  lwgeom = lwgeom_from_wkt("MULTIPOINT(-1 -1,-1 2.5,2 2,2 -1,1 1,2 2,4 5)", LW_PARSER_CHECK_NONE);
433  CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7);
434  g_ser1 = gserialized_from_lwgeom(lwgeom, &ret_size);
435  lwgeom_free(lwgeom);
436 
437  lwgeom = lwgeom_from_gserialized(g_ser1);
438  CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7);
439  lwgeom_free(lwgeom);
440 
441  lwgeom = lwgeom_from_gserialized(g_ser1);
442 
443  CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7);
444  lwgeom_free(lwgeom);
445 
446  lwfree(g_ser1);
447 
448 }
449 
450 static void test_lwcollection_extract(void)
451 {
452 
453  LWGEOM *geom;
454  LWCOLLECTION *col;
455 
456  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION(POINT(0 0))", LW_PARSER_CHECK_NONE);
457 
458  col = lwcollection_extract((LWCOLLECTION*)geom, 1);
459  CU_ASSERT_EQUAL(col->type, MULTIPOINTTYPE);
460  lwcollection_free(col);
461 
462  col = lwcollection_extract((LWCOLLECTION*)geom, 2);
463  CU_ASSERT_EQUAL(col->type, MULTILINETYPE);
464  lwcollection_free(col);
465 
466  col = lwcollection_extract((LWCOLLECTION*)geom, 3);
467  CU_ASSERT_EQUAL(col->type, MULTIPOLYGONTYPE);
468  lwcollection_free(col);
469 
470  lwgeom_free(geom);
471 
472  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION EMPTY", LW_PARSER_CHECK_NONE);
473 
474  col = lwcollection_extract((LWCOLLECTION*)geom, 1);
475  CU_ASSERT_EQUAL(col->type, MULTIPOINTTYPE);
476  lwcollection_free(col);
477 
478  col = lwcollection_extract((LWCOLLECTION*)geom, 2);
479  CU_ASSERT_EQUAL(col->type, MULTILINETYPE);
480  lwcollection_free(col);
481 
482  col = lwcollection_extract((LWCOLLECTION*)geom, 3);
483  CU_ASSERT_EQUAL(col->type, MULTIPOLYGONTYPE);
484  lwcollection_free(col);
485 
486  lwgeom_free(geom);
487 }
488 
489 static void test_lwgeom_free(void)
490 {
491  LWGEOM *geom;
492 
493  /* Empty geometries don't seem to free properly (#370) */
494  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION EMPTY", LW_PARSER_CHECK_NONE);
495  CU_ASSERT_EQUAL(geom->type, COLLECTIONTYPE);
496  lwgeom_free(geom);
497 
498  /* Empty geometries don't seem to free properly (#370) */
499  geom = lwgeom_from_wkt("POLYGON EMPTY", LW_PARSER_CHECK_NONE);
500  CU_ASSERT_EQUAL(geom->type, POLYGONTYPE);
501  lwgeom_free(geom);
502 
503  /* Empty geometries don't seem to free properly (#370) */
504  geom = lwgeom_from_wkt("LINESTRING EMPTY", LW_PARSER_CHECK_NONE);
505  CU_ASSERT_EQUAL(geom->type, LINETYPE);
506  lwgeom_free(geom);
507 
508  /* Empty geometries don't seem to free properly (#370) */
509  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
510  CU_ASSERT_EQUAL(geom->type, POINTTYPE);
511  lwgeom_free(geom);
512 
513 }
514 
515 static void do_lwgeom_flip_coordinates(char *in, char *out)
516 {
517  LWGEOM *g;
518  char * t;
519  double xmax, ymax;
520  int testbox;
521 
523  lwgeom_add_bbox(g);
524 
525  testbox = (g->bbox != NULL);
526  if ( testbox )
527  {
528  xmax = g->bbox->xmax;
529  ymax = g->bbox->ymax;
530  }
531 
533 
534  if ( testbox )
535  {
536  CU_ASSERT_DOUBLE_EQUAL(g->bbox->xmax, ymax, 0.00001);
537  CU_ASSERT_DOUBLE_EQUAL(g->bbox->ymax, xmax, 0.00001);
538  }
539 
540  t = lwgeom_to_wkt(g, WKT_EXTENDED, 8, NULL);
541  if (t == NULL) fprintf(stderr, "In:%s", in);
542  if (strcmp(t, out))
543  fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, t, out);
544 
545  CU_ASSERT_STRING_EQUAL(t, out)
546 
547  lwgeom_free(g);
548  lwfree(t);
549 }
550 
552 {
553  /*
554  * 2D geometries types
555  */
557  "POINT(1 2)",
558  "POINT(2 1)"
559  );
560 
562  "LINESTRING(1 2,3 4)",
563  "LINESTRING(2 1,4 3)"
564  );
565 
567  "POLYGON((1 2,3 4,5 6,1 2))",
568  "POLYGON((2 1,4 3,6 5,2 1))"
569  );
570 
572  "POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8))",
573  "POLYGON((2 1,4 3,6 5,2 1),(8 7,10 9,12 11,8 7))"
574  );
575 
577  "MULTIPOINT(1 2,3 4)",
578  "MULTIPOINT(2 1,4 3)"
579  );
580 
582  "MULTILINESTRING((1 2,3 4),(5 6,7 8))",
583  "MULTILINESTRING((2 1,4 3),(6 5,8 7))"
584  );
585 
587  "MULTIPOLYGON(((1 2,3 4,5 6,7 8)),((9 10,11 12,13 14,10 9)))",
588  "MULTIPOLYGON(((2 1,4 3,6 5,8 7)),((10 9,12 11,14 13,9 10)))"
589  );
590 
592  "GEOMETRYCOLLECTION EMPTY",
593  "GEOMETRYCOLLECTION EMPTY"
594  );
595 
597  "GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(3 4,5 6))",
598  "GEOMETRYCOLLECTION(POINT(2 1),LINESTRING(4 3,6 5))"
599  );
600 
602  "GEOMETRYCOLLECTION(POINT(1 2),GEOMETRYCOLLECTION(LINESTRING(3 4,5 6)))",
603  "GEOMETRYCOLLECTION(POINT(2 1),GEOMETRYCOLLECTION(LINESTRING(4 3,6 5)))"
604  );
605 
607  "CIRCULARSTRING(-2 0,0 2,2 0,0 2,2 4)",
608  "CIRCULARSTRING(0 -2,2 0,0 2,2 0,4 2)"
609  );
610 
612  "COMPOUNDCURVE(CIRCULARSTRING(0 1,1 1,1 0),(1 0,0 1))",
613  "COMPOUNDCURVE(CIRCULARSTRING(1 0,1 1,0 1),(0 1,1 0))"
614  );
615 
617  "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))",
618  "CURVEPOLYGON(CIRCULARSTRING(0 -2,-1 -1,0 0,-1 1,0 2,2 0,0 -2),(0 -1,0.5 0,0 1,1 0,0 -1))"
619  );
620 
622  "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 3))",
623  "MULTICURVE((5 5,5 3,3 3,3 0),CIRCULARSTRING(0 0,1 2,3 2))"
624  );
625 
627  "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)))",
628  "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(0 -2,-1 -1,0 0,-1 1,0 2,2 0,0 -2),(0 -1,0.5 0,0 1,1 0,0 -1)),((8 7,10 10,14 6,11 4,8 7)))"
629  );
630 
631 
632  /*
633  * Ndims
634  */
635 
637  "POINT(1 2 3)",
638  "POINT(2 1 3)"
639  );
640 
642  "POINTM(1 2 3)",
643  "POINTM(2 1 3)"
644  );
645 
647  "POINT(1 2 3 4)",
648  "POINT(2 1 3 4)"
649  );
650 
651 
652  /*
653  * Srid
654  */
655 
657  "SRID=4326;POINT(1 2)",
658  "SRID=4326;POINT(2 1)"
659  );
660 
662  "SRID=0;POINT(1 2)",
663  "POINT(2 1)"
664  );
665 }
666 
667 static void test_f2d(void)
668 {
669  double d = 1000000.123456789123456789;
670  float f;
671  double e;
672 
673  f = next_float_down(d);
674  d = next_float_down(f);
675  CU_ASSERT_DOUBLE_EQUAL(f,d, 0.0000001);
676 
677  e = (double)f;
678  CU_ASSERT_DOUBLE_EQUAL(f,e, 0.0000001);
679 
680  f = next_float_down(d);
681  d = next_float_down(f);
682  CU_ASSERT_DOUBLE_EQUAL(f,d, 0.0000001);
683 
684  f = next_float_up(d);
685  d = next_float_up(f);
686  CU_ASSERT_DOUBLE_EQUAL(f,d, 0.0000001);
687 
688  f = next_float_up(d);
689  d = next_float_up(f);
690  CU_ASSERT_DOUBLE_EQUAL(f,d, 0.0000001);
691 
692  d = DBL_MAX;
693  f = next_float_up(d);
694  d = next_float_up(f);
695  CU_ASSERT_DOUBLE_EQUAL(f, d, 0.0000001);
696 
697  d = DBL_MAX;
698  f = next_float_down(d);
699  d = next_float_down(f);
700  CU_ASSERT_DOUBLE_EQUAL(f, d, 0.0000001);
701 
702  d = -DBL_MAX;
703  f = next_float_up(d);
704  d = next_float_up(f);
705  CU_ASSERT_DOUBLE_EQUAL(f, d, 0.0000001);
706 
707  d = -DBL_MAX;
708  f = next_float_down(d);
709  d = next_float_down(f);
710  CU_ASSERT_DOUBLE_EQUAL(f, d, 0.0000001);
711 }
712 
713 /*
714  * This is a test for memory leaks, can't really test
715  * w/out checking with a leak detector (ie: valgrind)
716  *
717  * See http://trac.osgeo.org/postgis/ticket/1102
718  */
719 static void test_lwgeom_clone(void)
720 {
721  int i;
722 
723  char *ewkt[] =
724  {
725  "POINT(0 0.2)",
726  "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)",
727  "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)",
728  "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))",
729  "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))",
730  "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
731  "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))",
732  "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))",
733  "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))",
734  "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)))",
735  "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))))",
736  "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))",
737  "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)))",
738  "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)))"
739  };
740 
741 
742  for ( i = 0; i < (sizeof ewkt/sizeof(char *)); i++ )
743  {
744  LWGEOM *geom, *cloned;
745  char *in_ewkt;
746  char *out_ewkt;
747 
748  in_ewkt = ewkt[i];
749  geom = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE);
750  cloned = lwgeom_clone(geom);
751  out_ewkt = lwgeom_to_ewkt(cloned);
752  if (strcmp(in_ewkt, out_ewkt))
753  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
754  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
755  lwfree(out_ewkt);
756  lwgeom_free(cloned);
757  lwgeom_free(geom);
758  }
759 
760 
761 }
762 
763 /*
764  * Test lwgeom_force_clockwise
765  */
767 {
768  LWGEOM *geom;
769  LWGEOM *geom2;
770  char *in_ewkt, *out_ewkt;
771 
772  /* counterclockwise, must be reversed */
773  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
774  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
776  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
777  out_ewkt = lwgeom_to_ewkt(geom);
778  if (strcmp(in_ewkt, out_ewkt))
779  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
780  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
781  lwfree(out_ewkt);
782  lwgeom_free(geom);
783 
784  /* clockwise, fine as is */
785  geom = lwgeom_from_wkt("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", LW_PARSER_CHECK_NONE);
786  CU_ASSERT_TRUE(lwgeom_is_clockwise(geom));
788  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
789  out_ewkt = lwgeom_to_ewkt(geom);
790  if (strcmp(in_ewkt, out_ewkt))
791  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
792  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
793  lwfree(out_ewkt);
794  lwgeom_free(geom);
795 
796  /* counterclockwise shell (must be reversed), mixed-wise holes */
797  geom = lwgeom_from_wkt("POLYGON((0 0,10 0,10 10,0 10,0 0),(2 2,2 4,4 2,2 2),(6 2,8 2,8 4,6 2))", LW_PARSER_CHECK_NONE);
798  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
800  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,2 4,2 2),(6 2,8 2,8 4,6 2))";
801  out_ewkt = lwgeom_to_ewkt(geom);
802  if (strcmp(in_ewkt, out_ewkt))
803  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
804  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
805  lwfree(out_ewkt);
806  lwgeom_free(geom);
807 
808  /* clockwise shell (fine), mixed-wise holes */
809  geom = lwgeom_from_wkt("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,2 4,2 2),(6 2,8 4,8 2,6 2))", LW_PARSER_CHECK_NONE);
810  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
812  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,2 4,2 2),(6 2,8 2,8 4,6 2))";
813  out_ewkt = lwgeom_to_ewkt(geom);
814  if (strcmp(in_ewkt, out_ewkt))
815  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
816  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
817  lwfree(out_ewkt);
818  lwgeom_free(geom);
819 
820  /* clockwise narrow ring, fine as-is */
821  /* NOTE: this is a narrow ring, see ticket #1302 */
822  in_ewkt = "0103000000010000000500000000917E9BA468294100917E9B8AEA2841C976BE1FA4682941C976BE9F8AEA2841B39ABE1FA46829415ACCC29F8AEA284137894120A4682941C976BE9F8AEA284100917E9BA468294100917E9B8AEA2841";
823  geom = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
824  geom2 = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
825  lwgeom_force_clockwise(geom2);
826 
829  CU_ASSERT( lwgeom_same(geom, geom2) );
830  lwgeom_free(geom);
831  lwgeom_free(geom2);
832 }
833 
834 /*
835  * Test lwgeom_is_empty
836  */
837 static void test_lwgeom_is_empty(void)
838 {
839  LWGEOM *geom;
840 
841  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
842  CU_ASSERT( !lwgeom_is_empty(geom) );
843  lwgeom_free(geom);
844 
845  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
846  CU_ASSERT( lwgeom_is_empty(geom) );
847  lwgeom_free(geom);
848 
849  geom = lwgeom_from_wkt("LINESTRING EMPTY", LW_PARSER_CHECK_NONE);
850  CU_ASSERT( lwgeom_is_empty(geom) );
851  lwgeom_free(geom);
852 
853  geom = lwgeom_from_wkt("POLYGON EMPTY", LW_PARSER_CHECK_NONE);
854  CU_ASSERT( lwgeom_is_empty(geom) );
855  lwgeom_free(geom);
856 
857  geom = lwgeom_from_wkt("MULTIPOINT EMPTY", LW_PARSER_CHECK_NONE);
858  CU_ASSERT( lwgeom_is_empty(geom) );
859  lwgeom_free(geom);
860 
861  geom = lwgeom_from_wkt("MULTILINESTRING EMPTY", LW_PARSER_CHECK_NONE);
862  CU_ASSERT( lwgeom_is_empty(geom) );
863  lwgeom_free(geom);
864 
865  geom = lwgeom_from_wkt("MULTIPOLYGON EMPTY", LW_PARSER_CHECK_NONE);
866  CU_ASSERT( lwgeom_is_empty(geom) );
867  lwgeom_free(geom);
868 
869  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY, POINT EMPTY, LINESTRING EMPTY, POLYGON EMPTY, MULTIPOINT EMPTY, MULTILINESTRING EMPTY, MULTIPOLYGON EMPTY, GEOMETRYCOLLECTION(MULTIPOLYGON EMPTY))", LW_PARSER_CHECK_NONE);
870  CU_ASSERT( lwgeom_is_empty(geom) );
871  lwgeom_free(geom);
872 
873 }
874 
875 /*
876  * Test lwgeom_same
877  */
878 static void test_lwgeom_same(void)
879 {
880  LWGEOM *geom, *geom2;
881 
882  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
883  CU_ASSERT( lwgeom_same(geom, geom) );
884  lwgeom_add_bbox(geom);
885  CU_ASSERT( lwgeom_same(geom, geom) );
886  lwgeom_free(geom);
887 
888  geom = lwgeom_from_wkt("MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)))", LW_PARSER_CHECK_NONE);
889  CU_ASSERT( lwgeom_same(geom, geom) );
890  lwgeom_add_bbox(geom);
891  CU_ASSERT( lwgeom_same(geom, geom) );
892  lwgeom_free(geom);
893 
894  geom = lwgeom_from_wkt("LINESTRING(0 0, 2 0)", LW_PARSER_CHECK_NONE);
895  CU_ASSERT( lwgeom_same(geom, geom) );
896  lwgeom_add_bbox(geom);
897  CU_ASSERT( lwgeom_same(geom, geom) );
898  lwgeom_free(geom);
899 
900  geom = lwgeom_from_wkt("MULTILINESTRING((0 0, 2 0))", LW_PARSER_CHECK_NONE);
901  CU_ASSERT( lwgeom_same(geom, geom) );
902  lwgeom_add_bbox(geom);
903  CU_ASSERT( lwgeom_same(geom, geom) );
904  lwgeom_free(geom);
905 
906  geom = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
907  CU_ASSERT( lwgeom_same(geom, geom) );
908  lwgeom_add_bbox(geom);
909  CU_ASSERT( lwgeom_same(geom, geom) );
910  lwgeom_free(geom);
911 
912  geom = lwgeom_from_wkt("MULTIPOINT((0 0),(4 5))", LW_PARSER_CHECK_NONE);
913  CU_ASSERT( lwgeom_same(geom, geom) );
914  lwgeom_add_bbox(geom);
915  CU_ASSERT( lwgeom_same(geom, geom) );
916  lwgeom_free(geom);
917 
918  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
919  CU_ASSERT( lwgeom_same(geom, geom) );
920  lwgeom_add_bbox(geom);
921  CU_ASSERT( lwgeom_same(geom, geom) );
922  lwgeom_free(geom);
923 
924  geom = lwgeom_from_wkt("LINESTRING EMPTY", LW_PARSER_CHECK_NONE);
925  CU_ASSERT( lwgeom_same(geom, geom) );
926  lwgeom_add_bbox(geom);
927  CU_ASSERT( lwgeom_same(geom, geom) );
928  lwgeom_free(geom);
929 
930  geom = lwgeom_from_wkt("POLYGON EMPTY", LW_PARSER_CHECK_NONE);
931  CU_ASSERT( lwgeom_same(geom, geom) );
932  lwgeom_free(geom);
933 
934  geom = lwgeom_from_wkt("MULTIPOINT EMPTY", LW_PARSER_CHECK_NONE);
935  CU_ASSERT( lwgeom_same(geom, geom) );
936  lwgeom_free(geom);
937 
938  geom = lwgeom_from_wkt("MULTILINESTRING EMPTY", LW_PARSER_CHECK_NONE);
939  CU_ASSERT( lwgeom_same(geom, geom) );
940  lwgeom_free(geom);
941 
942  geom = lwgeom_from_wkt("MULTIPOLYGON EMPTY", LW_PARSER_CHECK_NONE);
943  CU_ASSERT( lwgeom_same(geom, geom) );
944  lwgeom_free(geom);
945 
946  geom = lwgeom_from_wkt("GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY, POINT EMPTY, LINESTRING EMPTY, POLYGON EMPTY, MULTIPOINT EMPTY, MULTILINESTRING EMPTY, MULTIPOLYGON EMPTY, GEOMETRYCOLLECTION(MULTIPOLYGON EMPTY))", LW_PARSER_CHECK_NONE);
947  CU_ASSERT( lwgeom_same(geom, geom) );
948  lwgeom_free(geom);
949 
950  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
951  geom2 = lwgeom_from_wkt("GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY, POINT EMPTY, LINESTRING EMPTY, POLYGON EMPTY, MULTIPOINT EMPTY, MULTILINESTRING EMPTY, MULTIPOLYGON EMPTY, GEOMETRYCOLLECTION(MULTIPOLYGON EMPTY))", LW_PARSER_CHECK_NONE);
952  CU_ASSERT( ! lwgeom_same(geom, geom2) );
953  lwgeom_free(geom);
954  lwgeom_free(geom2);
955 
956  geom = lwgeom_from_wkt("POINT(0 0)", LW_PARSER_CHECK_NONE);
957  geom2 = lwgeom_from_wkt("MULTIPOINT((0 0))", LW_PARSER_CHECK_NONE);
958  CU_ASSERT( ! lwgeom_same(geom, geom2) );
959  lwgeom_free(geom);
960  lwgeom_free(geom2);
961 
962  geom = lwgeom_from_wkt("POINT EMPTY", LW_PARSER_CHECK_NONE);
963  geom2 = lwgeom_from_wkt("POINT Z EMPTY", LW_PARSER_CHECK_NONE);
964  CU_ASSERT( ! lwgeom_same(geom, geom2) );
965  lwgeom_free(geom);
966  lwgeom_free(geom2);
967 
968 }
969 
970 /*
971  * Test lwgeom_force_curve
972  */
973 static void test_lwgeom_as_curve(void)
974 {
975  LWGEOM *geom;
976  LWGEOM *geom2;
977  char *in_ewkt, *out_ewkt;
978 
979  geom = lwgeom_from_wkt("LINESTRING(0 0, 10 0)", LW_PARSER_CHECK_NONE);
980  geom2 = lwgeom_as_curve(geom);
981  in_ewkt = "COMPOUNDCURVE((0 0,10 0))";
982  out_ewkt = lwgeom_to_ewkt(geom2);
983  if (strcmp(in_ewkt, out_ewkt))
984  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
985  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
986  lwfree(out_ewkt);
987  lwgeom_free(geom);
988  lwgeom_free(geom2);
989 
990  geom = lwgeom_from_wkt("MULTILINESTRING((0 0, 10 0))", LW_PARSER_CHECK_NONE);
991  geom2 = lwgeom_as_curve(geom);
992  in_ewkt = "MULTICURVE((0 0,10 0))";
993  out_ewkt = lwgeom_to_ewkt(geom2);
994  if (strcmp(in_ewkt, out_ewkt))
995  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
996  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
997  lwfree(out_ewkt);
998  lwgeom_free(geom);
999  lwgeom_free(geom2);
1000 
1001  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
1002  geom2 = lwgeom_as_curve(geom);
1003  in_ewkt = "CURVEPOLYGON((0 0,10 0,10 10,0 10,0 0))";
1004  out_ewkt = lwgeom_to_ewkt(geom2);
1005  if (strcmp(in_ewkt, out_ewkt))
1006  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
1007  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
1008  lwfree(out_ewkt);
1009  lwgeom_free(geom);
1010  lwgeom_free(geom2);
1011 
1012  geom = lwgeom_from_wkt("MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)))", LW_PARSER_CHECK_NONE);
1013  geom2 = lwgeom_as_curve(geom);
1014  in_ewkt = "MULTISURFACE(((0 0,10 0,10 10,0 10,0 0)))";
1015  out_ewkt = lwgeom_to_ewkt(geom2);
1016  if (strcmp(in_ewkt, out_ewkt))
1017  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
1018  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
1019  lwfree(out_ewkt);
1020  lwgeom_free(geom);
1021  lwgeom_free(geom2);
1022 
1023 }
1024 
1025 static void test_lwline_from_lwmpoint(void)
1026 {
1027  LWLINE *line;
1028  LWMPOINT *mpoint;
1029 
1030 // LWLINE *
1031 // lwline_from_lwmpoint(int srid, LWMPOINT *mpoint)
1032 
1033  mpoint = (LWMPOINT*)lwgeom_from_wkt("MULTIPOINT(0 0, 0 1, 1 1, 1 2, 2 2)", LW_PARSER_CHECK_NONE);
1034  line = lwline_from_lwmpoint(SRID_DEFAULT, mpoint);
1035  CU_ASSERT_EQUAL(line->points->npoints, mpoint->ngeoms);
1036  CU_ASSERT_DOUBLE_EQUAL(lwline_length_2d(line), 4.0, 0.000001);
1037 
1038  lwline_free(line);
1039  lwmpoint_free(mpoint);
1040 }
1041 
1042 /*
1043  * Test lwgeom_scale
1044  */
1045 static void test_lwgeom_scale(void)
1046 {
1047  LWGEOM *geom;
1048  POINT4D factor;
1049  char *out_ewkt;
1050  GBOX *box;
1051 
1052  geom = lwgeom_from_wkt("SRID=4326;GEOMETRYCOLLECTION(POINT(0 1 2 3),POLYGON((-1 -1 0 1,-1 2.5 0 1,2 2 0 1,2 -1 0 1,-1 -1 0 1),(0 0 1 2,0 1 1 2,1 1 1 2,1 0 2 3,0 0 1 2)),LINESTRING(0 0 0 0, 1 2 3 4))", LW_PARSER_CHECK_NONE);
1053  factor.x = 2; factor.y = 3; factor.z = 4; factor.m = 5;
1054  lwgeom_scale(geom, &factor);
1055  out_ewkt = lwgeom_to_ewkt(geom);
1056  ASSERT_STRING_EQUAL(out_ewkt, "SRID=4326;GEOMETRYCOLLECTION(POINT(0 3 8 15),POLYGON((-2 -3 0 5,-2 7.5 0 5,4 6 0 5,4 -3 0 5,-2 -3 0 5),(0 0 4 10,0 3 4 10,2 3 4 10,2 0 8 15,0 0 4 10)),LINESTRING(0 0 0 0,2 6 12 20))");
1057  lwgeom_free(geom);
1058  lwfree(out_ewkt);
1059 
1060  geom = lwgeom_from_wkt("POINT(1 1 1 1)", LW_PARSER_CHECK_NONE);
1061  lwgeom_add_bbox(geom);
1062  factor.x = 2; factor.y = 3; factor.z = 4; factor.m = 5;
1063  lwgeom_scale(geom, &factor);
1064  box = geom->bbox;
1065  ASSERT_DOUBLE_EQUAL(box->xmin, 2);
1066  ASSERT_DOUBLE_EQUAL(box->xmax, 2);
1067  ASSERT_DOUBLE_EQUAL(box->ymin, 3);
1068  ASSERT_DOUBLE_EQUAL(box->ymax, 3);
1069  ASSERT_DOUBLE_EQUAL(box->zmin, 4);
1070  ASSERT_DOUBLE_EQUAL(box->zmax, 4);
1071  ASSERT_DOUBLE_EQUAL(box->mmin, 5);
1072  ASSERT_DOUBLE_EQUAL(box->mmax, 5);
1073  lwgeom_free(geom);
1074 }
1075 
1076 void test_gbox_same_2d(void);
1078 {
1079  LWGEOM* g1 = lwgeom_from_wkt("LINESTRING(0 0, 1 1)", LW_PARSER_CHECK_NONE);
1080  LWGEOM* g2 = lwgeom_from_wkt("LINESTRING(0 0, 0 1, 1 1)", LW_PARSER_CHECK_NONE);
1081  LWGEOM* g3 = lwgeom_from_wkt("LINESTRING(0 0, 1 1.000000000001)", LW_PARSER_CHECK_NONE);
1082 
1083  lwgeom_add_bbox(g1);
1084  lwgeom_add_bbox(g2);
1085  lwgeom_add_bbox(g3);
1086 
1087  CU_ASSERT_TRUE(gbox_same_2d(g1->bbox, g2->bbox));
1088  CU_ASSERT_FALSE(gbox_same_2d(g1->bbox, g3->bbox));
1089 
1090  /* Serializing a GBOX with precise coordinates renders the boxes not strictly equal,
1091  * but still equal according to gbox_same_2d_float.
1092  */
1093  GSERIALIZED* s3 = gserialized_from_lwgeom(g3, NULL);
1094  GBOX s3box;
1095  gserialized_read_gbox_p(s3, &s3box);
1096 
1097  CU_ASSERT_FALSE(gbox_same_2d(g3->bbox, &s3box));
1098  CU_ASSERT_TRUE(gbox_same_2d_float(g3->bbox, &s3box));
1099 
1100  /* The serialized box equals itself by either the exact or closest-float compares */
1101  CU_ASSERT_TRUE(gbox_same_2d(&s3box, &s3box));
1102  CU_ASSERT_TRUE(gbox_same_2d_float(&s3box, &s3box));
1103 
1104  lwgeom_free(g1);
1105  lwgeom_free(g2);
1106  lwgeom_free(g3);
1107  lwfree(s3);
1108 }
1109 
1112 {
1113  uint32_t i;
1114 
1115  char *ewkt[] =
1116  {
1117  "POINT EMPTY",
1118  "LINESTRING EMPTY",
1119  "MULTIPOINT EMPTY",
1120  "MULTIPOINT (EMPTY)",
1121  "MULTILINESTRING EMPTY",
1122  "MULTILINESTRING (EMPTY)"
1123  };
1124 
1125  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
1126  {
1127  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
1128  GBOX box;
1129  gbox_init(&box);
1130 
1131  GSERIALIZED* gser = gserialized_from_lwgeom(geom, NULL);
1132 
1133  CU_ASSERT_FALSE(gserialized_has_bbox(gser));
1134 
1135  CU_ASSERT_EQUAL(LW_FAILURE, gserialized_peek_gbox_p(gser, &box));
1136 
1137  lwgeom_free(geom);
1138  lwfree(gser);
1139  }
1140 }
1141 
1144 {
1145  uint32_t i;
1146 
1147  char *ewkt[] =
1148  {
1149  "POINT (2.2945672355 48.85822923236)",
1150  "POINTZ (2.2945672355 48.85822923236 15)",
1151  "POINTM (2.2945672355 48.85822923236 12)",
1152  "POINT ZM (2.2945672355 48.85822923236 12 2)",
1153  "MULTIPOINT ((-76.45402132523 44.225406213532))",
1154  "MULTIPOINT Z ((-76.45402132523 44.225406213532 112))",
1155  "MULTIPOINT ZM ((-76.45402132523 44.225406213532 112 44))",
1156  "LINESTRING (2.2945672355 48.85822923236, -76.45402132523 44.225406213532)",
1157  "LINESTRING Z (2.2945672355 48.85822923236 6, -76.45402132523 44.225406213532 8)",
1158  "LINESTRING ZM (2.2945672355 48.85822923236 3 2, -76.45402132523 44.225406213532 9 4)",
1159  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532))",
1160  "MULTILINESTRING Z ((2.2945672355 48.85822923236 4, -76.45402132523 44.225406213532 3))"
1161  };
1162 
1163  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
1164  {
1165  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
1166  GBOX box_from_peek;
1167  GBOX box_from_lwgeom;
1168  gbox_init(&box_from_peek);
1169  gbox_init(&box_from_lwgeom);
1170 
1171  GSERIALIZED* gser = gserialized_from_lwgeom(geom, NULL);
1172 
1173  CU_ASSERT_FALSE(gserialized_has_bbox(gser));
1174 
1175  lwgeom_calculate_gbox(geom, &box_from_lwgeom);
1176  gserialized_peek_gbox_p(gser, &box_from_peek);
1177 
1178  gbox_float_round(&box_from_lwgeom);
1179 
1180  CU_ASSERT_TRUE(gbox_same(&box_from_peek, &box_from_lwgeom));
1181 
1182  lwgeom_free(geom);
1183  lwfree(gser);
1184  }
1185 }
1186 
1189 {
1190  uint32_t i;
1191 
1192  char *ewkt[] =
1193  {
1194  "MULTIPOINT ((-76.45402132523 44.225406213532), (-72 33))",
1195  "LINESTRING (2.2945672355 48.85822923236, -76.45402132523 44.225406213532, -72 33)",
1196  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532, -72 33))",
1197  "MULTILINESTRING ((2.2945672355 48.85822923236, -76.45402132523 44.225406213532), (-72 33, -71 32))"
1198  };
1199 
1200  for ( i = 0; i < (sizeof ewkt/sizeof(char*)); i++ )
1201  {
1202  LWGEOM* geom = lwgeom_from_wkt(ewkt[i], LW_PARSER_CHECK_NONE);
1203  GBOX box;
1204  gbox_init(&box);
1205  lwgeom_drop_bbox(geom);
1206 
1207  /* Construct a GSERIALIZED* that doesn't have a box, so that we can test the
1208  * actual logic of the peek function */
1209  size_t expected_size = gserialized_from_lwgeom_size(geom);
1210  GSERIALIZED* gser = lwalloc(expected_size);
1211  uint8_t* ptr = (uint8_t*) gser;
1212 
1213  ptr += 8; // Skip header
1214  gserialized_from_lwgeom_any(geom, ptr);
1215  gser->flags = geom->flags;
1216 
1217  CU_ASSERT_FALSE(gserialized_has_bbox(gser));
1218  CU_ASSERT_EQUAL(LW_FAILURE, gserialized_peek_gbox_p(gser, &box));
1219 
1220  lwgeom_free(geom);
1221  lwfree(gser);
1222  }
1223 }
1224 
1225 void test_signum_macro(void);
1227 {
1228  CU_ASSERT_EQUAL(SIGNUM(-5.0),-1);
1229  CU_ASSERT_EQUAL(SIGNUM( 5.0), 1);
1230  CU_ASSERT_EQUAL(SIGNUM( 0.0), 0);
1231  CU_ASSERT_EQUAL(SIGNUM(10) * 5, 5);
1232  CU_ASSERT_EQUAL(SIGNUM(-10) * 5, -5);
1233 }
1234 
1235 /*
1236 ** Used by test harness to register the tests in this file.
1237 */
1238 void libgeom_suite_setup(void);
1240 {
1241  CU_pSuite suite = CU_add_suite("serialization/deserialization", NULL, NULL);
1252  PG_ADD_TEST(suite, test_lwgeom_free);
1254  PG_ADD_TEST(suite, test_f2d);
1259  PG_ADD_TEST(suite, test_lwgeom_same);
1269 }
double x
Definition: liblwgeom.h:352
#define LINETYPE
Definition: liblwgeom.h:86
#define TYPMOD_GET_TYPE(typmod)
Definition: liblwgeom.h:167
static void test_gserialized_from_lwgeom_size(void)
Definition: cu_libgeom.c:159
int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
Definition: g_serialized.c:416
GBOX * bbox
Definition: liblwgeom.h:398
static void test_on_gser_lwgeom_count_vertices(void)
Definition: cu_libgeom.c:426
double m
Definition: liblwgeom.h:352
#define TYPMOD_GET_M(typmod)
Definition: liblwgeom.h:171
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:369
#define TYPMOD_SET_Z(typmod)
Definition: liblwgeom.h:170
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
Definition: lwout_wkt.c:669
static void test_typmod_macros(void)
Definition: cu_libgeom.c:21
void lwfree(void *mem)
Definition: lwutil.c:244
#define FLAGS_GET_READONLY(flags)
Definition: liblwgeom.h:144
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:371
void test_gbox_same_2d(void)
Definition: cu_libgeom.c:1077
uint8_t type
Definition: liblwgeom.h:503
static void test_gserialized_is_empty(void)
Definition: cu_libgeom.c:320
static void test_lwgeom_scale(void)
Definition: cu_libgeom.c:1045
#define ASSERT_STRING_EQUAL(o, e)
static int gserialized_peek_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Definition: g_serialized.c:463
#define FLAGS_GET_GEODETIC(flags)
Definition: liblwgeom.h:143
#define POLYGONTYPE
Definition: liblwgeom.h:87
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:518
#define TYPMOD_GET_SRID(typmod)
Macros for manipulating the &#39;typemod&#39; int.
Definition: liblwgeom.h:165
uint8_t flags
Definition: liblwgeom.h:397
double xmax
Definition: liblwgeom.h:293
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Calculate type integer and dimensional flags from string input.
Definition: g_util.c:163
#define LW_SUCCESS
Definition: liblwgeom.h:80
void lwline_free(LWLINE *line)
Definition: lwline.c:76
void lwgeom_scale(LWGEOM *geom, const POINT4D *factors)
Definition: lwgeom.c:1786
static void test_geometry_type_from_string(void)
Definition: cu_libgeom.c:362
#define SRID_DEFAULT
Definition: liblwgeom.h:195
#define FLAGS_GET_ZM(flags)
Definition: liblwgeom.h:153
void gserialized_set_srid(GSERIALIZED *s, int32_t srid)
Write the SRID into the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:117
double lwline_length_2d(const LWLINE *line)
Definition: lwline.c:586
static void test_lwgeom_force_clockwise(void)
Definition: cu_libgeom.c:766
float next_float_down(double d)
Definition: lwgeom_api.c:51
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
static void test_lwcollection_extract(void)
Definition: cu_libgeom.c:450
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:149
static void test_lwgeom_as_curve(void)
Definition: cu_libgeom.c:973
static void test_gbox_serialized_size(void)
Definition: cu_libgeom.c:237
int gserialized_has_bbox(const GSERIALIZED *gser)
Check if a GSERIALIZED has a bounding box without deserializing first.
Definition: g_serialized.c:40
static void test_flags_macros(void)
Definition: cu_libgeom.c:76
void lwgeom_drop_bbox(LWGEOM *lwgeom)
Call this function to drop BBOX and SRID from LWGEOM.
Definition: lwgeom.c:635
LWGEOM * lwgeom_flip_coordinates(LWGEOM *in)
Reverse the X and Y coordinate order.
Definition: lwgeom.c:1507
static void test_lwgeom_free(void)
Definition: cu_libgeom.c:489
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
Definition: g_serialized.c:179
#define LW_FAILURE
Definition: liblwgeom.h:79
float next_float_up(double d)
Definition: lwgeom_api.c:72
unsigned int uint32_t
Definition: uthash.h:78
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:701
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:146
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:36
void gbox_float_round(GBOX *gbox)
Round given GBOX to float boundaries.
Definition: g_box.c:717
static void do_lwgeom_flip_coordinates(char *in, char *out)
Definition: cu_libgeom.c:515
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:72
double zmax
Definition: liblwgeom.h:297
double ymin
Definition: liblwgeom.h:294
static void test_serialized_srid(void)
Definition: cu_libgeom.c:127
void libgeom_suite_setup(void)
Definition: cu_libgeom.c:1239
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:51
double xmin
Definition: liblwgeom.h:292
static void test_f2d(void)
Definition: cu_libgeom.c:667
#define FLAGS_GET_BBOX(flags)
Definition: liblwgeom.h:142
void test_signum_macro(void)
Definition: cu_libgeom.c:1226
static void test_lwgeom_calculate_gbox(void)
Definition: cu_libgeom.c:201
LWLINE * lwline_from_lwmpoint(int srid, const LWMPOINT *mpoint)
Definition: lwline.c:290
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
#define PG_ADD_TEST(suite, testfunc)
static void test_lwgeom_is_empty(void)
Definition: cu_libgeom.c:837
void test_gserialized_peek_gbox_p_fails_for_unsupported_cases(void)
Definition: cu_libgeom.c:1188
double ymax
Definition: liblwgeom.h:295
char * s
Definition: cu_in_wkt.c:23
#define TYPMOD_SET_TYPE(typmod, type)
Definition: liblwgeom.h:168
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
Definition: g_box.c:191
double z
Definition: liblwgeom.h:352
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:444
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:544
uint8_t gflags(int hasz, int hasm, int geodetic)
Construct a new flags char.
Definition: g_util.c:145
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:797
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define WKT_EXTENDED
Definition: liblwgeom.h:2085
#define FLAGS_SET_BBOX(flags, value)
Definition: liblwgeom.h:148
void test_gserialized_peek_gbox_p_gets_correct_box(void)
Definition: cu_libgeom.c:1143
static void test_lwgeom_flip_coordinates(void)
Definition: cu_libgeom.c:551
static void test_lwgeom_clone(void)
Definition: cu_libgeom.c:719
size_t gserialized_from_lwgeom_size(const LWGEOM *geom)
Calculate required memory segment to contain a serialized form of the LWGEOM.
Definition: g_serialized.c:810
static void test_lwgeom_same(void)
Definition: cu_libgeom.c:878
static void test_lwline_from_lwmpoint(void)
Definition: cu_libgeom.c:1025
static void test_lwgeom_from_gserialized(void)
Definition: cu_libgeom.c:254
double mmin
Definition: liblwgeom.h:298
double zmin
Definition: liblwgeom.h:296
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:648
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
uint8_t type
Definition: liblwgeom.h:396
type
Definition: ovdump.py:41
static size_t gserialized_from_lwgeom_any(const LWGEOM *geom, uint8_t *buf)
double mmax
Definition: liblwgeom.h:299
void lwcollection_free(LWCOLLECTION *col)
Definition: lwcollection.c:340
#define ASSERT_DOUBLE_EQUAL(o, e)
#define TYPMOD_SET_SRID(typmod, srid)
Definition: liblwgeom.h:166
LWGEOM * lwgeom_as_curve(const LWGEOM *lwgeom)
Create a new LWGEOM of the appropriate CURVE* type.
Definition: lwgeom.c:373
int lwgeom_is_clockwise(LWGEOM *lwgeom)
Check clockwise orientation on LWGEOM polygons.
Definition: lwgeom.c:64
#define TYPMOD_GET_Z(typmod)
Definition: liblwgeom.h:169
void * lwalloc(size_t size)
Definition: lwutil.c:229
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1346
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1189
int gbox_same_2d_float(const GBOX *g1, const GBOX *g2)
Check if two given GBOX are the same in x and y, or would round to the same GBOX in x and if serializ...
Definition: g_box.c:199
double y
Definition: liblwgeom.h:352
#define MULTILINETYPE
Definition: liblwgeom.h:89
int ngeoms
Definition: liblwgeom.h:468
unsigned char uint8_t
Definition: uthash.h:79
int gbox_same(const GBOX *g1, const GBOX *g2)
Check if 2 given Gbox are the same.
Definition: g_box.c:176
void test_gserialized_peek_gbox_p_no_box_when_empty(void)
Definition: cu_libgeom.c:1111
static void test_lwgeom_count_vertices(void)
Definition: cu_libgeom.c:408
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:100
size_t gbox_serialized_size(uint8_t flags)
Return the number of bytes necessary to hold a GBOX of this dimension in serialized form...
Definition: g_box.c:451
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
#define SIGNUM(n)
Macro that returns: -1 if n < 0, 1 if n > 0, 0 if n == 0.
#define FLAGS_SET_READONLY(flags, value)
Definition: liblwgeom.h:150
uint8_t flags
Definition: liblwgeom.h:383
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:147
POINTARRAY * points
Definition: liblwgeom.h:422
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition: g_box.c:683