TransWikia.com

Checking what changed inside updated shapefile

Geographic Information Systems Asked on February 11, 2021

I am using different shapefiles from open data in Switzerland. They have just updated the whole set. My question is: how to compared two layers (new and old version)? I would like to know the differences in geometry, as well as attributes. In the data there are points, lines and polygons and some of the sets contains a big amount of features (more than 300 000 elements).

I have already checked all the simillar questions, but they all focus on creating the third layer with differences or particular layer example.

What I want to know is just what has been changed.

I am working with QGIS 2.14.3 and i am familiar with Python.

3 Answers

It is not with QGIS or PyQGIS, but if you know Python and the modules Pandas and GeoPandas (Python 2.7 and 3.x), it is easy using the solution of Outputting difference in two pandas dataframes side by side - highlighting the difference if the two shapefiles have the same schema and the same record indexes

import geopandas as gp
# convert shapefiles to GeoDataFrame
old = gp.GeoDataFrame.from_file("shape_old.shp")
new = gp.GeoDataFrame.from_file("shape_new.shp")
old

enter image description here

new  

enter image description here

import numpy as np
import pandas as pd
# which entries have changed
ne_stacked = (old != new).stack()
changed = ne_stacked[ne_stacked]
changed.index.names = ['id', 'col']
print changed
id  col     
0   geometry    True
    test        True
1   ensayo      True
2   ensayo      True
    geometry    True

Compare the columns which has been changed.

difference_locations = np.where(old != new)
changed_from = old.values[difference_locations]
changed_to = new.values[difference_locations]
pd.DataFrame({'from': changed_from, 'to': changed_to}, index=changed.index)

enter image description here

But with more than 300 000 elements...

Answered by gene on February 11, 2021

Maybe a solution is to join the attributes of the same feature (after and before the changes) into one table (you can name added attributes differently) so you can export it to excel and do your math to find differences, %, and so on.

You may even don't need to join those attributes. Just export the attributes of all the features and work the differences in Excel.

Answered by Andreu Amoros on February 11, 2021

There is a new tool which was added in QGIS 3.12 called "Detect dataset changes" that does exactly what you want. It accepts any geometry type including line. The tool

Compares two vector layers, and determines which features are unchanged, added or deleted between the two. It is designed for comparing two different versions of the same dataset.

Original line:

enter image description here

Modified line:

enter image description here

Changes happened:

enter image description here

Please refer to the help above for more detailed information.

Information in the changelog for QGIS 3.12: https://qgis.org/en/site/forusers/visualchangelog312/#feature-add-new-algorithm-detect-dataset-changes

Answered by ahmadhanb on February 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP