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);
48 fprintf(stderr,
"\nIn: %s\nExp: %s\nObt: (null)\n", in, exp_srs);
49 CU_ASSERT_EQUAL(srs, exp_srs);
51 else if (strcmp(srs, exp_srs))
53 fprintf(stderr,
"\nIn: %s\nExp: %s\nObt: %s\n", in, exp_srs, srs);
54 CU_ASSERT_STRING_EQUAL(srs, exp_srs);
59 fprintf(stderr,
"\nIn: %s\nExp: (null)\nObt: %s\n", in, srs);
60 CU_ASSERT_EQUAL(srs, exp_srs);
72 "LINESTRING(0 1,2 3,4 5)",
73 "{\"type\":\"LineString\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[0,1],[2,3],[4,5]]}",
78 "POLYGON((0 1,2 3,4 5,0 1))",
79 "{\"type\":\"Polygon\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]]]}",
84 "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
85 "{\"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]]]}",
90 "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
91 "{\"type\":\"MultiLineString\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[[0,1],[2,3],[4,5]],[[6,7],[8,9],[10,11]]]}",
96 "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
97 "{\"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]]]]}",
102 "GEOMETRYCOLLECTION EMPTY",
103 "{\"type\":\"GeometryCollection\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"geometries\":[]}",
107 static void in_geojson_test_bbox(
void)
111 "LINESTRING(0 1,2 3,4 5)",
112 "{\"type\":\"LineString\",\"bbox\":[0,1,4,5],\"coordinates\":[[0,1],[2,3],[4,5]]}",
117 "POLYGON((0 1,2 3,4 5,0 1))",
118 "{\"type\":\"Polygon\",\"bbox\":[0,1,4,5],\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]]]}",
123 "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
124 "{\"type\":\"Polygon\",\"bbox\":[0,1,4,5],\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]],[[6,7],[8,9],[10,11],[6,7]]]}",
129 "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
130 "{\"type\":\"MultiLineString\",\"bbox\":[0,1,10,11],\"coordinates\":[[[0,1],[2,3],[4,5]],[[6,7],[8,9],[10,11]]]}",
135 "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
136 "{\"type\":\"MultiPolygon\",\"bbox\":[0,1,10,11],\"coordinates\":[[[[0,1],[2,3],[4,5],[0,1]]],[[[6,7],[8,9],[10,11],[6,7]]]]}",
141 "GEOMETRYCOLLECTION(LINESTRING(0 1,-1 3),LINESTRING(2 3,4 5))",
142 "{\"type\":\"GeometryCollection\",\"bbox\":[-1,1,4,5],\"geometries\":[{\"type\":\"LineString\",\"coordinates\":[[0,1],[-1,3]]},{\"type\":\"LineString\",\"coordinates\":[[2,3],[4,5]]}]}",
147 "GEOMETRYCOLLECTION EMPTY",
148 "{\"type\":\"GeometryCollection\",\"geometries\":[]}",
152 static void in_geojson_test_geoms(
void)
156 "LINESTRING(0 1,2 3,4 5)",
157 "{\"type\":\"LineString\",\"coordinates\":[[0,1],[2,3],[4,5]]}",
162 "POLYGON((0 1,2 3,4 5,0 1))",
163 "{\"type\":\"Polygon\",\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]]]}",
168 "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
169 "{\"type\":\"Polygon\",\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]],[[6,7],[8,9],[10,11],[6,7]]]}",
174 "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
175 "{\"type\":\"MultiLineString\",\"coordinates\":[[[0,1],[2,3],[4,5]],[[6,7],[8,9],[10,11]]]}",
180 "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
181 "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0,1],[2,3],[4,5],[0,1]]],[[[6,7],[8,9],[10,11],[6,7]]]]}",
187 "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)))",
188 "{'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]]]]}",
193 "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
194 "{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[0,1]},{\"type\":\"LineString\",\"coordinates\":[[2,3],[4,5]]}]}",
199 "GEOMETRYCOLLECTION EMPTY",
200 "{\"type\":\"GeometryCollection\",\"geometries\":[]}",
210 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.