String geoJson = "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[-126.456789,-2.123,0.0],[-123.456789,2.123,0.0],[-124.456789,2.123,0.0],[-125.456789,-2.123,0.0],[-126.456789,-2.123,0.0]]]},\"properties\":{\"myProp\":\"PropData1\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-123.123,55.555,0.0]},\"properties\":{\"myProp\":\"PropData2\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[[[123.456789,2.123,0.0],[-123.456789,2.123,0.0],[-124.456789,2.123,0.0],[-125.456789,-2.123,0.0],[123.456789,2.123,0.0]]]},\"properties\":{\"myProp\":\"PropData3\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-15.123,75.555,0.0]},\"properties\":{\"myProp\":\"PropData4\"}}]}";
JtsSpatialContextFactory factory = new JtsSpatialContextFactory();
JtsSpatialContext context = new JtsSpatialContext(factory);
GeoJSONReader geojsonReader = new GeoJSONReader(context, factory);
Shape shape = geojsonReader.read(geoJson);
Unknown type: FeatureCollection
java.text.ParseException: Unknown type: FeatureCollection
at org.locationtech.spatial4j.io.GeoJSONReader.readShape(GeoJSONReader.java:273)
at org.locationtech.spatial4j.io.GeoJSONReader.read(GeoJSONReader.java:48)
at org.locationtech.spatial4j.io.GeoJSONReader.read(GeoJSONReader.java:54)
For convince here is the geoJson which I try to parse:
Hi,
Spatial4j works with the "geometry" portion of GeoJSON, not the FeatureCollection wrapper. Perhaps pertinent documentation needs to be more clear about that.
Version:
spatial4j-0.7
The code to reproduce the error:
For convince here is the
geoJson
which I try to parse: