9.6. SparkSQL Functions

The following is a list of the spatial SparkSQL user-defined functions defined by the geomesa-spark-sql module.

9.6.1. Geometry Constructors

9.6.1.1. st_box2DFromGeoHash

Geometry st_box2DFromGeoHash(String geohash, Int prec)

Alias of st_geomFromGeoHash.

9.6.1.2. st_geomFromGeoHash

Geometry st_geomFromGeoHash(String geohash, Int prec)

Returns the Geometry of the bounding box corresponding to the Geohash string geohash (base-32 encoded) with a precision of prec bits. See Geohash for more information on GeoHashes.

9.6.1.3. st_geomFromText

Geometry st_geomFromText(String wkt)

Alias of st_geomFromWKT.

9.6.1.4. st_geomFromWKB

Geometry st_geomFromWKB(Array[Byte] wkb)

Creates a Geometry from the given Well-Known Binary representation (WKB).

9.6.1.5. st_geomFromWKT

Geometry st_geomFromWKT(String wkt)

Creates a Geometry from the given Well-Known Text representation (WKT).

9.6.1.6. st_geometryFromText

Geometry st_geometryFromText(String wkt)

Alias of st_geomFromWKT

9.6.1.7. st_lineFromText

LineString st_lineFromText(String wkt)

Creates a LineString from the given WKT representation.

9.6.1.8. st_mLineFromText

MultiLineString st_mLineFromText(String wkt)

Creates a MultiLineString corresponding to the given WKT representation.

9.6.1.9. st_mPointFromText

MultiPoint st_mPointFromText(String wkt)

Creates a MultiPoint corresponding to the given WKT representation.

9.6.1.10. st_mPolyFromText

MultiPolygon st_mPolyFromText(String wkt)

Creates a MultiPolygon corresponding to the given WKT representation.

9.6.1.11. st_makeBBOX

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

Creates a Geometry representing a bounding box with the given boundaries.

9.6.1.12. st_makeBox2D

Geometry st_makeBox2D(Point lowerLeft, Point upperRight)

Creates a Geometry representing a bounding box defined by the given Points.

9.6.1.13. st_makeLine

LineString st_makeLine(Seq[Point] points)

Creates a LineString using the given sequence of vertices in points.

9.6.1.14. st_makePoint

Point st_makePoint(Double x, Double y)

Creates a Point with an x and y coordinate.

9.6.1.15. st_makePointM

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

Creates a Point with an x, y, and m coordinate.

9.6.1.16. st_makePolygon

Polygon st_makePolygon(LineString shell)

Creates a Polygon formed by the given LineString shell, which must be closed.

9.6.1.17. st_point

Point st_point(Double x, Double y)

Returns a Point with the given coordinate values. This is an OGC alias for st_makePoint.

9.6.1.18. st_pointFromGeoHash

Point st_pointFromGeoHash(String geohash, Int prec)

Return the Point at the geometric center of the bounding box defined by the Geohash string geohash (base-32 encoded) with a precision of prec bits. See Geohash for more information on Geohashes.

9.6.1.19. st_pointFromText

Point st_pointFromText(String wkt)

Creates a Point corresponding to the given WKT representation.

9.6.1.20. st_pointFromWKB

Point st_pointFromWKB(Array[Byte] wkb)

Creates a Point corresponding to the given WKB representation.

9.6.1.21. st_polygon

Polygon st_polygon(LineString shell)

Creates a Polygon formed by the given LineString shell, which must be closed.

9.6.1.22. st_polygonFromText

Polygon st_polygonFromText(String wkt)

Creates a Polygon corresponding to the given WKT representation.

9.6.2. Geometry Accessors

9.6.2.1. st_boundary

Geometry st_boundary(Geometry geom)

Returns the boundary, or an empty geometry of appropriate dimension, if geom is empty.

9.6.2.2. st_coordDim

Int st_coordDim(Geometry geom)

Returns the number of dimensions of the coordinates of Geometry geom.

9.6.2.3. st_dimension

Int st_dimension(Geometry geom)

Returns the inherent number of dimensions of this Geometry object, which must be less than or equal to the coordinate dimension.

9.6.2.4. st_envelope

Geometry st_envelope(Geometry geom)

Returns a Geometry representing the bounding box of geom.

9.6.2.5. st_exteriorRing

LineString st_exteriorRing(Geometry geom)

