Geometry Constructors

The geometry constructors can be used to create a Geometry using the well-known binary (WKB) representation, well-known text (WKT) representation, or Geohash.

st_geomFromGeoHash

Geometry st_geomFromGeoHash(String geohash, Int prec)

This function returns the Geometry of the bounding box corresponding to the Geohash string geohash (base-32 encoded) with the precision of prec bits. For more information about Geohash, see Geohash.

Example:

  • Query command:

    select st_astext(st_geomFromGeoHash('ssf17',25))

  • The query result is as follows:
    POLYGON ((25.4443359375 26.9384765625, 25.4443359375 26.982421875, 25.48828125 26.982421875, 25.48828125 26.9384765625, 25.4443359375 26.9384765625))

st_box2DFromGeoHash

Geometry st_box2DFromGeoHash(String geohash, Int prec)

Alias for st_geomFromGeoHash. Refer to the example in st_geomFromGeoHash.

st_geomFromWKB

Geometry st_geomFromWKB(Array[Byte] wkb)

This function creates a Geometry from the given WKB.

Example:

  • Query command:

    select st_astext((st_geomFromWKB(st_asBinary(st_geomFromText(location))))) from geotbl where id='3'

  • The query result is as follows:
    MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))

st_geomFromWKT

Geometry st_geomFromWKT(String wkt)

This function creates a Geometry from the given WKT.

st_geomFromText

Geometry st_geomFromText(String wkt)

Alias for st_geomFromWKT.

Example:

  • Query command:

    select st_astext((st_geomFromText(location))) from geotbl where id='1'

  • The query result is as follows:
    POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))

st_geometryFromText(String wkt)

Geometry st_geometryFromText(String wkt)

Alias for st_geomFromWKT.

Example:

  • Query command:

    select st_astext((st_geometryFromText(location))) from geotbl where id='5'

  • The query result is as follows:
    LINESTRING (30 10, 40 40, 20 40, 10 20, 30 10)

st_lineFromText

LineString st_lineFromText(String wkt)

This function creates a LineString from the given WKT representation.

Example:

  • Query command:

    select st_astext((st_lineFromText(location))) from geotbl where id='5'

  • The query result is as follows:
    LINESTRING (30 10, 40 40, 20 40, 10 20, 30 10)

st_mLineFromText

MultiLineString st_mLineFromText(String wkt)

This function creates a MultiLineString corresponding to the given WKT representation.

Example:

  • Query command:

    select st_astext((st_mLineFromText(location))) from geotbl where id='7'

  • The query result is as follows:
    MULTILINESTRING ((30 10, 40 40, 20 40, 10 20, 30 10), (30 10, 40 40, 20 40, 10 20, 30 10))

st_mPointFromText

MultiPoint st_mPointFromText(String wkt)

This function creates a MultiPoint corresponding to the given WKT representation.

Example:

  • Query command:

    select st_astext((st_mPointFromText(location))) from geotbl where id='8'

  • The query result is as follows:
    MULTIPOINT ((11 22), (10 22))

st_mPolyFromText

MultiPolygon st_mPolyFromText(String wkt)

This function creates a MultiPolygon corresponding to the given WKT representation.

Example:

  • Query command:

    select st_astext((st_mPolyFromText(location))) from geotbl where id='3'

  • The query result is as follows:
    MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))

st_makeBBOX

Geometry st_makeBBOX(Double lowerX, Double lowerY, Double upperX, Double upperY)

This function creates a Geometry representing a bounding box with the given boundaries.

Example:

  • Query command:

    select st_astext((st_makeBBOX(10,20,10,20)))

  • The query result is as follows:
    POINT (10 20)

st_makeBox2D

Geometry st_makeBox2D(Point lowerLeft, Point upperRight)

This function creates a Geometry representing a bounding box defined by the given points.

Example:

  • Query command:

    select st_astext(st_makeBox2D(st_castToPoint(st_geomFromWKT('POINT (11 22)')),st_castToPoint(st_geomFromWKT('POINT (10 20)'))))

  • The query result is as follows:
    POLYGON ((10 20, 10 22, 11 22, 11 20, 10 20))

st_makePoint

Point st_makePoint(Double x, Double y)

This function creates a point with x and y coordinates.

Example:

  • Query command:

    select st_astext(st_makePoint(1,2))

  • The query result is as follows:
    POINT (1 2)

st_makePointM

Point st_makePointM(Double x, Double y, Double m)

This function creates a point with x, y, and m coordinates.

Example:

  • Query command:

    select st_astext(st_makePointM(1,2,2))

  • The query result is as follows:
    POINT (1 2)

st_makePolygon

Polygon st_makePolygon(LineString shell)

This function creates a Polygon formed by the given LineString shell, which must be closed.

Example:

  • Query command:

    select st_astext(st_makePolygon(st_castToLineString(st_geomFromWKT('LINESTRING (30 10, 40 40, 20 40, 10 20, 30 10)'))))

  • The query result is as follows:
    POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))

st_point

Point st_point(Double x, Double y)

This function creates a point with the given coordinate values. This is an OGC alias for st_makePoint.

Example:

  • Query command:

    select st_astext(st_point(1,2))

  • The query result is as follows:
    POINT (1 2)

st_pointFromGeoHash

Point st_pointFromGeoHash(String geohash, Int prec)

This function creates the point at the geometric center of the bounding box defined by the Geohash string geohash (base-32 encoded) with the precision of prec bits. For more information about Geohash, see Geohash.

Example:

  • Query command:

    select st_astext(st_pointFromGeoHash('s5zv4',25))

  • The query result is as follows:
    POINT (11.00830078125 21.99462890625)

st_pointFromText

Point st_pointFromText(String wkt)

This function creates a point corresponding to the given WKT representation.

Example:

  • Query command:

    select st_astext(st_pointFromText('POINT (1 2)'))

  • The query result is as follows:
    POINT (1 2)

st_pointFromWKB

Point st_pointFromWKB(Array[Byte] wkb)

This function creates a point corresponding to the given WKB representation.

Example:

  • Query command:

    select st_astext((st_pointFromWKB(st_asBinary(st_geomFromText(location))))) from geotbl where id='6'

  • The query result is as follows:
    POINT (11 22)

st_polygon

Polygon st_polygon(LineString shell)

This function creates a Polygon formed by the given LineString shell, which must be closed.

Example:

  • Query command:

    select st_astext(st_polygon(st_castToLineString(st_geomFromWKT('LINESTRING (30 10, 40 40, 20 40, 10 20, 30 10)'))))

  • The query result is as follows:
    POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))

st_polygonFromText

Polygon st_polygonFromText(String wkt)

This function creates a polygon corresponding to the given WKT representation.

Example:

  • Query command:

    select st_astext(st_polygonFromText('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'))

  • The query result is as follows:
    POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))