-- This example demonstrates how to use SE_Dissolve to combine several
-- geometries into a single geometry by aggregation.
-- 
-- The source geometries must all be of the same dimension; you cannot
-- combine points with linestrings, etc.

-- Example 1: combining points

CREATE TABLE well_locations (id   integer,
                             locn ST_Point);

INSERT INTO well_locations VALUES(1, "1000 point (34.326 43.452)");
INSERT INTO well_locations VALUES(2, "1000 point (18.143 56.987)");
INSERT INTO well_locations VALUES(3, "1000 point (76.722 87.732)");

SELECT SE_Dissolve(locn) FROM well_locations;


-- Example 2: combining polygons

CREATE TABLE honeycomb (cell_id int,
                        cell    ST_Polygon);

INSERT INTO honeycomb 
   VALUES (1, '0 polygon((5 10,7 7,10 7,12 10,10 13,7 13,5 10))');

INSERT INTO honeycomb 
   VALUES (2, '0 polygon((12 4,15 4,17 7,15 10,12 10,10 7,12 4))');

INSERT INTO honeycomb 
   VALUES (3, '0 polygon((17 7,20 7,22 10,20 13,17 13,15 10,17 7))');

INSERT INTO honeycomb 
   VALUES (4, '0 polygon((15 10,17 13,15 16,12 16,10 13,12 10,15 10))');


select SE_Dissolve(cell) from honeycomb;

