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

Z coordinate isn't used in JtsGeoJSONWriter #191

Open
porunov opened this issue Aug 12, 2020 · 3 comments
Open

Z coordinate isn't used in JtsGeoJSONWriter #191

porunov opened this issue Aug 12, 2020 · 3 comments

Comments

@porunov
Copy link

porunov commented Aug 12, 2020

I've found that JtsGeoJSONWriter cannot parse JtsPoint with 3 coordinates (x,y,z) to GeoJSON string. z coordinate is just dropped during parsing.
An example is below. geoJSONPoint should be the same JSON as backToGeoJSONPoint variable but you can see that Z coordinate isn't returned.

String geoJSONPoint = "{\"type\": \"Point\", \"coordinates\": [-117.26028657062011, 32.87234560059042, 12.1]}";
JtsSpatialContextFactory factory = new JtsSpatialContextFactory();
factory.geo = true;
factory.useJtsPoint = true;
factory.useJtsLineString = true;
factory.datelineRule = DatelineRule.none;
JtsSpatialContext context = new JtsSpatialContext(factory);
GeoJSONReader geojsonReader = new GeoJSONReader(context, factory);
JtsGeoJSONWriter geoJSONWriter = new JtsGeoJSONWriter(context, factory);
Shape shape = geojsonReader.read(geoJSONPoint);
String backToGeoJSONPoint = geoJSONWriter.toString(shape);
@porunov
Copy link
Author

porunov commented Aug 12, 2020

I guess there are 2 internal issues:

  1. JtsPoint isn't an instance of JtsGeometry. Thus, it is treated as simple point in JtsGeoJSONWriter.
  2. Even if we add a special case to treat JtsPoint similarly to JtsGeometry it still stores only 2 coordinates (x and y) because of the next method:
protected void write(Writer output, NumberFormat nf, Coordinate coord) throws IOException {
    output.write(91);
    output.write(nf.format(coord.x));
    output.write(44);
    output.write(nf.format(coord.y));
    output.write(93);
}

@dsmiley
Copy link
Contributor

dsmiley commented Aug 25, 2020

Z dimension is kind of a gray area; not particularly well supported. Feel free to file a PR to rectify the situation. I plan to do a release next week but I can delay for a PR.

@porunov
Copy link
Author

porunov commented Aug 25, 2020

I don't want to block the release because I don't think we will work on fixing Z dimension soon. Later if we decide that Z dimension is needed we could work on the PR.

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