0

I want to access the source fields(like in QGIS)

shp(right click properties->Source fields)

but in Geopandas.

The logic is to access the source fields (maybe export it in txt) of a valid shapefile and programmatically compare it with the corresponding(source fields) of a new similar shapefile, to test for differences that are not appropriate. For example (column names, data types, length of characters.)

1

You cannot do this in GeoPandas (apart from reading in the full file, and then you can see the column names and data types).
But if you only want the schema of fields (properties) and types, you can use fiona directly (what GeoPandas uses under the hood). For example:

>>> import geopandas
>>> import fiona
>>> path_shapefile = geopandas.datasets.get_path('nybb')

>>> with fiona.collection(path_shapefile) as source:
...     print(source.schema)     
{'geometry': 'Polygon', 'properties': OrderedDict([('BoroCode', 'int:4'), ('BoroName', 'str:32'), ('Shape_Leng', 'float:19.11'), ('Shape_Area', 'float:19.11')])}
  • How do you suggest to achieve the plan I described with the checking between valid and new shapefiles if they are identical in these specific details? – user122244 Jun 22 '18 at 14:04
  • You can compare the dict (or elements of it) that source.schema returns (for example you can compare the keys of the schema['properties'] subdict to compare the field names). For the rest it will depend on what "appropriate" is for your use case. – joris Jun 22 '18 at 14:51
  • appropriate here means to be completely the same properties – user122244 Jun 22 '18 at 14:54
  • If completely the same, you can compare the dictionaries for exact equality (schema1 == schema2) – joris Jun 22 '18 at 15:34

Your Answer

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

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