简体   繁体   中英

Qgis Python Console, Count unique features in polygons

Hello I am using the python console to count the number of unique features of points in a polygon layer. Here is the link where I'm replicating the code link .

Here is what my code looks like:

processing.runalg('qgis:countuniquepointsinpolygon', poly, pts, "fclass", "pt_count", res)

poly is my polygon layer, pts is my points layer, "fclass" is the field name in pts layer, "pt_count" will be the field where the unique feature counts will go into, and res is the new polygon to be created with "pt_count" field in it.

when I run the code I get the following error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'res' is not defined

the field "fclass" from pts looks like this: Image

Is there a reason why I get this error if res is suppose to be created?

Did you try passing a filename as res ? For example:

processing.runalg('qgis:countuniquepointsinpolygon', poly, pts, "fclass", "pt_count", "myresult.shp")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM