2

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:\Users\me\Downloads (working folder is D:\OneDrive\FLGIS\Boundaries) 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

5
  • Now anyone can edit it Sep 14 '20 at 21:24
  • Any speculation as to what corrupted a datafile is just that, speculation. Even if you provided a detailed list of every operation performed, all that could be generated would be places where the file could have been corrupted (ignoring the most likely cause, physical media failure).
    – Vince
    Sep 14 '20 at 21:30
  • Usually the problem with shp files is that people forget to copy also the accompanying files (dbf, shx), maybe that might be the case? Anyway as @Vince mentioned, we can't really help here even though you have put a lot of effort into explaining your situation, sorry.
    – Miro
    Sep 15 '20 at 13:00
  • In your zip file there is actually missing shx file which is mandatory. en.wikipedia.org/wiki/Shapefile
    – Miro
    Sep 15 '20 at 13:08
  • 2
    I would add that not representing a feature on a map is generally better done by symbology or filtering rather than using an edited copy of the data....
    – J.R
    Sep 15 '20 at 13:39
4

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

enter image description here

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.

1
  • Thank you, that was the only problem. It's missing on my end. Sep 15 '20 at 22:32
4

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.

1
  • yer they should deprecate shapefiles formally.
    – nr_aus
    Aug 13 '21 at 0:41

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.