1

Can QGIS show the differences between two sets of polygons?

A map is filled completely with adjacent object geometries, so there are no gaps or overlaps. An object could be a street or a house.

You can change the map by providing a set of changes of object geometries (in an XML file). After applying the changes, the map should not contain holes/gaps or overlaps.

To make a change to an object's geometry on the map, first, the "current" geometry (that is on the map) is given, then the change in the geometry as a "new" geometry.

There are 3 types of changes:

  1. A change consists of a new object with only a "new" geometry;
  2. A change has a only "current" geometry and no "new" geometry, so indicating is will be removed.
  3. A change has a "current" geometry and a (changed) "new" geometry.

Example: an error is introduced while splitting 1 object into 2 parts.

  • Object 1: replace 'current' 4x3 meter geometry with a 'new' 2x3 meter geometry;
  • Ojbect 2: a 'new' object geometry is 1x3 meter geometry.

This set of changes introduces a hole in the map of 1x3 meter. See in this picture: enter image description here

Question: How to show any gaps and overlaps of the polygons of the "current" and "new" situation in a .gml file using QGIS?

In other words: let Qgis show the differences between the current set of polygons and the new set of polygons.

Sample file

I cannot share original files. Having not many means at this spot, I still tried to create a sample file. I could not validate it in qgis at this location.

Sample change file

This set of 3 changes will split object 123 in half. Object 124 will replace only a small part of the original 123 geometry. Object 125 will overlap partly with the new geometry of object 123.

So this change would introduce 2 errors: there will be a gap between 125 and 124. Object 125 also overlaps with the new geometry of object 123.

Another simplified example file.

The structure of a simplified change file is:

Sample file structure

Update: Some ideas

Because the map has no overlaps or gaps we know the current geometries are correct. A good baseline. To find any gaps introduced by the new geometries, could we make a union of all current objects and substract all new geometries? Additionally, could we make a union of the new geometries and subtract the current geometries? Ok, we should add the intersections between new geometries as errors.

Background info:

Because the existing huge map doesn't have holes/overlaps, I only want QGIS to check 1 set of changes at any time.

The simplified objects have a GML geometry and two attributes: id + current/new indication.

There is a process validating any sets of changes. On successful validation, the set of changes is applied to the map. On validation errors, the error messages are specified.

To improve the analysis of errors, I would like to import one set of changes to qgis, so qgis will show any errors visually. So, in the above example, QGIS will mark the hole on the map. The geographic data is stored in GML format.

7
  • Do I understand correctly: You have an xml file saved on your hard drive, it causes errors and you just want to find holes and intersections in this file? If so, then I need to look at the content of your xml. How is your geographic data stored? Commented Aug 31, 2023 at 10:59
  • The geographic data is in gml format. The original file is eg in citigml format. I preprocess the file, export it so it contains in essence a very simple format with per object being the id, the gml, the current/new indication and the termination date. I can drag the file into a new Qgis layer and I can see the geometries. I can categorize on current/new and I see all current or new geometries.
    – tm1701
    Commented Aug 31, 2023 at 14:45
  • 2
    It seems to me that you have complicated your question, a lot of unnecessary details, people do not understand your need. Your question should look something like this: How to find gaps and overlaps between polygons in a .gml file using QGIS? An example of your file and your wish for gaps and overlaps to be displayed graphically. Sorry for the advice, but I recommend that you redo your question in this way, then you will probably get several answers on how to do this, provide information about your file and a screen shot with objects. Commented Aug 31, 2023 at 21:12
  • 1
    Rethinking the question again I simplified it. Thanks for challenging the question. See eg the title and rephrasing the question. And simplified the data!
    – tm1701
    Commented Sep 1, 2023 at 7:51
  • The current and new geometries are both stored in the same GML file? It would likely help to include a sample of your data to give a clearer picture of what you are working with. If your data are sensitive you could make a small mock sample of 2 or 3 situations.
    – Matt
    Commented Sep 1, 2023 at 11:08

1 Answer 1

3
+50

I made a style for displaying gaps and intersections. It uses a QGIS expression to find two geometries that have the same "id" field value and "type" field value = 'new'. The intersection or gap between these two geometries is then obtained as a new geometry that is displayed on the map. enter image description here

You can download the style and the gml file I created from google drive. Open the GML file in QGIS and apply a style to it.

Style Explanation

1. Rule for displaying gaps

First we combine two geometries that have the same "id" field value and "type" field value = 'new' using the combine function, then we subtract this combined geometry from the same combined geometry wrapped in convex_hull.

with_variable('combine_geom', 
combine(geometry(get_feature(@layer, map('id', attribute('id'),'type','new'))), $geometry),
difference(convex_hull(@combine_geom), @combine_geom))

enter image description here

2. Rule for displaying intersections

Here we get the feature geometry that has the same "id" field value as the current feature and "type" field value = 'new'. Then we get the intersection of the geometries of these two features, it will be displayed on the map. Unfortunately, I myself do not understand how the overlaps function works here. But without it, the result is not correct.

with_variable('new_geom_2', 
geometry(get_feature(@layer, map('id', attribute('id'),'type','new'))),
if (overlaps(@new_geom_2, $geometry),
intersection(@new_geom_2, $geometry),
null))

enter image description here

3. Turn on symbol levels

We turn on the display levels for the rules so that gaps and intersections are not hidden by ordinary objects. We set our gaps and intersections to a value greater than the rest of the objects so that the gaps and intersections are on top. enter image description here

10
  • Thank you for your time, helping me to get the question improved and this answer.
    – tm1701
    Commented Sep 2, 2023 at 7:32
  • Thank you again. I studied your data. Please check the rules for the 3 change types. One change consists of a current (or old situation) and a new geometry. An unique object (with 1 I'd) can't have more than one 'new' situation. See the given example that displays a gap. An overlap example would be to add a third (new) object that is larger than the missing 1x3 part.
    – tm1701
    Commented Sep 2, 2023 at 7:54
  • What do you mean by "current (or old situation)"? I don't understand what "situation" means in this context? Commented Sep 2, 2023 at 8:46
  • 1
    So far, I see that you just have a set of objects between which you want to find gaps and intersections, right? Some of these objects are new, but why does it matter? Commented Sep 2, 2023 at 10:46
  • 1
    Regarding the "some ideas" paragraph, I can tell you that yes we can. We can union and subtract any geometries. This can be done with the Processing Toolbox, pyqgis scripts, or QGIS expressions and styles like in my answer. Commented Sep 2, 2023 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.