-
Notifications
You must be signed in to change notification settings - Fork 366
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
pyshp-2.2.0 test failure #2012
Comments
Actually this looks like a bug in pyshp-2.2.0. With pyshp-2.1.3 the test passes. |
So upon further investigation, pyshp-2.2.0 enforces the positive orientation of the outer polygon ring, while pyshp-2.1.3 does not. The |
I just noticed there's also the issue that depending on whether pyshp or fiona are used to read the shapefiles, the returned ring orientations will differ, as fiona won't reverse the orientation. Not sure what convention cartopy expects, but it might also something that needs to be solved by shapely (which deals with transforming the geometry from pyshp into a CC @QuLogic as Fedora cartopy maintainer. |
Yes, I commented on that commit; I'm still confused as to whether this change is intentional. |
The switch to enforcing ring orientation in pyshp 2.2 was indeed intentional and in an effort to conform to the new GeoJSON RFC7946 specification, where it is one of the requirements. In theory the switch should not have caused any types of issues, since the original 2008 GeoJSON specification did not say anything about ring orientation. The exception as evidenced in this issue is for test cases where expected coordinate sequences have to be made explicit. However, after reading more up on the GeoJSON RFC7946 spec, I have come to conclude that the next version pyshp will probably revert back to not enforcing ring orientation as before (instead keeping the rings in whichever orientation they were stored in the shapefile). I had not realized this before, but RFC7946 also requires that all coordinates must be in WGS84 coordinates, and some other rules about geometry splitting around the antimeridian. Supporting these requirements would then mean that pyshp would have to be dependent on Indeed, the reason fiona does not enforce ring orientation is that it relies on GDAL to generate the geojson, and the GDAL GeoJSON driver still uses the 2008 specification by default. Given the backwards incompatible changes, the consensus in the GDAL community appears to have been that the switch to RFC7946 should be manually set and should be "all-or-nothing". Since pyshp cannot reasonably be expected to support "all" of RFC7946, I think it's better to only support the 2008 GeoJSON spec and just make this clear in the docs. After all, the purpose of pyshp is not to generate perfectly valid geojson, but rather to have quick access to the geometry contents in a human-readable standard - for these purposes 2008 GeoJSON is sufficient enough. If anyone wants to generate RFC7946-valid GeoJSON for file-based storage or sending across the internet, the burden should then fall on the user or some third-party library to do the necessary coordinate projection, clipping, etc. While this means that cartopy's test error will disappear when I revert this in the next pyshp version, I do suspect this issue might come up again soon. As the only official standard, it's likely that RFC7946 will only become more widely used, and if GDAL makes RFC7946 the default in future versions then fiona will produce geojson which enforces ring orientation as pyshp 2.2 does, and the cartopy test will fail once again. Given this, maybe a more robust fix here is to enforce a particular ring orientation in the test itself? This might be as simple as sorting the rings before comparing them: |
Thanks for clarifying things @karimbahgat. |
This is only required in the RFC7946 GeoJSON specification, which it won't be possible to fully support in pyshp. Instead sticking to the original 2008 GeoJSON, keeping all rings in the same orientation as stored in the shapefile. More details at SciTools/cartopy#2012.
For info, this test should no longer fail for pyshp v2.3.0. Geojson ring orientation has now been reverted back to preserving the original shapefile ring orientation (not enforcing ring orientation based on exterior/interior). See a9ba72da52743850164185dd8db5fd821494fd11 for details. |
I'm building proj9 for fedora, and rebuilding cartopy against it yielded the following test failure:
The text was updated successfully, but these errors were encountered: