0

I have a GeoPackage that includes series of lines, each line corresponds to the itinerary of a person from point A to point B. I would like to know how to calculate the overlapping of lines (the superimposition has been made by the sna) and how to get to know which one are the most used itineraries.

I've already tried to use QChainage to get a heat map but I wondered if there was another way.

2
  • 1
    What's a "sna"? The School Nutrition Association? The ticker symbol of Snap-on Incorporated?
    – csk
    Nov 13, 2018 at 19:31
  • Depending on the setup of your data, this may help: gis.stackexchange.com/questions/295022/…
    – csk
    Nov 13, 2018 at 19:41

1 Answer 1

1

If you are familiar with PyQGIS you could do something like this (QGIS 3.4.1):

# 'lines' is a polyline vector layer with one empty attribute field. 
# It could have more fields but remember to adjust the field index 
# in the attributes dictionary - {feature_number:{field_index:attribute_value}}

l = QgsProject.instance().mapLayersByName('lines')[0]

feats = l.getFeatures()

count = []

for f in feats:
    l.selectByIds([f.id()])
    j = processing.run('native:saveselectedfeatures',{'INPUT':l,'OUTPUT':'memory:target_line'})
    processing.run('native:selectbylocation', {'INPUT':l,'PREDICATE':7,'INTERSECT':j['OUTPUT'],'METHOD':0})
    s = processing.run('native:saveselectedfeatures',{'INPUT':l,'OUTPUT':'memory:selection'})
    t = len(list(s['OUTPUT'].getFeatures()))
    r = {f.id():{0:t}}
    count.append(r)

l_prov = l.dataProvider()

for i in count:
    l_prov.changeAttributeValues(i)

intersect count

Bear in mind that it counts intersecting features, not number of intersections.

1
  • I'm glad I could help. Does it solve what you were asking?
    – Matt
    Nov 17, 2018 at 6:14

Your Answer

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

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