Returns a LineString representing the exterior ring of the geometry; returns null if the Geometry is not a Polygon.

9.6.2.6. st_geometryN

Int st_geometryN(Geometry geom, Int n)

Returns the n-th Geometry (1-based index) of geom if the Geometry is a GeometryCollection, or geom if it is not.

9.6.2.7. st_interiorRingN

Int st_interiorRingN(Geometry geom, Int n)

Returns the n-th interior LineString ring of the Polygon geom. Returns null if the geometry is not a Polygon or the given n is out of range.

9.6.2.8. st_isClosed

Boolean st_isClosed(Geometry geom)

Returns true if geom is a LineString or MultiLineString and its start and end points are coincident. Returns true for all other Geometry types.

9.6.2.9. st_isCollection

Boolean st_isCollection(Geometry geom)

Returns true if geom is a GeometryCollection.

9.6.2.10. st_isEmpty

Boolean st_isEmpty(Geometry geom)

Returns true if geom is empty.

9.6.2.11. st_isRing

Boolean st_isRing(Geometry geom)

Returns true if geom is a LineString or a MultiLineString and is both closed and simple.

9.6.2.12. st_isSimple

Boolean st_isSimple(Geometry geom)

Returns true if geom has no anomalous geometric points, such as self intersection or self tangency.

9.6.2.13. st_isValid

Boolean st_isValid(Geometry geom)

Returns true if the Geometry is topologically valid according to the OGC SFS specification.

9.6.2.14. st_numGeometries

Int st_numGeometries(Geometry geom)

If geom is a GeometryCollection, returns the number of geometries. For single geometries, returns 1,

9.6.2.15. st_numPoints

Int st_numPoints(Geometry geom)

Returns the number of vertices in Geometry geom.

9.6.2.16. st_pointN

Point st_pointN(Geometry geom, Int n)

If geom is a LineString, returns the n-th vertex of geom as a Point. Negative values are counted backwards from the end of the LineString. Returns null if geom is not a LineString.

9.6.2.17. st_x

Float st_X(Geometry geom)

If geom is a Point, return the X coordinate of that point.

9.6.2.18. st_y

Float st_y(Geometry geom)

If geom is a Point, return the Y coordinate of that point.

9.6.3. Geometry Cast

9.6.3.1. st_castToLineString

LineString st_castToLineString(Geometry g)

Casts Geometry g to a LineString.

9.6.3.2. st_castToPoint

Point st_castToPoint(Geometry g)

Casts Geometry g to a Point.

9.6.3.3. st_castToPolygon

Polygon st_castToPolygon(Geometry g)

Casts Geometry g to a Polygon.

9.6.3.4. st_byteArray

Array[Byte] st_byteArray(String s)

Encodes string s into an array of bytes using the UTF-8 charset.

9.6.4. Geometry Editors

9.6.4.1. st_translate

Geometry st_translate(Geometry geom, Double deltaX, Double deltaY)

Returns the Geometry produced when geom is translated by deltaX and deltaY.

9.6.5. Geometry Outputs

9.6.5.1. st_asBinary

Array[Byte] st_asBinary(Geometry geom)

Returns Geometry geom in WKB representation.

9.6.5.2. st_asGeoJSON

String st_asGeoJSON(Geometry geom)

Returns Geometry geom in GeoJSON representation.

9.6.5.3. st_asLatLonText

String st_asLatLonText(Point p)

Returns a String describing the latitude and longitude of Point p in degrees, minutes, and seconds. (This presumes that the units of the coordinates of p are latitude and longitude.)

9.6.5.4. st_asText

String st_asText(Geometry geom)

Returns Geometry geom in WKT representation.

9.6.5.5. st_geoHash

String st_geoHash(Geometry geom, Int prec)

Returns the Geohash (in base-32 representation) of an interior point of Geometry geom. See Geohash for more information on Geohashes.

9.6.6. Spatial Relationships

9.6.6.1. st_area

Double st_area(Geometry g)

If Geometry g is areal, returns the area of its surface in square units of the coordinate reference system (for example, degrees^2 for EPSG:4326). Returns 0.0 for non-areal geometries (e.g. Points, non-closed LineStrings, etc.).

9.6.6.2. st_centroid

Point st_centroid(Geometry g)

Returns the geometric center of a geometry.

9.6.6.3. st_closestPoint

Point st_closestPoint(Geometry a, Geometry b)

Returns the Point on a that is closest to b. This is the first point of the shortest line.

9.6.6.4. st_contains

Boolean st_contains(Geometry a, Geometry b)

Returns true if and only if no points of b lie in the exterior of a, and at least one point of the interior of b lies in the interior of a.

9.6.6.5. st_covers

Boolean st_covers(Geometry a, Geometry b)

Returns true if no point in Geometry b is outside Geometry a.

9.6.6.6. st_crosses

Boolean st_crosses(Geometry a, Geometry b)

Returns true if the supplied geometries have some, but not all, interior points in common.

9.6.6.7. st_disjoint

Boolean st_disjoint(Geometry a, Geometry b)

Returns true if the geometries do not “spatially intersect”; i.e., they do not share any space together. Equivalent to NOT st_intersects(a, b).

9.6.6.8. st_distance

Double st_distance(Geometry a, Geometry b)

Returns the 2D Cartesian distance between the two geometries in units of the coordinate reference system (e.g. degrees for EPSG:4236).

9.6.6.9. st_distanceSphere

Double st_distanceSphere(Geometry a, Geometry b)

Approximates the minimum distance between two longitude/latitude geometries assuming a spherical earth.

9.6.6.10. st_distanceSpheroid

Double st_distanceSpheroid(Geometry a, Geometry b)

Returns the minimum distance between two longitude/latitude geometries assuming the WGS84 spheroid.

9.6.6.11. st_equals

Boolean st_equals(Geometry a, Geometry b)

Returns true if the given Geometries represent the same logical Geometry. Directionality is ignored.

9.6.6.12. st_intersects

Boolean st_intersects(Geometry a, Geometry b)

Returns true if the geometries spatially intersect in 2D (i.e. share any portion of space). Equivalent to NOT st_disjoint(a, b).

9.6.6.13. st_length

Double st_length(Geometry geom)

Returns the 2D path length of linear geometries, or perimeter of areal geometries, in units of the the coordinate reference system (e.g. degrees for EPSG:4236). Returns 0.0 for other geometry types (e.g. Point).

9.6.6.14. st_lengthSphere

Double st_lengthSphere(LineString line)

Approximates the 2D path length of a LineString geometry using a spherical earth model. The returned length is in units of meters. The approximation is within 0.3% of st_lengthSpheroid and is computationally more efficient.

9.6.6.15. st_lengthSpheroid

Double st_lengthSpheroid(LineString line)

Calculates the 2D path length of a LineString geometry defined with longitude/latitude coordinates on the WGS84 spheroid. The returned length is in units of meters.

9.6.6.16. st_overlaps

Boolean st_overlaps(Geometry a, Geometry b)

Returns true if the geometries have some but not all points in common, are of the same dimension, and the intersection of the interiors of the two geometries has the same dimension as the geometries themselves.

9.6.6.17. st_relate

String st_relate(Geometry a, Geometry b)

Returns the DE-9IM 3x3 interaction matrix pattern describing the dimensionality of the intersections between the interior, boundary and exterior of the two geometries.

9.6.6.18. st_relateBool

Boolean st_relateBool(Geometry a, Geometry b, String mask)

Returns true if the DE-9IM interaction matrix mask mask matches the interaction matrix pattern obtained from st_relate(a, b).

9.6.6.19. st_touches

Boolean st_touches(Geometry a, Geometry b)

Returns true if the geometries have at least one point in common, but their interiors do not intersect.

9.6.6.20. st_within

Boolean st_within(Geometry a, Geometry b)

Returns true if geometry a is completely inside geometry b.

9.6.7. Geometry Processing

9.6.7.1. st_antimeridianSafeGeom

Geometry st_antimeridianSafeGeom(Geometry geom)

If geom spans the antimeridian, attempt to convert the geometry into an equivalent form that is “antimeridian-safe” (i.e. the output geometry is covered by BOX(-180 -90, 180 90)). In certain circumstances, this method may fail, in which case the input geometry will be returned and an error will be logged.

9.6.7.2. st_bufferPoint

Geometry st_bufferPoint(Point p, Double buffer)

Returns a Geometry covering all points within a given radius of Point p, where radius is given in meters.

9.6.7.3. st_convexHull

Geometry st_convexHull(Geometry geom)

Aggregate function. The convex hull of a geometry represents the minimum convex geometry that encloses all geometries geom in the aggregated rows.