ST_Envelope

Definition

ST_Envelope returns the minimum bounding box of a geometry object as a polygon.

Dive-inDive-in:

This function conforms with the Open Geospatial Consortium (OGC) Simple Features specification that states that ST_Envelope return a polygon. To work with special cases of point geometries or horizontal or vertical lines, the ST_Envelope function returns a polygon around these shapes, which is a small envelope tolerance calculated based on the XY scale factor for the geometry's spatial reference system. This tolerance is subtracted from the min x and y and added to the max x and y coordinates to return the polygon around these shapes.

Syntax

Oracle and PostgreSQL

sde.st_envelope (geometry1 sde.st_geometry)

SQLite

st_envelope (geometry1 geometryblob)

Return type

Oracle and PostgreSQL

ST_Geometry

SQLite

Geometryblob

Example

The envelope_test table's geotype column stores the name of the geometry subclass stored in the g1 column. The INSERT statements insert each geometry subclass into the envelope_test table.

Next, the ST_Envelope function is run to return the polygon envelope around each geometry.

Oracle

--Create table and insert values.
CREATE TABLE envelope_test (
 geotype varchar(20),
 g1 sde.st_geometry
);

INSERT INTO ENVELOPE_TEST VALUES (
'Point',
sde.st_geometry ('point (-1509734.232 -36684.757)', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Linestring',
sde.st_geometry ('linestring (-1511144.181 -37680.015, -1509734.232 -38841.149, -1508656.036 -39753.469)', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Polygon',
sde.st_geometry ('polygon ((-1506333.768 -36435.943, -1504343.252 -36767.695, -1502684.489 -35357.747, -1506333.768 -36435.943))', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Multipoint',
sde.st_geometry ('multipoint (-1493229.539 -40665.789, -1494141.859 -40831.665, -1495800.622 -42739.242)', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Multilinestring',
sde.st_geometry ('multilinestring ((-1504757.943 -33201.355, -1507411.964 -35606.561), (-1502518.613 -38094.706, -1499781.653 -37099.448, -1498952.272 -34694.241))', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Multipolygon',
sde.st_geometry ('multipolygon (((-1492068.405 -47300.841, -1492814.848 -45725.016, -1493975.983 -46471.459,
-1493478.354 -47798.47, -1492068.405 -47300.841), (-1497874.076 -48047.284, -1498537.581 -50618.367, -1497210.571 -50037.8,
-1497874.076 -48047.284)))', 102004)
);
--Return the polygon envelope around each geometry in well-known text.
SELECT geotype geometry_type,
 sde.st_astext (sde.st_envelope (g1)) envelope
 FROM ENVELOPE_TEST;

GEOMETRY_TYPE    ENVELOPE
 
Point           |POLYGON (( -1509734.23220000 -36684.75720000, -1509734.23180000 -36684.75720000, 
-1509734.23180000 -36684.75680000, -1509734.23220000 -36684.75680000, -1509734.23220000 -36684.75720000))

Linestring      |POLYGON (( -1511144.18100000 -39753.46900000, -1508656.03600000 -39753.46900000, 
-1508656.03600000 -37680.01500000, -1511144.18100000 -37680.01500000, -1511144.18100000 -39753.46900000))

Polygon         |POLYGON (( -1506333.76800000 -36767.69500000, -1502684.48900000 -36767.69500000, 
-1502684.48900000 -35357.74700000, -1506333.76800000 -35357.74700000, -1506333.76800000 -36767.69500000))

Multipoint      |POLYGON (( -1495800.62200000 -42739.24200000, -1493229.53900000 -42739.24200000, 
-1493229.53900000 -40665.78900000, -1495800.62200000 -40665.78900000, -1495800.62200000 -42739.24200000))

Multilinestring |POLYGON (( -1507411.96400000 -38094.70600000, -1498952.27200000 -38094.70600000, 
-1498952.27200000 -33201.35500000, -1507411.96400000 -33201.35500000, -1507411.96400000 -38094.70600000))

Multipolygon    |POLYGON (( -1498537.58100000 -50618.36700000, -1492068.40500000 -50618.36700000, 
-1492068.40500000 -45725.01600000, -1498537.58100000 -45725.01600000, -1498537.58100000 -50618.36700000))

PostgreSQL

--Create table and insert values.
CREATE TABLE envelope_test (
 geotype varchar(20),
 g1 sde.st_geometry
);

INSERT INTO ENVELOPE_TEST VALUES (
'Point',
sde.st_geometry ('point (-1509734.232 -36684.757)', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Linestring',
sde.st_geometry ('linestring (-1511144.181 -37680.015, -1509734.232 -38841.149, -1508656.036 -39753.469)', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Polygon',
sde.st_geometry ('polygon ((-1506333.768 -36435.943, -1504343.252 -36767.695, -1502684.489 -35357.747, -1506333.768 -36435.943))', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Multipoint',
sde.st_geometry ('multipoint (-1493229.539 -40665.789, -1494141.859 -40831.665, -1495800.622 -42739.242)', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Multilinestring',
sde.st_geometry ('multilinestring ((-1504757.943 -33201.355, -1507411.964 -35606.561), (-1502518.613 -38094.706, -1499781.653 -37099.448, -1498952.272 -34694.241))', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
'Multipolygon',
sde.st_geometry ('multipolygon (((-1492068.405 -47300.841, -1492814.848 -45725.016, -1493975.983 -46471.459,
-1493478.354 -47798.47, -1492068.405 -47300.841), (-1497874.076 -48047.284, -1498537.581 -50618.367, -1497210.571 -50037.8,
-1497874.076 -48047.284)))', 102004)
);
--Return the polygon envelope around each geometry in well-known text.
SELECT geotype AS geometry_type, 
 sde.st_astext (sde.st_envelope (g1)) AS Envelope
 FROM envelope_test;

geometry_type     envelope

"Point"           |"POLYGON (( -1509734.23220000 -36684.75720000, -1509734.23180000 -36684.75720000, 
-1509734.23180000 -36684.75680000, -1509734.23220000 -36684.75680000, -1509734.23220000 -36684.75720000))"

"Linestring"      |"POLYGON (( -1511144.18100000 -39753.46900000, -1508656.03600000 -39753.46900000, 
-1508656.03600000 -37680.01500000, -1511144.18100000 -37680.01500000, -1511144.18100000 -39753.46900000))"

"Polygon"         |"POLYGON (( -1506333.76800000 -36767.69500000, -1502684.48900000 -36767.69500000, 
-1502684.48900000 -35357.74700000, -1506333.76800000 -35357.74700000, -1506333.76800000 -36767.69500000))"

