[GIS] Getting difference between two versions of Shapefile using QGIS

fields-attributesqgisshapefile

I have two shapefiles that are the same in terms of the type of information they contain (same attribute fields). One is essentially an updated version of the other, so the newer version contains all the data of the earlier version plus more.

Each data entry has a unique id field. I am looking for a way to essentially 'subtract' the older shapefile from the newer one. This cannot be a spatial operation, it must be based on the attributes. I use primarily OGR and QGIS.

Any ideas on how to do something like this?

Best Answer

I assume a situation like below:

  1. When we visited last week, there were only three (3) schools. (Layer school_layer_1)
  2. However, we found five (5) schools this week. (Layer school_layer_2)

And we want to know which schools are newly built.

enter image description here

Then we can use a Virtual Layer to find out suspicious schools.

enter image description here

The SQL query is:

SELECT * FROM school_layer_2
WHERE id
IN (
    SELECT id FROM school_layer_2
    EXCEPT
    SELECT id FROM school_layer_1
   )

The produced Virtual Layer (green circles) is a point layer with the records of difference between school_layer_1 and school_layer_2.