In the previous chapter, we learned how to use ST_Collect
function to compose Multi-geometries from components. This is computationally cheap, but sometimes, retaining the borders between components (for example, land parcels) is not desirable. This is where union
functions come into play.
PostGIS has three unioning functions:
ST_Union
ST_MemUnion
, which is memory optimized (that is, it will take more time but less memory)ST_UnaryUnion
, which operates at geometry component-level (and hence is more suitable for Multi-geometries)
The usage of unioning functions is similar to other spatial aggregate
functions. The first possibility is to supply two geometries. For example, let's pick two town boundaries and simulate the administrative boundary if they were merged:
SELECT ST_Union( (SELECT wkb_geometry FROM multipolygons WHERE osm_id = '2828737'), (SELECT wkb_geometry FROM multipolygons WHERE osm_id = '2828740') );
The resulting polygon has no boundary...