-
Notifications
You must be signed in to change notification settings - Fork 91
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
Support for LineStringZM #171
Conversation
f925f0f
to
7eb2282
Compare
Hey @bryanjos - I realized I hadn't updated the README, so that's been fixed. Does it make sense to you for me to go ahead and add support for the other "ZM" variants which are not currently supported by geo? No sweat if you don't have time to review or merge anything for a while, just wanted to make sure I'm not digging too much of a hole. |
@kanatohodets I think what you have here is good. But there is a conflict here with the PR I just merged in. I also think that PR tightened up the JSON parsing to be more GeoJSON compliant and maybe the ZM variants don't work for GeoJSON. Other than that, everything else looks good! |
Well! Things got a bit interesting as I dug into the merge conflict. TL;DR: I think I found an old bug with 'Z' things and GeoJSON decoding. I'm
As far as I understand the GeoJSON spec, it does not allow LineStringZ (or any PointZ, however, is correct - it does not parse "PointZ". I think this means that I would suggest the following:
Do any of these suggestions resonate with you? I think doing 1-3 will bring I'm happy to pick up this work (or something else entirely!) in whatever order Examples from my reference parser, PostGIS 3.2:
The same function decodes into a LineStringZ when the GeoJSON coords have
And when GeoJSON is provided with the 'M' member, it is ignored and decoded as
|
@kanatohodets thanks for the research you put in here. I am aligned in your thinking with points 1-3. And for point 4, I would just stick to the spec. There's been enough discussions and issues around it that I think it's best to stick to the spec. |
@kanatohodets And I think geo will need a breaking change for some unrelated things so with what you have set forth, I think you can add some deprecations until that change is ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for your work on this, @kanatohodets! I learned a lot reading through this discussion, and the code and tests look great.
I'm gonna merge this with the tests fixed to match the existing behavior of dropping the M coordinate on GeoJSON encode, since it broadly aligns with the way the rest of the Z and M handling works already, but I've filed #188 to follow up on the GeoJSON compatibility stuff. I think I'm with you all of points 1-4—in particular, my preference would be to continue accepting "type": "LineStringZ"
for backward compatibility. Even though it's out of spec, it seems easy enough to avoid breaking in case somebody's relying on that behavior, and I don't think anyone's using Geo's parser as a check for whether a file is spec-compliant.
lib/geo/json/encoder.ex
Outdated
# GeoJSON does not allow "m", and does not recognize "LineStringZM" as | ||
# a type | ||
coordinates = Enum.map(coordinates, fn({x, y, z, _m}) -> [x, y, z] end) | ||
%{"type" => "LineString", "coordinates" => coordinates} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a fine compromise for compatibility. I wonder, though, whether it'll be surprising to folks that the m
value totally disappears. If people complain, we may want to do something like include the m
in the GeoJSON feature's properties
. That seems like a hack, though, so not something I'd do proactively.
@@ -1,12 +1,14 @@ | |||
defmodule Geo.WKB.Decoder do | |||
@moduledoc false | |||
|
|||
# these numbers can be referenced against postgis.git/doc/ZMSgeoms.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link is very much appreciated!
This PR adds support for LineStringZM, a Line String Z with a 4th value for
arbitrary metadata, like timestamps of measurements.
If this looks good to you, I'm happy to send more PRs adding 'M' variants of
other geo types (individually or batched, whatever your preference).
Kudos for an easy codebase to work with! I found it super straightforward to
implement this, even as a newcomer to GIS.