16 #include "CUnit/Basic.h"
31 fprintf(stderr,
"\nIn: %s\nExp: %s\nObt: %s\n", in, exp,
cu_error_msg);
40 fprintf(stderr,
"\nIn: %s\nExp: %s\nObt: %s\n", in, exp, h);
41 CU_ASSERT_STRING_EQUAL(h, exp);
45 CU_ASSERT_STRING_EQUAL(h, exp);
52 fprintf(stderr,
"\nIn: %s\nExp: %s\nObt: (null)\n", in, exp_srs);
53 CU_ASSERT_EQUAL(srs, exp_srs);
55 else if (strcmp(srs, exp_srs))
57 fprintf(stderr,
"\nIn: %s\nExp: %s\nObt: %s\n", in, exp_srs, srs);
58 CU_ASSERT_STRING_EQUAL(srs, exp_srs);
63 fprintf(stderr,
"\nIn: %s\nExp: (null)\nObt: %s\n", in, srs);
64 CU_ASSERT_EQUAL(srs, exp_srs);
76 "LINESTRING(0 1,2 3,4 5)",
77 "{\"type\":\"LineString\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[0,1],[2,3],[4,5]]}",
82 "POLYGON((0 1,2 3,4 5,0 1))",
83 "{\"type\":\"Polygon\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]]]}",
88 "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
89 "{\"type\":\"Polygon\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]],[[6,7],[8,9],[10,11],[6,7]]]}",
94 "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
95 "{\"type\":\"MultiLineString\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[[0,1],[2,3],[4,5]],[[6,7],[8,9],[10,11]]]}",
100 "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
101 "{\"type\":\"MultiPolygon\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[[[0,1],[2,3],[4,5],[0,1]]],[[[6,7],[8,9],[10,11],[6,7]]]]}",
106 "GEOMETRYCOLLECTION EMPTY",
107 "{\"type\":\"GeometryCollection\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"geometries\":[]}",
111 static void in_geojson_test_bbox(
void)
115 "LINESTRING(0 1,2 3,4 5)",
116 "{\"type\":\"LineString\",\"bbox\":[0,1,4,5],\"coordinates\":[[0,1],[2,3],[4,5]]}",
121 "POLYGON((0 1,2 3,4 5,0 1))",
122 "{\"type\":\"Polygon\",\"bbox\":[0,1,4,5],\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]]]}",
127 "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
128 "{\"type\":\"Polygon\",\"bbox\":[0,1,4,5],\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]],[[6,7],[8,9],[10,11],[6,7]]]}",
133 "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
134 "{\"type\":\"MultiLineString\",\"bbox\":[0,1,10,11],\"coordinates\":[[[0,1],[2,3],[4,5]],[[6,7],[8,9],[10,11]]]}",
139 "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
140 "{\"type\":\"MultiPolygon\",\"bbox\":[0,1,10,11],\"coordinates\":[[[[0,1],[2,3],[4,5],[0,1]]],[[[6,7],[8,9],[10,11],[6,7]]]]}",
145 "GEOMETRYCOLLECTION(LINESTRING(0 1,-1 3),LINESTRING(2 3,4 5))",
146 "{\"type\":\"GeometryCollection\",\"bbox\":[-1,1,4,5],\"geometries\":[{\"type\":\"LineString\",\"coordinates\":[[0,1],[-1,3]]},{\"type\":\"LineString\",\"coordinates\":[[2,3],[4,5]]}]}",
151 "GEOMETRYCOLLECTION EMPTY",
152 "{\"type\":\"GeometryCollection\",\"geometries\":[]}",
156 static void in_geojson_test_geoms(
void)
160 "LINESTRING(0 1,2 3,4 5)",
161 "{\"type\":\"LineString\",\"coordinates\":[[0,1],[2,3],[4,5]]}",
166 "POLYGON((0 1,2 3,4 5,0 1))",
167 "{\"type\":\"Polygon\",\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]]]}",
172 "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
173 "{\"type\":\"Polygon\",\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]],[[6,7],[8,9],[10,11],[6,7]]]}",
178 "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
179 "{\"type\":\"MultiLineString\",\"coordinates\":[[[0,1],[2,3],[4,5]],[[6,7],[8,9],[10,11]]]}",
184 "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
185 "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0,1],[2,3],[4,5],[0,1]]],[[[6,7],[8,9],[10,11],[6,7]]]]}",
191 "MULTIPOLYGON(((4 0,0 -4,-4 0,0 4,4 0),(2 0,0 2,-2 0,0 -2,2 0)),((24 0,20 -4,16 0,20 4,24 0),(22 0,20 2,18 0,20 -2,22 0)),((44 0,40 -4,36 0,40 4,44 0),(42 0,40 2,38 0,40 -2,42 0)))",
192 "{'type':'MultiPolygon','coordinates':[[[[4,0],[0,-4],[-4,0],[0,4],[4,0]],[[2,0],[0,2],[-2,0],[0,-2],[2,0]]],[[[24,0],[20,-4],[16,0],[20,4],[24,0]],[[22,0],[20,2],[18,0],[20,-2],[22,0]]],[[[44,0],[40,-4],[36,0],[40,4],[44,0]],[[42,0],[40,2],[38,0],[40,-2],[42,0]]]]}",
197 "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
198 "{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[0,1]},{\"type\":\"LineString\",\"coordinates\":[[2,3],[4,5]]}]}",
203 "GEOMETRYCOLLECTION EMPTY",
204 "{\"type\":\"GeometryCollection\",\"geometries\":[]}",
210 "{\"type\":\"Point\",\"coordinates\":[]}",
216 "{\"type\":\"LineString\",\"coordinates\":[]}",
222 "{\"type\":\"Polygon\",\"coordinates\":[]}",
228 "{\"type\":\"MultiPoint\",\"coordinates\":[]}",
233 "MULTIPOLYGON EMPTY",
234 "{\"type\":\"MultiPolygon\",\"coordinates\":[]}",
244 CU_pSuite suite = CU_add_suite(
"geojson_input", NULL, NULL);
static void in_geojson_test_srid(void)
static void do_geojson_test(const char *exp, char *in, char *exp_srs)
void in_geojson_suite_setup(void)
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
#define PG_ADD_TEST(suite, testfunc)
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
void lwgeom_free(LWGEOM *geom)
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.