3

I am looking to measure the impact of urban green on pedestrian route choice, and in that connection I want to create a new field within a line layer that counts how many trees exist in a radius of 10 meters from the center of each feature in the line layer. (could also be within the radius of 10 meters from the two extremes of the line, doesn't matter so much).

I am working in QGIS 3.4.13-Madeira.

Am at a total loss as to how to do this, and can't seem to find any articles that might point me in the right direction.

urban green

(the points are trees)

2
  • Well, you don't need to limit this to any vertice based radius; it's trivial to get a true line proximity count. However, it is crucial for us to know what software you are using; please edit the tags of your question to include it, and remember to limit it to a single piece (or stack) of software (i.e. not QGIS + ArcGiS)
    – geozelot
    Commented Sep 17, 2020 at 8:10
  • Thanks for the tip, I've now done so! Commented Sep 17, 2020 at 9:44

1 Answer 1

5

Assuming your roads layer has no respective field yet:

  • mark the layer and open the Field Calculator
    • toggle Create a new field
    • choose an Output field name
    • select Output field type: Whole number (integer)
    • paste this expression:
      aggregate( '<tree_layer_name>', 'count', '', distance( geometry( @parent ), $geometry ) <= <dist> )

      with <tree_layer_name> replaced with the actual name of the tree layer, and <dist> replaced with the search radius around the line feature

      Note:
      The <dist> value will be treated as units of CRS, meaning that, if your layers are referenced in EPSG:4326 (or any geographic reference), these will be degrees. For it to be treated as meters, make sure your layers are projected in a suitable metric projection!
3
  • Great, that worked - thanks heaps! Commented Sep 28, 2020 at 7:36
  • Just a question on the mechanics at work - does it count within the radius of the endpoints, or from the radius of each point on the line? Commented Sep 28, 2020 at 7:37
  • @Klaus_Asbjorn Glad it helped. It's the latter: a dot product distance between a line and a point, extended for a finite segment. If it solved your question consider upvoting and/or accepting the answer, that'd be nice ,)
    – geozelot
    Commented Sep 28, 2020 at 7:59

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.