15 #include "CUnit/Basic.h"
29 fprintf(stderr,
"\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
31 CU_ASSERT_STRING_EQUAL(h, out);
47 fprintf(stderr,
"\nIn: %s\nOut: %s\nTheo: %s\n",
62 "POINT(1.1111111111111 1.1111111111111)",
63 "{\"type\":\"Point\",\"coordinates\":[1,1]}",
68 "POINT(1.1111111111111 1.1111111111111)",
69 "{\"type\":\"Point\",\"coordinates\":[1.111,1.111]}",
74 "POINT(1.2345678901234 1.2345678901234)",
75 "{\"type\":\"Point\",\"coordinates\":[1.23456789,1.23456789]}",
80 "POINT(1E300 -1E300)",
81 "{\"type\":\"Point\",\"coordinates\":[1e+300,-1e+300]}",
87 "{\"type\":\"Point\",\"coordinates\":[1,2]}",
92 "POINT(59.99 -59.99)",
93 "{\"type\":\"Point\",\"coordinates\":[59.99,-59.99]}",
103 "{\"type\":\"Point\",\"coordinates\":[0,0]}",
115 "{\"type\":\"Point\",\"coordinates\":[0,1,2]}",
121 "{\"type\":\"Point\",\"coordinates\":[0,1]}",
127 "{\"type\":\"Point\",\"coordinates\":[0,1,2]}",
136 "LINESTRING(0 1,2 3,4 5)",
137 "{\"type\":\"LineString\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[0,1],[2,3],[4,5]]}",
142 "POLYGON((0 1,2 3,4 5,0 1))",
143 "{\"type\":\"Polygon\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]]]}",
148 "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
149 "{\"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]]]}",
154 "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
155 "{\"type\":\"MultiLineString\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[[[0,1],[2,3],[4,5]],[[6,7],[8,9],[10,11]]]}",
160 "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
161 "{\"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]]]]}",
166 "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
167 "{\"type\":\"GeometryCollection\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"geometries\":[{\"type\":\"Point\",\"coordinates\":[0,1]},{\"type\":\"LineString\",\"coordinates\":[[2,3],[4,5]]}]}",
172 "GEOMETRYCOLLECTION EMPTY",
173 "{\"type\":\"GeometryCollection\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"geometries\":[]}",
177 static void out_geojson_test_bbox(
void)
181 "LINESTRING(0 1,2 3,4 5)",
182 "{\"type\":\"LineString\",\"bbox\":[0,1,4,5],\"coordinates\":[[0,1],[2,3],[4,5]]}",
187 "POLYGON((0 1,2 3,4 5,0 1))",
188 "{\"type\":\"Polygon\",\"bbox\":[0,1,4,5],\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]]]}",
193 "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
194 "{\"type\":\"Polygon\",\"bbox\":[0,1,4,5],\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]],[[6,7],[8,9],[10,11],[6,7]]]}",
199 "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
200 "{\"type\":\"MultiLineString\",\"bbox\":[0,1,10,11],\"coordinates\":[[[0,1],[2,3],[4,5]],[[6,7],[8,9],[10,11]]]}",
205 "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
206 "{\"type\":\"MultiPolygon\",\"bbox\":[0,1,10,11],\"coordinates\":[[[[0,1],[2,3],[4,5],[0,1]]],[[[6,7],[8,9],[10,11],[6,7]]]]}",
211 "GEOMETRYCOLLECTION(LINESTRING(0 1,-1 3),LINESTRING(2 3,4 5))",
212 "{\"type\":\"GeometryCollection\",\"bbox\":[-1,1,4,5],\"geometries\":[{\"type\":\"LineString\",\"coordinates\":[[0,1],[-1,3]]},{\"type\":\"LineString\",\"coordinates\":[[2,3],[4,5]]}]}",
217 "GEOMETRYCOLLECTION EMPTY",
218 "{\"type\":\"GeometryCollection\",\"geometries\":[]}",
222 static void out_geojson_test_geoms(
void)
226 "LINESTRING(0 1,2 3,4 5)",
227 "{\"type\":\"LineString\",\"coordinates\":[[0,1],[2,3],[4,5]]}",
232 "POLYGON((0 1,2 3,4 5,0 1))",
233 "{\"type\":\"Polygon\",\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]]]}",
238 "POLYGON((0 1,2 3,4 5,0 1),(6 7,8 9,10 11,6 7))",
239 "{\"type\":\"Polygon\",\"coordinates\":[[[0,1],[2,3],[4,5],[0,1]],[[6,7],[8,9],[10,11],[6,7]]]}",
244 "MULTILINESTRING((0 1,2 3,4 5),(6 7,8 9,10 11))",
245 "{\"type\":\"MultiLineString\",\"coordinates\":[[[0,1],[2,3],[4,5]],[[6,7],[8,9],[10,11]]]}",
250 "MULTIPOLYGON(((0 1,2 3,4 5,0 1)),((6 7,8 9,10 11,6 7)))",
251 "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0,1],[2,3],[4,5],[0,1]]],[[[6,7],[8,9],[10,11],[6,7]]]]}",
256 "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
257 "{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[0,1]},{\"type\":\"LineString\",\"coordinates\":[[2,3],[4,5]]}]}",
262 "GEOMETRYCOLLECTION EMPTY",
263 "{\"type\":\"GeometryCollection\",\"geometries\":[]}",
268 "GEOMETRYCOLLECTION(POINT(0 1),GEOMETRYCOLLECTION(LINESTRING(2 3,4 5)))",
269 "GeoJson: geometry not supported.");
273 "CIRCULARSTRING(-2 0,0 2,2 0,0 2,2 4)",
274 "lwgeom_to_geojson: 'CircularString' geometry type not supported");
278 "COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1,1 0),(1 0,0 1))",
279 "lwgeom_to_geojson: 'CompoundCurve' geometry type not supported");
283 "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))",
284 "lwgeom_to_geojson: 'CurvePolygon' geometry type not supported");
288 "MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 2))",
289 "lwgeom_to_geojson: 'MultiCurve' geometry type not supported");
293 "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)))",
294 "lwgeom_to_geojson: 'MultiSurface' geometry type not supported");
303 CU_pSuite suite = CU_add_suite(
"geojson_output", NULL, NULL);
static void out_geojson_test_dims(void)
static void do_geojson_unsupported(char *in, char *out)
static void out_geojson_test_precision(void)
static void do_geojson_test(char *in, char *out, char *srs, int precision, int has_bbox)
static void out_geojson_test_srid(void)
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
void out_geojson_suite_setup(void)
#define PG_ADD_TEST(suite, testfunc)
void lwgeom_free(LWGEOM *geom)
#define LW_PARSER_CHECK_NONE
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
char * lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.