Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

ST_GeomFromGeoSquare - Amazon Redshift
This page has not been translated into your language. Request translation

ST_GeomFromGeoSquare

ST_GeomFromGeoSquare returns a geometry that covers the area that is represented by an input geosquare value. The returned geometry is always two-dimensional. To calculate a geosquare value, see ST_GeoSquare.

Syntax

ST_GeomFromGeoSquare(geosquare)
ST_GeomFromGeoSquare(geosquare, max_depth)

Arguments

geosquare

A value of data type BIGINT or an expression that evaluates to a BIGINT type that is a geosquare value that describes the sequence of subdivisions made on the initial domain to reach the desired square. This value is calculated by ST_GeoSquare.

max_depth

A value of data type INTEGER that represents the maximum number of domain subdivisions made on the initial domain. The value must be greater than or equal to 1.

Return type

GEOMETRY

If geosquare is not valid, the function returns an error.

If the input max_depth is not within range, the function returns an error.

Examples

The following SQL returns a geometry from a geosquare value.

SELECT ST_AsText(ST_GeomFromGeoSquare(797852));
st_astext -------------------------------------------------------------------------------------------------------------------- POLYGON((13.359375 52.3828125,13.359375 52.734375,13.7109375 52.734375,13.7109375 52.3828125,13.359375 52.3828125))

The following SQL returns a geometry from a geosquare value and a maximum depth of 3.

SELECT ST_AsText(ST_GeomFromGeoSquare(797852, 3));
st_astext -------------------------------------- POLYGON((0 45,0 90,45 90,45 45,0 45))

The following SQL first calculates the geosquare value for Seattle by specifying the x coordinate as longitude and the y coordinate as latitude (-122.3, 47.6). Then it returns the polygon for the geosquare. Although the output is a two-dimensional geometry, it can be used to calculate spatial data in terms of longitude and latitude.

SELECT ST_AsText(ST_GeomFromGeoSquare(ST_GeoSquare(ST_Point(-122.3, 47.6))));
st_astext ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- POLYGON((-122.335167014971 47.6080129947513,-122.335167014971 47.6080130785704,-122.335166931152 47.6080130785704,-122.335166931152 47.6080129947513,-122.335167014971 47.6080129947513))
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.