Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty geometry to be parsed by jts2geojson #49

Open
rtroilo opened this issue Oct 26, 2022 · 1 comment
Open

Allow empty geometry to be parsed by jts2geojson #49

rtroilo opened this issue Oct 26, 2022 · 1 comment

Comments

@rtroilo
Copy link

rtroilo commented Oct 26, 2022

Many thanks for this great library @bjornharrtell !

Currently jts2geojson is not be able to parse empty geometries in either direction.
This is a correct behavior as GeoJSON processors are not required to parse empty geometries but may do so.

Would you are interested and accept a PR which brings empty geometry parsing into jts2geojson?

JTS already implements this with the additional dependency org.locationtech.jts.io:jts-io-common and the corresponding org.locationtech.jts.io.geojson.GeoJsonWriter.

var geomFactory = new GeometryFactory();
var geoJsonWriter = new org.locationtech.jts.io.geojson.GeoJsonWriter();
geoJsonWriter.setEncodeCRS(false);

var emptyPoint = geomFactory.createPoint();

var geoJson = geoJsonWriter.write(emptyPoint);
// {"type":"Point","coordinates":[]}

RFT 7946 Geometry Object

A GeoJSON Geometry object of any type other than
"GeometryCollection" has a member with the name "coordinates".
The value of the "coordinates" member is an array. The structure
of the elements in this array is determined by the type of
geometry. GeoJSON processors MAY interpret Geometry objects with
empty "coordinates" arrays as null objects.

@bjornharrtell
Copy link
Owner

Sure, sounds like a sensible thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants