-
-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Faster ring orientation checks, enforce geojson output ring orientation
- Loading branch information
1 parent
103bad0
commit 298d981
Showing
2 changed files
with
84 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
298d981
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.
While the description says it's for enforcing GeoJSON output ring orientation, this seems to have an effect on reading shapefiles. Is that an intended change?
298d981
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.
You're right, that is actually what I meant, it enforces ring orientation in the output when creating a geojson, ie reading a shapefile to geojson. Previously I didn't do so, since geojson does not strictly require a particular ring orientation for outer/inner rings, it only recommends it. This commit enforced the recommended orientations.
298d981
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.
Sorry, I'm still a bit confused; I'm not using any GeoJSON. All I did was read a shapefile and look at it from the Python classes, and now the orientation is flipped. Are you saying pyshp classes are internally GeoJSON?
298d981
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 changes to ring orientation does not touch any of the code defining how a shapefile is read from file. Internally each shape is read into a
Shape
class with atype
, a flat list ofpoints
and a flat list ofparts
. If you're reading the same shapefile before and after this commit and inspect theShape
contents they should be exactly the same and in the same order (egsf.shape(0).points
). The enforced ring orientation only applies when reading a shapefile and then converting from the internal shape structure to a geojson representation/dict (i.e. when calling the geo_interface property), or the opposite when writing a shapefile and adding a shape based on a geojson dict (i.e.sf.shape({'type':'Point', 'coordinates':[0,0]})
). So I suspect the way you are "looking at" or inspecting the shape contents involves converting to geojson, eg via the__geo_interface__
attribute or some external library? The new code should at any rate be the "correct" orientation according to the geojson specification:Hope this makes sense. Are there any unforeseen consequences of the new enforcement of ring orientation for your application?
298d981
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.
It breaks a test in Cartopy: SciTools/cartopy#2012 We don't directly use
__geo_interface__
, but I think this comes up implicitly via conversion to shapely?It doesn't break any plots, so I think this is still safe. However, as noted in the issue, the result is now different from reading with Fiona, which could be annoying.
298d981
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.
Yes, that's likely what's happening, shapely using the geo interface to convert to shapely geometry. I added a detailed answer and possible solution in SciTools/cartopy#2012. In short, while this commit produces correct ring orientation according to the newest RFC7946 GeoJSON spec, the results are different because fiona/GDAL still use 2008 GeoJSON. After reading up on the RFC7946 specification in more detail, the required changes are so extensive that a complete shift to the new standard would be beyond the scope of pyshp. So the next version will likely switch back to not enforcing ring orientation in accordance with 2008 GeoJSON.