Bug report #16628

Count Unique Points in Polygons seems to fail inside a loop (PyQGIS)

Added by Diego García Díaz almost 7 years ago. Updated almost 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Processing/QGIS
Affected QGIS version:2.18.8 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:24528

Description

Hi,

I have been using the tool 'is:countuniquepointsinpolygon' inside a loop with 4000 polygons and a shapefile with 500000 points. The tool runs without any issue, but when I look at the result field, the maximum value that it gets is 2 (which is incorrect). If I run the tool from the toolbox, just for one polygon I get correct results, but for one reason inside the loop never go over 2 (maybe something with memory available?). Besides, this happens with a huge number of points, if I run the loop with a smaller shapefile point, it throws correct results.

I have uploaded to my Dropbox 5 polygons and a 10% of the points (I also get wrong values with this small sub dataset): https://www.dropbox.com/sh/f5982yd8dovsng3/AAAfwVmbtGc4uSOhi96GLHP4a?dl=0

And the script that I wrote is this:

------Code------

import os, processing

  1. Set local variables
    path = r'my\base\path\Dissolves'
    continents = r'\somepath\points.shp'
    outpath = r'path\to\outfile'
  1. Creamos la lista de shapes
    shpList = [os.path.join(path, i) for i in os.listdir(path) if i.endswith('.shp') and not 'point' in i]
    print('creada lista de', len(shpList), 'shapes')

for shp in shpList:

outShp = os.path.join(outpath, os.path.split(shp)[1])
print('Haciendo especie:', os.path.split(shp)[1])
try:
  1. Ejecutamos el join espacial dentro de un tr por si hubiera algun error poder continuar al siguiente shape
    processing.runalg('qgis:countuniquepointsinpolygon', shp, continents, 'issed', 'NUMPOINTS', outShp)
except Exception as e:
print('Error', e, os.path.split(shp)[1])
continue

-----End Code-------

Thanks for your help!

Best regards,
Diego Garcia Diaz

History

#1 Updated by Giovanni Manghi almost 7 years ago

  • Project changed from QGIS Redmine (QGIS bug tracker) to QGIS Application
  • Easy fix? set to No
  • Regression? set to No
  • Crashes QGIS or corrupts data set to No
  • Affected QGIS version set to 2.18.8
  • Category changed from Any to Python plugins

#2 Updated by evangelos vafeiadis almost 7 years ago

try:

  1. Ejecutamos el join espacial dentro de un tr por si hubiera algun error poder continuar al siguiente shape
    processing.runalg('qgis:countuniquepointsinpolygon', shp, continents, 'issed', 'NUMPOINTS', outShp)

Hello Giovanni,

your input parameters seem to be wrong. It's 'isseed' instead of 'issed'. Could you try again?

#3 Updated by evangelos vafeiadis almost 7 years ago

PS. Can you assign the bug to me? I plan to a bit of extra code to catch an error like this.

#4 Updated by Borys Jurgiel over 6 years ago

  • Category changed from Python plugins to Processing/QGIS

I'm updating the category. Unfortunately I have no idea how to assign it to you. Giovanni, are you around?

#5 Updated by Alexander Bruy about 6 years ago

  • Status changed from Open to Feedback

Please check with latest 2.18 and master.

#6 Updated by Alexander Bruy almost 6 years ago

  • Status changed from Feedback to Closed

Closed for the lack of feedback. Please reopen if necessary.

Also available in: Atom PDF