3

@TeddyTedTed's answer is nice, however, I am looking for something more efficient.

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 with no deletion. I intend to sign an attribute that says if the layer overlaps.

Can you suggest the most beneficial way? Maybe a Virtual Layer?

So far I have in mind:

  • 2
    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? – ThingumaBob Mar 1 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 Mar 1 at 15:34
3

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

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)
  • What can be a problem? I am receiving the following issue ...line 18, in <module> layer.setSelectedFeatures(selectedSet) TypeError: an integer is required – Taras Mar 6 at 6:55
  • @Taras - Probably an issue with your layer? – Joseph Mar 6 at 10:18
  • Probably you are right! – Taras Mar 6 at 10:19
2

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
+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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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