"Multipoint"      |"POLYGON (( -1495800.62200000 -42739.24200000, -1493229.53900000 -42739.24200000, 
-1493229.53900000 -40665.78900000, -1495800.62200000 -40665.78900000, -1495800.62200000 -42739.24200000))"

"Multilinestring" |"POLYGON (( -1507411.96400000 -38094.70600000, -1498952.27200000 -38094.70600000, 
-1498952.27200000 -33201.35500000, -1507411.96400000 -33201.35500000, -1507411.96400000 -38094.70600000))"

"Multipolygon"    |"POLYGON (( -1498537.58100000 -50618.36700000, -1492068.40500000 -50618.36700000, 
-1492068.40500000 -45725.01600000, -1498537.58100000 -45725.01600000, -1498537.58100000 -50618.36700000))"

SQLite

--Create table and insert values.
CREATE TABLE envelope_test (
 geotype varchar(20)
);

SELECT AddGeometryColumn (
 NULL,
 'envelope_test',
 'g1',
 4326,
 'geometry',
 'xy',
 'null'
);

INSERT INTO ENVELOPE_TEST VALUES (
 'Point',
 st_geometry ('point (-1509734.232 -36684.757)', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
 'Linestring',
 st_geometry ('linestring (-1511144.181 -37680.015, -1509734.232 -38841.149, -1508656.036 -39753.469)', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
 'Polygon',
 st_geometry ('polygon ((-1506333.768 -36435.943, -1504343.252 -36767.695, -1502684.489 -35357.747, -1506333.768 -36435.943))', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
 'Multipoint',
 st_geometry ('multipoint (-1493229.539 -40665.789, -1494141.859 -40831.665, -1495800.622 -42739.242)', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
 'Multilinestring',
 st_geometry ('multilinestring ((-1504757.943 -33201.355, -1507411.964 -35606.561), (-1502518.613 -38094.706, -1499781.653 -37099.448, -1498952.272 -34694.241))', 102004)
);

INSERT INTO ENVELOPE_TEST VALUES (
 'Multipolygon',
 st_geometry ('multipolygon (((-1492068.405 -47300.841, -1492814.848 -45725.016, -1493975.983 -46471.459,
-1493478.354 -47798.47, -1492068.405 -47300.841), (-1497874.076 -48047.284, -1498537.581 -50618.367, -1497210.571 -50037.8,
-1497874.076 -48047.284)))', 102004)
);
--Return the polygon envelope around each geometry in well-known text.
SELECT geotype AS geometry_type, 
 st_astext (st_envelope (g1)) AS "Envelope"
 FROM envelope_test;

geometry_type   Envelope

Point           POLYGON (( -1509734.23220000 -36684.75720000, -1509734.23180000 -36684.75720000, 
-1509734.23180000 -36684.75680000, -1509734.23220000 -36684.75680000, -1509734.23220000 -36684.75720000))

Linestring      POLYGON (( -1511144.18100000 -39753.46900000, -1508656.03600000 -39753.46900000, 
-1508656.03600000 -37680.01500000, -1511144.18100000 -37680.01500000, -1511144.18100000 -39753.46900000))

Polygon         POLYGON (( -1506333.76800000 -36767.69500000, -1502684.48900000 -36767.69500000, 
-1502684.48900000 -35357.74700000, -1506333.76800000 -35357.74700000, -1506333.76800000 -36767.69500000))

Multipoint      POLYGON (( -1495800.62200000 -42739.24200000, -1493229.53900000 -42739.24200000, 
-1493229.53900000 -40665.78900000, -1495800.62200000 -40665.78900000, -1495800.62200000 -42739.24200000))

Multilinestring POLYGON (( -1507411.96400000 -38094.70600000, -1498952.27200000 -38094.70600000, 
-1498952.27200000 -33201.35500000, -1507411.96400000 -33201.35500000, -1507411.96400000 -38094.70600000))

Multipolygon    POLYGON (( -1498537.58100000 -50618.36700000, -1492068.40500000 -50618.36700000, 
-1492068.40500000 -45725.01600000, -1498537.58100000 -45725.01600000, -1498537.58100000 -50618.36700000))

Related Topics

6/19/2015