[GIS] Recover lost polygons from shapefile in QGIS

editingpolygonqgisshapefile

I've committed a newbie error it seems in GQIS with a polygon shapefile.

I wanted to remove about 15 of the 210 polygons, and put those 15 in another file.

I made a duplicate of the polygon shapefile.
In the duplicate file I removed everything from the attributes table, started cutting and pasting lines from the original to duplicate file attribute tables.
I saved the edits in duplicate with the 15 polygons, gave it a new name.
I tried to save the edits in the original now with 195 polygons, wouldn't let me.
I made another copy of that original, but it only had the 15 removed polygons.
Started closing error messages, thinking it would allow me to save.
I tried closing edits of the original, I selected discard changes. All remaining 195 polygons dissapeared, all 15 polygons removed are now present.
Closed project without saving changes, but alas the shapefile had been saved. The cpg, prj and qpg files seem unchanged with the original date, so I copied those for safekeeping. Loading the project again it comes back with the 195 polygons missing (about 8 hours work).

Is this a lost cause or is there a way to recover them?

Best Answer

Duplicating a layer is not the same as making a copy of the source data.

Duplicating a layer

When you duplicate a layer, QGIS creates a second link to the same source file. Any edits you make to the duplicate layer are made to the source file. Any layers that link to that same source file will also have those changes.

To duplicate a layer, right click on the layer name in the layer panel > duplicate layer.

enter image description here

In newer versions of QGIS (eg 3.4), a warning will pop up which says,

Layer duplication complete: Note that it's using the same data source.

enter image description here

The "duplicate" layer will be called "original_layer_name copy."


Making a copy of a layer, AKA backing up your data

In order to actually back up the source data, you must create a copy of the source file.

Right click on the layer name in the layer panel > Export > Save features as...

enter image description here

enter image description here


If you duplicated your layer instead of backing up the source data, then you're stuck with the results of any edits you made to the duplicate layer. Your 195 deleted polygons are gone. I'm genuinely sorry.

Every GIS user learns this lesson one way or another. The lucky ones were taught this by a more experienced GIS user, or we learned it by losing only a small amount of data. Unfortunately you learned it in a particularly painful way, by losing a large amount of unique data.

Related Question