BUG: Exporting a GeoDataframe with column 'fid' to GeoPackage will delete that column
See original GitHub issueSteps:
-
Create a GeoDataframe with a column
'fid'
-
Export as a GeoPackage using
to_file()
-
Read the exported GeoPackage
Bug
The 'fid'
column should exist, but is missing.
Hunches
A scan of both the GeoPandas and the Fiona source code reveal no reason this bug should occur, so I suspect that it’s actually an issue with GDAL.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How to make necessary changes to Geodataframe to export ...
it is when I am trying to convert a geodataframe which has a string/object field with lists in it to shapefile. Do you...
Read more >Reading and Writing Files - GeoPandas
GeoDataFrames can be exported to many different standard formats using the geopandas.GeoDataFrame.to_file() method. For a full list of supported formats, type ...
Read more >Debugging GeoPandas GeoPackage IO - kuan butts
When you write to a GPKG file and then re-read the output file back in as a GeoDataFrame, a column named fid will...
Read more >OSMNX graph_from_gdfs KeyError: 'x' when converting a ...
Your problem appears to be that the u , v , and key columns in your edges GeoDataFrame contain null values, presumably from...
Read more >Writing to GeoPackage fails when two attributes have the ...
Here is the error message I get with geopandas/fiona (the ... so that the resulting GeoDataFrame contained two columns with the same name ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I forgot about this back then… but a new case where a solution for this would have made life a lot easier arrived…
So, in response to @jorisvandenbossche: I think your second option sounds great. It is safe backwards-compatibility wise, and as it is an index, it sounds reasonable that it would end up as the index of the resulting GeoDataFrame as well.
I also noticed
pyogrio.read_dataframe
supports it already (on the master branch, not yet in the released latest version), via a parameter called “fid_as_index=False”: https://pyogrio.readthedocs.io/en/latest/api.html#geopandas-integrationI am still a bit hesitant to always convert the
id
to an"fid"
column, when reading from a GeoPackage file: 1) it introduces GPKG specific code in geopandas and 2) it adds an additional column for all users, also when you actually don’t use/need it.But I certainly understand that, if you want access to the FID of the GeoPackage file, the current situation is quite annoying…
So some option I can think of:
Thoughts? Somebody interested in doing a PR for one of those?