In my QGIS project of American railroads, using USGS Base Topo Layer and shapefiles giving railroad details as of 2015, I have used the Python-3 pyshp library to edit the dbf database, adding some fields.

After writing out the edited shapefile with pyshp.Writer QGIS rejects my new shapefile as invalid, without any pointer as to the reason of rejection.

How can I check the integrity of a processed shapefile, preferably with Python ?

I use QGIS-3.14.11-Madeira, pyshp-1.1.12 and Python-3.6

  • You can try checking with ogrinfo but if QGIS says no then it is probably broken. OGR might give more error messages though
    – Ian Turton
    Jan 27 at 16:03
  • It is possible that you created a shapefile with invalid geometries (records without geometry or visa versa). Maybe some help here although this is a QGIS solution. qgistutorials.com/en/docs/3/handling_invalid_geometries.html. Have you tried opening just the DBF file in Access or Base? Maybe you created columns with invalid names in the attribute table? This would likely throw errors but those errors may have been passed over depending on your code. Can you post your code?
    – GBG
    Jan 27 at 16:56
  • @Ian Turton: ogrinfo strangely says open <shapefile> using driver "ESRI Shapefile" successful. Nothing else. Yet QGIS rejects and removes it from my project. When I use another version, also edited, that loads OK, so probably indeed my fault at editing. Jan 28 at 17:58

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.