1

I have a shapefile I created with GeoPandas that I am unable to use in a 3rd party application. The problem seems to lie with differences in how integer fields are being interpreted vs a shapefile created in ArcGIS.

Detail on my specific problem can be found: https://github.com/Riverscapes/gcd/issues/402

Apparently Esri uses their own special-sauce for encoding DBFs, however, inclusion of the 'driver' kwarg, e.g.

gpd.to_file("my_file.shp", crs=crs, driver='ESRI Shapefile')

does not address my problem.

So perhaps I need to be using the 'schema' and/or 'mode' kwargs? However, there's not much info on how to implement these in the docs Can anyone direct me to deeper detail on gpd.to_file()?

The 3rd party app seems to be expecting whatever flavour gets created in (or exported from) ArcGIS. However, as freeware, the developers don't presently have resources to address the issue on the app side.

The only workaround I've found is to open the gpd-generated shapefile in Arc, add a new field to the attribute table as "short integer" (and only as short integer...detail here), and export from Arc.

I would like to skip the detour through Arc and go directly from GeoPandas to the 3rd party app.

0

1 Answer 1

1

Based on this answer, you can define a schema:

import geopandas as gpd

df = gpd.read_file('test.shp')

# Add a couple of fields that don't exist already
df['shortint'] = 1
df['longint'] = 2

# Get geopandas to populate a schema dict so we don't have to build it from scratch
schema = gpd.io.file.infer_schema(df)
schema['properties']['shortint'] = 'int32:4'  # 'Short integer' format
schema['properties']['longint'] = 'int32:10'  # 'Long integer' format

df.to_file('test2.shp', schema=schema)

As the fields look in ArcGIS:

enter image description here

And in QGIS

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.