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
BUG: to_file ignores crs without any info #2387
Comments
I digged a bit deeper into this and using from osgeo import ogr, osr
crs_wkt = 'PROJCRS["unknown",BASEGEOGCRS["unknown",DATUM["unknown",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1,ID["EPSG",9001]]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8901]]],CONVERSION["unknown",METHOD["Equidistant Cylindrical",ID["EPSG",1028]],PARAMETER["Latitude of 1st standard parallel",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8823]],PARAMETER["Longitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["False easting",0,LENGTHUNIT["unknown",111319.490793274],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["unknown",111319.490793274],ID["EPSG",8807]]],CS[Cartesian,3],AXIS["(E)",east,ORDER[1],LENGTHUNIT["unknown",111319.490793274]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["unknown",111319.490793274]],AXIS["ellipsoidal height (h)",up,ORDER[3],LENGTHUNIT["metre",1,ID["EPSG",9001]]]]'
spatialRef = osr.SpatialReference()
spatialRef.ImportFromWkt(crs_wkt)
spatialRef.MorphToESRI()
file = open(r"C:\Users\rquast\Desktop\_delete\testshp\test.prj", 'w')
file.write(spatialRef.ExportToWkt())
file.write(m.crs_plot.to_wkt())
file.close() results in >>> ERROR 1: PROJ: proj_as_wkt: Projected 3D CRS can only be exported since WKT2:2019 |
This may be a helpful reference: https://pyproj4.github.io/pyproj/stable/crs_compatibility.html#osgeo-gdal spatialRef.ExportToWkt(["FORMAT=WKT2_2018"]) |
Hi, thanks for the report! I believe that this is caused by some behaviour of PROJ, that instead of raising when trying to export CRS to WKT1 GDAL format just silently returns None (see also pyproj4/pyproj#1036). When trying to save it with pyogrio.write_dataframe(gdf, 'tst.shp')
UserWarning: 'crs' was not provided. The output dataset will not have projection information defined and may not be usable in other systems. Even that is not entirely clear because the CRS was provided, it is just incompatible. Because we do this conversion on our side, we should add a check and warn about that. Around here: geopandas/geopandas/io/file.py Lines 392 to 395 in 51864ac
|
Ah, yes. Thanks! |
I actually isn't that easy as with GDAL >= 3.0, we use |
Hey, thanks for the follow up on this! I'm really no expert on this but I think the problem might be that in pyproj there's actually only As a general comment, I think a warning should go to |
Ideally yes, but right now we don't know this. We would need |
Related: Toblerity/Fiona#979 |
Related: #1697 |
From: Toblerity/Fiona#977 (comment) Write: with fiona.Env(OSR_WKT_FORMAT="WKT2_2018"), fiona.open("./test.shp", "w", driver="ESRI Shapefile", schema=schema, crs=target_crs) as collection:
collection.write(feature): Read: with fiona.Env(OSR_WKT_FORMAT="WKT2_2018"), fiona.open("./test.shp") as collection:
print(collection.crs) |
geopandas version: #1697 (comment) Write: with fiona.Env(OSR_WKT_FORMAT="WKT2_2018"):
df.to_file('./test.shp') Read: with fiona.Env(OSR_WKT_FORMAT="WKT2_2018"):
gdf = geopandas.read_file("./test.shp") |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of geopandas.
(optional) I have confirmed this bug exists on the main branch of geopandas.
Code Sample, a copy-pastable example
Problem description
I guess the general problem is obvious...
The reason why I think this is problematic is because geopandas is perfectly happy with the crs (reprojections etc. work as expected) so one would expect that saving the GeoDataFrame should work as well.
Expected Output
a
.proj
file with the crs alongside the other shapefiles or at least a warning that the crs was not exported.Output of
geopandas.show_versions()
SYSTEM INFO
python : 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 05:37:49) [MSC v.1916 64 bit (AMD64)]
executable : D:\miniconda\envs\rt1\python.exe
machine : Windows-10-10.0.17763-SP0
GEOS, GDAL, PROJ INFO
GEOS : None
GEOS lib : None
GDAL : 3.4.0
GDAL data dir: None
PROJ : 8.2.0
PROJ data dir: D:\miniconda\envs\rt1\Library\share\proj
PYTHON DEPENDENCIES
geopandas : 0.10.2
pandas : 1.3.5
fiona : 1.8.20
numpy : 1.21.5
shapely : 1.8.0
rtree : 0.9.7
pyproj : 3.2.1
matplotlib : 3.5.1
mapclassify: 2.4.3
geopy : None
psycopg2 : None
geoalchemy2: None
pyarrow : None
pygeos : None
The text was updated successfully, but these errors were encountered: