Is there any simple integration for calculating count of points in polygon using QGIS-Python integration?
In other words, are there any pre-defined functions for points in polygon of QGIS using python, so that we can use them in our python script?
Answer
Great methods already posted! There are also tools from the Processing Toolbox which you could call from your script (this is assuming you are running scripts inside QGIS):
- Count points in polygon
- Counts points in polygon (weighted)
- Count unique points in polygon
Taking the first tool, you could call it using:
import processing
Result = "path\to\saved_output.shp"
processing.runalg("qgis:countpointsinpolygon", "path\to\polygon_layer.shp", "path\to\point_layer.shp", 'NUMPOINTS', Result)
where NUMPOINTS
is the name of the field which stores the number of points.
I'm using QGIS 2.8.2-Wien, Processing plugin v2.9.3. Hope this helps!
No comments:
Post a Comment