1

In a PostGRES/PostGIS database, I have a table "myTable" containing very large numbers of polygons (the geometry is under the column "Polygon"). Each polygon has a numerical value under the "Var1" column. They also each fall under an area stored as a string in the "Region" column.

Since these polygons are too numerous, I'd like to aggregate them according to the region they belong to.

This is what I'm doing:

SELECT ST_Collect(Polygon) as geom FROM myTable GROUP BY Region;

Although, by doing that, I lose the very important values under Var1.

How can I compute the means of the values of Var1 for each polygons under the same Region, and output it in my query?

1

the answer is in the question.... just compute the average!

SELECT ST_Collect(Polygon) as geom, avg(var1)
FROM myTable 
GROUP BY Region; 
1
  • This works, thanks a lot!
    – Lucien S.
    Dec 20 '19 at 15:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.