0

I have a similar problem, but I can't get the syntax correct. This refers to the following question:

Merge polygons in CartoDB?

enter image description here

I'm trying to merge multiple polygons into one (in this case, just the 5 NYC boroughs into a single polygon, but for now I'm trying to merge all of them). This doesn't seem to work, as the result is still separate polygons.

SELECT

counties_ny
, cartodb_id
, max(county) as county
, max(fips) as fips
, max(county_fip) as county_fip

, st_union(the_geom_webmercator) as the_geom_webmercator

FROM counties_ny

group by county, counties_ny.cartodb_id

1
  • At least the unique field "cartodb_id" does not feel most suitable for grouping.
    – user30184
    Commented Mar 18, 2015 at 15:26

1 Answer 1

2

If you only want one output record, remove the GROUP BY clause:

SELECT
1 AS cartodb,
ST_Union(the_geom_webmercator) AS the_geom_webmercator
FROM counties_ny

The output will be a MultiPolygon, probably, since Staten Island and other things cannot be merged due to the water in between.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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