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

No support for Feature & FeatureCollection in GeoJson #419

Closed
FreifeldRoyi opened this issue Apr 21, 2019 · 8 comments
Closed

No support for Feature & FeatureCollection in GeoJson #419

FreifeldRoyi opened this issue Apr 21, 2019 · 8 comments

Comments

@FreifeldRoyi
Copy link

Hi
Feature & FeatureCollection is part of GeoJson spec for quite some time, and yet to be implemented in JTS (nor in Spatial4J).
Do you plan on releasing an implementation for it ?

@dr-jts
Copy link
Contributor

dr-jts commented Apr 21, 2019

The problem is that JTS has no notion of attributes. So it's not clear how these would be provided to the GeoJSON I/O classes, or in fact whether to do this.

The GeoJSON IO classes were really provided to be embedded in other JSON frameworks which needed to handled geometry.

@FreifeldRoyi
Copy link
Author

If I parse the Feature & FeatureCollection, will it be possible to hand the inner geometry type to JTS as a string and get a Geometry back, or should I construct everything manually? Or is there some other approach?
I know that https://github.com/bjornharrtell/jts2geojson somewhat supports these features. Is there a better practice?

@dr-jts
Copy link
Contributor

dr-jts commented Apr 22, 2019

If I parse the Feature & FeatureCollection, will it be possible to hand the inner geometry type to JTS as a string and get a Geometry back

Yes, that is the target use case for the GeoJSONReader.

I know that https://github.com/bjornharrtell/jts2geojson somewhat supports these features. Is there a better practice?

I will check with the original author of these classes to see what his architecture was.

@dr-jts
Copy link
Contributor

dr-jts commented Apr 23, 2019

The GeoJSONReader class is designed to be used in the context of JSON frameworks which allow custom deserializers to be defined. E.g. the Jackson API.

Here's a (partial) code snippet which shows how it can be used in Jackson:

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.ObjectCodec;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;

public class GeoJsonJacksonDeserializer extends JsonDeserializer<Geometry>
{
	public Geometry deserialize(JsonParser jsonParser, DeserializationContext context)
	{
		ObjectCodec oc = jsonParser.getCodec();
		JsonNode node = oc.readTree(jsonParser);
		String geoJson = node.toString();
		GeoJsonReader geoJsonReader = new GeoJsonReader();

		Reader reader = new StringReader(geoJson);
		Geometry result = geoJsonReader.read(reader);

@dr-jts dr-jts closed this as completed Aug 27, 2019
@danishnawab
Copy link
Contributor

@dr-jts Would it be a fair compromise to reduce GeoJSON's Feature to JTS' Geometry (and consequently FeatureCollection to GeometryCollection)?
Since JTS doesn't have a notion of additional properties (or id), could we just jettison those attributes and still map the standard GeoJSON types to the existing (and compatible) JTS types?
The GeoJSON RFC doesn't ascribe any special meaning to the properties object, so I suppose there is no harm in dropping it.
I could submit a PR if this proposal resonates with you.

@dr-jts
Copy link
Contributor

dr-jts commented Feb 11, 2022

@danishnawab yes, that seems like a reasonable extension. A PR for review is welcome.

@danishnawab
Copy link
Contributor

@dr-jts Here's the PR: #837

@ferdinand-swoboda
Copy link

The GeoJSONReader class is designed to be used in the context of JSON frameworks which allow custom deserializers to be defined. E.g. the Jackson API.

@dr-jts Is there a specific reason not to include a dedicated Jackson module such as e.g. this one into jts-io-common?
It would make its usage easier to input via a plain ObjectMapper.registerModule(new JtsGeometryModule());.

If not, would there be interest in a PR for such an addition?

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

No branches or pull requests

4 participants