-- The envelope_test table's geotype column stores the name of the 
-- geometry subclass stored in the g1 ST_Geometry column. 

CREATE TABLE envelope_test (geotype varchar(20),
                            g1      ST_Geometry);

-- The INSERT statements insert each geometry subclass into the
-- envelope_test table.
INSERT INTO envelope_test VALUES( 
   'Point', 
   ST_PointFromText('point (10.02 20.01)',1000)
);

INSERT INTO envelope_test VALUES( 
   'Linestring', 
   ST_LineFromText('linestring (10.01 20.01, 10.01 30.01, 10.01 40.01)', 1000) 
);

INSERT INTO envelope_test VALUES( 
   'Linestring', 
   ST_LineFromText('linestring (10.02 20.01,10.32 23.98,11.92 25.64)', 1000) 
);

INSERT INTO envelope_test VALUES( 
   'Polygon', 
   ST_PolyFromText('polygon ((10.02 20.01,11.92 35.64,25.02 34.15,19.15 33.94, 10.02 20.01))',1000) 
);

INSERT INTO envelope_test VALUES( 
   'Multipoint', 
   ST_MPointFromText('multipoint (10.02 20.01,10.32 23.98,11.92 25.64)', 1000) 
);

INSERT INTO envelope_test VALUES( 
   'Multilinestring', 
   ST_MLineFromText('multilinestring ((10.01 20.01,20.01 20.01,30.01 20.01), (30.01 20.01,40.01 20.01,50.01 20.01))',1000) 
);

INSERT INTO envelope_test VALUES( 
   'Multilinestring', 
   ST_MLineFromText('multilinestring ((10.02 20.01,10.32 23.98,11.92 25.64),(9.55 23.75,15.36 30.11))',1000) 
);

INSERT INTO envelope_test VALUES( 
   'Multipolygon', 
   ST_MPolyFromText('multipolygon (((10.02 20.01,11.92 35.64,25.02 34.15,19.15 33.94,10.02 20.01)),((51.71 21.73,73.36 27.04,71.52 32.87,52.43 31.90,51.71 21.73)))',1000) 
);

-- The query lists the subclass name and its envelope.  Th
-- ST_Envelope function returns a point, linestring, or polygon.

SELECT geotype, ST_Envelope(g1) Envelope 
   FROM envelope_test;
