4

I am working on a public transport network in one shapefile (polyline type) in QGIS 2.18.

Certain bus routes share the same paths, means that one line-part can repeat more than once. It always has the same identical geometry.

For instance, if I select a feature with 'Identify Features' I will have three outcomes in the Identify results table, see an image below.

Tranport_network_Example

I want to select all the features that share the same geometry and further process it. I intend to sign an attribute that says if the layer overlaps.

Can you suggest the most beneficial way?

So far I have tried:

2
  • 3
    are those geometries always in fact identical? can they also share only parts of each other? can they have different orientations (likely for reversed directions)? do you want to delete them (did you try Vector general | Delete duplicate geometries - you could compare the 'cleaned' result with the original)? or how do you intent to handle duplicates?
    – geozelot
    Commented Mar 1, 2019 at 15:24
  • Make sure your Geometries are Single Part. I would convert your Polylines to Centroid, easy to compare Points. This removes the direction aspect of a Polyline.
    – klewis
    Commented Mar 1, 2019 at 15:34

4 Answers 4

4

Duplicate the layer.

In the processing toolbox use 'Join attributes by location (summary)'.

Use the original and the duplicate layers for the input and join layers.

Select 'equals' as the geometry predicate.

Run.

The attribute table of the resulting layer will have a field in it called "YourIDField_count". Where this is greater than 1 is where you have duplicate geometries.

Now select everything in the joined layer where the count is over 1.

Use these to select by location (geom predicate = equals) from the original layer.

2
  • In QGIS 3.30.1, no field called "YourIDField_count" appears in the attribute table of the resulting layer.
    – Catlike
    Commented Apr 16, 2023 at 14:17
  • I had a similar same problem as @Catlike. The problem for me was that I had an id field which was not filled in. The following is a solution. This also makes it that you don't get 50 new fields: - 'Fields to summarise': just pick one field that does have a value for all features (or to be safe use field calculator to fill in a value in a new field) - 'Summaries to calculate': count You will now have <the field you chose>_count in your output layer. When it is above 1, you will have duplicates.
    – Silke
    Commented Apr 26, 2023 at 11:11
4

Use the geometry checker plugin to check for duplicates

enter image description here

The Result tab will display a table of duplicate features. You can select features on the map by selecting them in the Result table.

enter image description here

If you choose the option "Fix selected errors, prompt for resolution method" you get a popup like this that allows you to choose to remove duplicates or not.

enter image description here

1
  • 1
    In QGIS 3.30.1, the process returned no "errors" when in fact I know there are duplicates. (One layer was exported from the other and has some identical geometry/geography with the original.)
    – Catlike
    Commented Apr 16, 2023 at 14:42
3
+50

You can use the Topology Checker Panel and define the rule (your road layer should not have duplicates.)

enter image description here

After defining your rule, you press Ok and you run.

The Tool will give you their Feature ID and if you click to a particular line it will zoom to the layer, for further investigation. enter image description here

3

You could modify the Delete duplicate geometries script from QGIS 2.18 where once duplicated features are found which have the exact same geometry, they are stored in a list along with the original feature. You could then select all these features:

layer = iface.activeLayer()
features = layer.getFeatures()
geoms = dict()
for current, f in enumerate(features):
    geoms[f.id()] = QgsGeometry(f.geometry())

cleaned = dict(geoms)
selectedSet = []

for i, g in geoms.iteritems():
    for j in cleaned.keys():
        if g.isGeosEqual(cleaned[j]):
            if i == j or i not in cleaned:
                continue
            if g.isGeosEqual(cleaned[j]):
                selectedSet.extend([g, j])

layer.setSelectedFeatures(selectedSet)
4
  • What can be a problem? I am receiving the following issue ...line 18, in <module> layer.setSelectedFeatures(selectedSet) TypeError: an integer is required
    – Taras
    Commented Mar 6, 2019 at 6:55
  • @Taras - Probably an issue with your layer?
    – Joseph
    Commented Mar 6, 2019 at 10:18
  • Probably you are right!
    – Taras
    Commented Mar 6, 2019 at 10:19
  • I copied this script and ran it. It returned both entire routes, not the segments that overlap.
    – Catlike
    Commented Apr 16, 2023 at 15:03

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.