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
CRS Axis Order issues with 1.8.9 #816
Comments
@snowman2 I don't seem to be able to replicate this with just a fiona example:
with the latest fiona:
|
@jorisvandenbossche the Longitude and Latitude are swapped like the example I have above for the latest fiona in your WKT string. So, that seems consistent with this issue. |
Ah, indeed, I was only looking at the presence/absence of the |
Yes, that is indeed troubling. The WKT is mangled and misleading. |
So but do you have a reproducible example for the output you showed above? (where the authority was removed) |
Not sure. I may have deleted the environment. |
Ah, and now I see why I thought I couldn't replicate it. Because for another file, I actually get the "correct" axis order (the one that matches the EPSG code):
This still gives latitude/longitude order in the CRS. So it seems to depend on the actual source representation of the CRS. In case of the above example, it is a WKT in a |
@jorisvandenbossche, you are correct. Inside the |
@snowman2 as far as I know we must, for EPSG:4326 and some other CRS, expect the WKT reported by Fiona 1.8.9 & GDAL 3.0 to report lat/long order at the same time the Fiona API returns long/lat coordinates. GDALSetAxisMappingStrategy is what Fiona uses to preserve the existing coordinate order but I don't think there was ever any intent for that function to modify the WKT representation of the CRS. |
That is great news! I guess I assumed it did since it was in the I think this is resolved then. Thanks for the clarification! |
I still have a bunch of questions, though, related to this.
|
And the plot thickens: >>> import fiona
>>> import geopandas
>>> schema = geopandas.io.file.infer_schema(geopandas.read_file(geopandas.datasets.get_path('nybb')))
>>> _CRS = (
... 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,'
... 'AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],'
... 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],'
... 'UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],'
... 'AXIS["Longitude",EAST],AXIS["Latitude",NORTH]]'
... )
>>> fds = fiona.open("test.geojson", driver="GeoJSON", mode='w', schema=schema, crs_wkt=_CRS)
>>> fds.close()
>>> with fiona.open("test.geojson") as c:
... print(c.crs_wkt)
...
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
>>> fds = fiona.open("test.geojson", driver="GeoJSON", mode='w', schema=schema, crs="EPSG:4326")
>>> fds.close()
>>> with fiona.open("test.geojson") as c:
... print(c.crs_wkt)
...
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Longitude",EAST],AXIS["Latitude",NORTH]]
>>> fds = fiona.open("test.geojson", driver="GeoJSON", mode='w', schema=schema, crs_wkt="EPSG:4326")
>>> fds.close()
>>> with fiona.open("test.geojson") as c:
... print(c.crs_wkt)
...
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Longitude",EAST],AXIS["Latitude",NORTH]] So, it seems the WKT representation with the axis order swapped is not honored and always produces the lat/lon order while the EPSG code always produces the lon/lat order when reading back in. |
This is really funny, with the GeoJSON driver:
|
@snowman2 if you look at the geojson file for the first case, you will see that there was no crs information written (so in the case you passed a WKT to For passing "urn:ogc:def:crs:OGC:1.3:CRS84", it's the same. The resulting geojson file does not include crs information. So it seems that such urn string is also not recognized as input crs description. So as an additional issue, it seems that the input to
also generates a geojson file with no crs information without any error or warning. |
I opened #823 as a specific issue for the invalid The strange thing is though, that
|
According to the GeoJSON standard (RFC7946 (August 2016)) all coordinates are in the urn:ogc:def:crs:OGC::CRS84 coordinate system. As previous draft versions of the GeoJSON standard supported coordinate systems, it could be that previous versions of the gdal GeoJSON driver supported custom coordinate systems. |
@rbuffat yes, I know that the latest spec only allows CRS84, while the older spec (http://geojson.org/geojson-spec.html) includes a specification for a CRS description. As an example, with current fiona, I can perfectly write a different CRS (using the variables from above)
and then the resulting geojson file includes this:
Now, regardless of which is spec is being used:
|
Correcting myself here: in fact, when forcing the new spec (passing So it is only when "urn:ogc:def:crs:OGC:1.3:CRS84" is written into the file, you get back a WKT that is not EPSG:4326 (but the proj4 string still says it is!), and you have this roundtrip problem. |
I think this is an issue with GDAL then. I would think with the new emphasis on axis order, the GeoJSON should differentiate between CRS84 and EPSG:4326 when reading and writing the CRS without the new spec activated. |
I am not sure it is up to GDAL to change CRS84 into EPSG:4326. While it is fiona that knows that it is always using x/y (lon/lat) order and thus already ignoring the axis order (using the traditional GIS axis order). What do you think about Fiona returning EPSG:4326 instead of CRS84 for geojson format? |
What do you think about Fiona returning EPSG:4326 instead of CRS84 for geojson format? Overall, this is my take on it: geopandas/geopandas#1101 (comment) But, I also think bringing this question to the GDAL devs would be a good idea as well. I think it would be good for Fiona 2+ to take axis order into consideration. Possibly add the option for users to toggle on/off the axis order stuff? |
Opened issue: OSGeo/gdal#2035 |
@snowman2 the GeoJSON spec, RFC 7946, says the CRS is the OGC's CRS84 (which is explicitly long/lat order). FIona shouldn't go against that. |
I agree 💯 |
Well, Fiona (or GDAL) does go against it. |
@snowman2 thanks for opening that issue! |
Not a problem! Looks like EPSG:4326 is the winner in this scenario and the fix is in GDAL, so no change needed in Fiona. |
Problem Description
When reading in: https://raw.githubusercontent.com/geopandas/geopandas/master/geopandas/tests/data/overlay/overlap/df1_df2_overlap-union.geojson
With previous versions of Fiona, the WKT string was read in as:
However, currently (1.8.9) it is read in as:
Everything is mostly the same except for the axis order at the end.
I believe this is due to this line:
Fiona/fiona/_crs.pyx
Line 65 in 960568d
This is problematic for a couple of reasons:
Recommended Solution
Add an
always_xy
flag tocrs_to_wkt()
and only use it when creating a CRS to be used in the transformation. It would also be a good idea to add analways_xy
flag to the transformation operations for the case where the user modified the underlying data to match the axis order specified in the CRS. For Fiona 1.8.x, thealways_xy
flag could be omitted from the transformation operations and just default toalways_xy=True
incrs_to_wkt()
Thoughts?
The text was updated successfully, but these errors were encountered: