Tuesday, 21 November 2017

pyqgis - QGIS: SQL query within python console to sum a column based on values of other two columns



We have 100's of shapefiles for which we have to generate excel reports based on few (combination of) parameters in the attribute table. I am using SQL query to achieve this and when i run the query in the "Create Virtual layer" process, it works fine and the output has been generated, which will be saved as an excel file. Instead of this process, i am trying to run this through python console. Though the code didn't show any error, the output is not being printed. Do i have to change the SQL query format in the code ?


Image 1: For the shapefile final_bdry, Total_Area has to be calculated based on two other columns - MS_Area, Ground_Con (similar to Pivot_Table in excel, sum of a column based on unique count of other two columns). No issues with the query and i am getting the desired output in the virtual_layer. enter image description here.


Image 2: But, if i run the same query within python console, result is "None" enter image description here Ref: Used this as ref SQL queries in shapefiles using python/gdal return none result




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...