MySQL tutorial: ST_MAKEENVELOPE [EN]
top of page
CerebroSQL

MySQL: 

ST_MAKEENVELOPE

ST_MakeEnvelope(pt1, pt2)

Returns the rectangle that forms the envelope around two points, as a
Point, LineString, or Polygon.

Calculations are done using the Cartesian coordinate system rather than
on a sphere, spheroid, or on earth.

Given two points pt1 and pt2, ST_MakeEnvelope() creates the result
geometry on an abstract plane like this:

o If pt1 and pt2 are equal, the result is the point pt1.

o Otherwise, if (pt1, pt2) is a vertical or horizontal line segment,
the result is the line segment (pt1, pt2).

o Otherwise, the result is a polygon using pt1 and pt2 as diagonal
points.

The result geometry has an SRID of 0.

ST_MakeEnvelope() handles its arguments as described in the
introduction to this section, with these exceptions:

o If the arguments are not Point values, an ER_WRONG_ARGUMENTS
(https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference
.html#error_er_wrong_arguments) error occurs.

o An ER_GIS_INVALID_DATA
(https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference
.html#error_er_gis_invalid_data) error occurs for the additional
condition that any coordinate value of the two points is infinite or
NaN.

o If any geometry has an SRID value for a geographic spatial reference
system (SRS), an ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
(https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference
.html#error_er_not_implemented_for_geographic_srs) error occurs.

URL: https://dev.mysql.com/doc/refman/8.0/en/spatial-convenience-functions.html

Example

mysql> SET @pt1 = ST_GeomFromText('POINT(0 0)');
mysql> SET @pt2 = ST_GeomFromText('POINT(1 1)');
mysql> SELECT ST_AsText(ST_MakeEnvelope(@pt1, @pt2));
+----------------------------------------+
| ST_AsText(ST_MakeEnvelope(@pt1, @pt2)) |
+----------------------------------------+
| POLYGON((0 0,1 0,1 1,0 1,0 0)) |
+----------------------------------------+

bottom of page