[GIS] Speeding up QGIS spatial join

performanceqgisspatial-join

I am trying to calculate the coverage that a set of points has of a road network layer. I have 100 million points and approximately 80,000 segments in my road network layer.

I have created a buffer around each road segment (roadsegment.shp) and am attempting to run a spatial query (using the standard spatial query tool in QGIS) to see which segments contain at least one of my 100 million points (points.shp). However, this query is taking far too long to run and I need to find a more efficient way to do this.

I am not concerned with the number of points in each road segment buffer and I do not need to pass an attribute from the buffer to ALL of the points. I just need to know whether or not a segment contains a point. Once I know that it does, it can be dropped from the analysis. I think that this must help me to make the query more efficient.

I should point out that I am fairly new to QGIS and only know how to use the standard tools in the software.

Can anybody help me with a script to speed up the processing?

Best Answer

Add a spatial index to each of your shapefile layers:

Layer > Properties... > General then Create spatial index.

Another way is to create them for all the layers in one go:

Vector > Data Management Tools > Create Spatial Index... then Select all then OK

Related Question