Thursday, 19 January 2017

Preserving geometry of Union output with Virtual Layer in QGIS 2


There is a polygon layer "Union23" that was created with 'Union' tool.


Polygon_Layer


Layer's attribute table includes the following values.


AT_values


My effort is simply to aggregate those polygons by "FLAECHEID" field with the sum and count of a field "In_Value1" via Virtual Layer. So I am using the expression



SELECT *, SUM(In_Value1), COUNT(In_Value1)
FROM Union23
GROUP BY "FLAECHEID"

However, I am getting really weird output and I do not understand why I am losing a part of geometry on the way? Any suggestions?


VL_Output




When I use the solution offered by @JGH I am somehow getting better output but still with small issues. It is most like related to the original geometry. Improving geometry is necessary as was mentioned by @Stu Smith.


VL_output_2





References:




Answer



When using a mix of an aggregate function and a regular row, SQLite will return a random row for the not-aggregated field (see doc, point 3). To overcome this, don't use * but properly aggregated fields, including on the geometry


SELECT ST_UNION(geometry), SUM(In_Value1), COUNT(In_Value1)
FROM Union23
GROUP BY "FLAECHEID"

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...