st_makeenvelope function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 18.2 and above

Important

This feature is in Public Preview.

Note

This feature is not available on Databricks SQL Classic warehouses. To learn more about Databricks SQL warehouses, see SQL warehouse types.

Returns a GEOMETRY value representing the 2D axis-aligned envelope (minimum bounding box) defined by the two corner coordinates (x1, y1) and (x2, y2).

Syntax

st_makeenvelope ( x1, y1, x2, y2 )

Arguments

  • x1: A DOUBLE value, representing the X coordinate of the first corner.
  • y1: A DOUBLE value, representing the Y coordinate of the first corner.
  • x2: A DOUBLE value, representing the X coordinate of the second corner.
  • y2: A DOUBLE value, representing the Y coordinate of the second corner.

Returns

A value of type GEOMETRY, representing the 2D axis-aligned envelope of the two input corners. The SRID of the returned geometry is 0.

The input corners may be provided in any order; the resulting envelope is the same as if the corners were normalized to (xmin, ymin) and (xmax, ymax).

The type of the returned geometry depends on the input corners:

  • If the box degenerates to a single point (x1 = x2 and y1 = y2), the result is a point.
  • If the box degenerates to a segment (x1 = x2 or y1 = y2, but not both), the result is a linestring with two points.
  • Otherwise, the result is a polygon with five vertices (closed ring).

The function returns NULL if any of the inputs is NULL.

Examples

-- Returns the polygon envelope defined by two corners.
> SELECT st_astext(st_makeenvelope(1.0, 2.0, 4.0, 6.0));
  POLYGON((1 2,1 6,4 6,4 2,1 2))
-- Corners may be provided in any order.
> SELECT st_astext(st_makeenvelope(4.0, 6.0, 1.0, 2.0));
  POLYGON((1 2,1 6,4 6,4 2,1 2))
-- Returns a point when the box degenerates to a point.
> SELECT st_astext(st_makeenvelope(3.0, 5.0, 3.0, 5.0));
  POINT(3 5)
-- Returns a linestring when the box degenerates to a horizontal segment.
> SELECT st_astext(st_makeenvelope(1.0, 0.0, 4.0, 0.0));
  LINESTRING(1 0,4 0)
-- Returns a linestring when the box degenerates to a vertical segment.
> SELECT st_astext(st_makeenvelope(0.0, 2.0, 0.0, 7.0));
  LINESTRING(0 2,0 7)
-- The SRID of the returned geometry is always 0.
> SELECT st_srid(st_makeenvelope(0.0, 0.0, 10.0, 10.0));
  0