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?


1 Answer 1


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:


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.