1

I have been looking for a way to extract various stats for each group from a shp file which contains groups of points. I found that Group Stats tool is the way to do that. However I would like to iterate this tool over 100 shp files. Is there any way to do that in the QGIS python window?

Otherwise I have to merge all files then apply the tool. But this makes data very large and unmanageable.

I used code below to run items iteratively. Only issue I had, when I open the excel file, it throws me a “repair warning”. After I click OK all calculations are there. But not sure why excel gives those warnings.

import processing for itemfeature in listofShps: outputfullpath=os.path.dirname(itemfeature)+'\\'+os.path.basename(itemfeature)[:-4]+'.xlsx' processing.run('qgis:statisticsbycategories',{'CATEGORIES_FIELD_NAME' : [strCatagoryFieldName],'INPUT' : itemfeature,'VALUES_FIELD_NAME' : strValueFieldName,'OUTPUT' : outputfullpath} )
  • Plugins are independently created. If the plugin developer didn't add a batch process method, then it doesn't exist. QGIS core tools all have batch processing methods, so have a look at the "statistics by categories" tool and see if it does what you need. – csk May 1 at 20:08
  • Thank you for advice, it definitely helped. I used code below to run items iteratively. Only issue I had, when I open the excel file, it throws me a “repair warning”. After I click OK all calculations are there. But not sure why excel gives those warnings. >> import processing for itemfeature in listofShps: outputfullpath=os.path.dirname(itemfeature)+'\\'+os.path.basename(itemfeature)[:-4]+'.xlsx' processing.run('qgis:statisticsbycategories',{'CATEGORIES_FIELD_NAME' : [strCatagoryFieldName],'INPUT' : itemfeature,'VALUES_FIELD_NAME' : strValueFieldName,'OUTPUT' : outputfullpath} ) – ncelik May 2 at 19:50
  • are you opening the .dbf portion of a shapefile? – csk May 2 at 20:29
  • I am using path of the " .shp " file as input parameters. Then after running the code, I am trying to open the result of the tool which is ".xlsx" which I specified in the code. – ncelik May 3 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.