I am converting an excel sheet to .shp via pandas i.e. I have a dataframe with 150+ columns and ~900 records (increasing by about 50 every day), that I convert to geodataframe and export to shp:

output_data.to_file(filename, driver='ESRI Shapefile')

Saving this data to shp in Global Mapper creates a 3.5MB dbf

In QGIS, a 14MB dbf

Using Geopandas 6.5MB dbf

I've seen that the geodataframe has 15 decimal places for every numeric field, including whole numbers. Same thing for QGIS. Global Mapper's field lengths are equal to the lengthiest field in each column.

How can I keep geopandas from adding 15 decimals? I assume this is what bloats the filesize since I refactored some fields in QGIS and got a much smaller output dbf. The fields are also shorter in pandas df, before converting to geodf.

  • You may need to use some of the fiona options to specify a precision in the output shapefile. See fiona.readthedocs.io/en/stable/manual.html#writing-vector-data Does it have to be a shapefile? Can you save to a GeoPackage? – Spacedman Feb 13 at 17:37
  • thanks @gene I have tried that, but as soon as the df is written to dbf the trailing digits reappear – Andre Geo Feb 14 at 13:00
  • thanks @Spacedman unfortunately it has to be a shapefile. The only specification that I can see is defining a schema by passing a dict, which dictates the data types but not the length. Unless I'm missing something? – Andre Geo Feb 14 at 13:03
  • Section 1.6.2 shows how to set data type and length, eg "float:15.2" is a floating point number with two decimals points. What does ogrinfo show for the formats for your various shapefiles? – Spacedman Feb 14 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.