3

I would like to find out the average distance from high schools (represented as a point in QGIS) to libraries (represented as another point in QGIS) in New York's 32 districts.

I have already calculated the distance to nearest library for each individual high school, but I need the result to be averaged at the district level. in other words, the result should be something like: "in district 5, the average distance between a high school and a library is 2 miles".

Is there any way to do this without manually calculating the average distance for each district, plotting this average into a table, and joining this table to the vector layer for districts?

Vince
  • 20,017
  • 15
  • 45
  • 64
ray
  • 31
  • 1
  • 1
    Is there a chance you have ArcGIS with an advanced license? In that software I would generate a near table then use summary statistics to find the average (mean) distance as the crow flies. There could be a QGIS equivalent https://gis.stackexchange.com/questions/168120/what-qgis-tool-or-plugin-is-equivalent-to-the-esri-near-tool and https://gis.stackexchange.com/questions/126639/calculating-all-distances-from-single-points-to-multiple-polygons could both be helpful, and for statistics https://gis.stackexchange.com/questions/266303/what-is-the-equivalent-of-summarize-field-in-qgis might help. – Michael Stimson Nov 14 '19 at 00:34
  • 1
    you can also do this with QGIS, see this nice tutorial from Ujaval: http://www.qgistutorials.com/en/docs/3/nearest_neighbor_analysis.html – eurojam Nov 14 '19 at 07:49
  • 2
    Use the aggregate functions in the Field Calculator to add a field to the district layer. Something like aggregate('High Schools', 'mean', "Distance to Library",intersects($geometry,@parent)). Substitute the name of your High Schools layer and the name of the "distance to library" field in that layer. – csk Nov 14 '19 at 17:00

1 Answers1

2

This question was asked several times, always with a different nuance.

The same, as there are many possible solutions, can be answered in several ways.

The solution provided by @csk seems to me the best if you want to include the information in the existing Districts layer.

In the links provided by @MichaelStimson there are also very good solutions. The virtual layer solution is very good for cases where the origin values vary frequently. The answers that included plugins were very good at the time, but the constant development of QGIS was including many functionalities that began as a plugin.

The tutorial provided by @eurojam is good to start the spatial analysis, although it does not answer your question exactly.

Which is best for your case, depends on the functionality you want.


If the source data does not change constantly (that is, you want to perform the calculation only once), and you also prefer to obtain the result in a new layer, which includes the geometries and attribute table of the Districts layer, with one or more new fields , which are some statistical function of one or more fields of the HighScools layer, spatially related under the predicate contains (District cointains High Schools), the Join attributes by location (summary) tool seems to me the most appropriate:

1

Gabriel De Luca
  • 14,289
  • 3
  • 20
  • 51