Geographic Information Systems Asked by qu4ntumrush on January 17, 2021
I’m working on a project regarding the coastline of Tampa Bay and over a long period I’ve edited a 2004 snapshot of the coastline from a line shapefile into a polygon shapefile representing the coastline in 1940.
Last night I had to make an inset map of the area and thought it would look better if I removed the rivers. To do that I copied the shapefile to C:UsersmeDownloads
(working folder is D:OneDriveFLGISBoundaries
) and removed the rivers of the original shapefile in ArcGIS Pro, which meant the edits were irreversible (I couldn’t copy the file within the map for some reason).
Now I need the copied, unedited shapefile, so I deleted the original shapefile and moved the copy back to its place. Now I can’t add it to any GIS program nor can I replace the data source of the original file. In QGIS it says "invalid data source"
and ArcGIS Pro says "layer's data source could not be changed"
or "failed to add data."
The last backup was made at the end of July and I have modified it slightly and backed up more recent variations (e.g. as a line shapefile or a polygon shapefile with lakes), so it’s not the end of the world. However, I would like to know what exactly corrupted it and how it is corrupted and whether it can be fixed. The linked ZIP includes the shapefile files (coast_1940) as well as the metadata for the original shapefile (coast_feb04).
https://drive.google.com/file/d/1UoOAbLg8bORz4XDEnGGb9SuOQ8yQ7efU/view?usp=sharing
Your shapefile is missing the .shx file, one of the three mandatory files (shp, dbf and shx).
You can regenerate it using pyshp
shp = "coast_1940" # NOTE no .shp extension
from shapefile import (Reader, Writer)
try: # Py2 (I haven't actually tested on python 2...)
from StringIO import StringIO as IO
except ImportError: # Py3
from io import BytesIO as IO
with IO() as shpio, IO() as dbfio: # Don't overwrite existing .shp, .dbf
with Reader(shp) as r, Writer(shp=shpio, dbf=dbfio, shx=shp+'.shx') as w:
w.fields = r.fields[1:] # skip first deletion field
for rec in r.iterShapeRecords():
w.record(*rec.record)
w.shape(rec.shape)
Here is a version I fixed with pyshp
As to why your .shx disappeared, I don't know. You may have forgotten to copy it or perhaps a sync/deletion issue arising from using a cloud storage (OneDrive) for GIS data.
Correct answer by user2856 on January 17, 2021
As pointed out in the comments and other answer, the problem with shapefiles is often that people miss some other mandatory files accompanying shapefile. (https://en.wikipedia.org/wiki/Shapefile)
Please note there is simple way to recreate shx since QGIS 3.12 - there is a native algorithm in QGIS to repair or create the *.shx file called 'Repair Shapefile' in processing toolbox. You can use this tool in general to deal with corrupted shapefiles in other ways.
I would also like to encourage you to start using some other modern format like OGC GeoPackage (GPKG) unless you are stacked with shapefile for legacy or other really important reasons.
Answered by Miro on January 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP