After you create a SparkSession object, you can call the read method to load data from the SparkSession object to a DataFrame object. Ganos Spark provides a series of spatio-temporal user-defined functions (UDFs). These UDFs allow you to query spatio-temporal data based on SQL. This topic describes the spatio-temporal UDFs.

## Spatial constructor functions

- ST_GeomFromGeoHash
`Geometry st_geomFromGeoHash(String geohash, Int prec)`

Returns a GeoHash value from a given GeoHash code. The prec parameter specifies the precision of a GeoHash value.

- ST_GeomFromWKT
`Geometry st_geomFromWKT(String wkt)`

Constructs a geometry from a well-known text (WKT) representation.

- ST_GeomFromWKB
`Geometry st_geomFromWKB(Array[Byte] wkb)`

Constructs a geometry from a well-known binary (WKB) representation.

- ST_LineFromText
`LineString st_lineFromText(String wkt)`

Constructs a geometry based on the given points that represent the lower left and upper right corners of the geometry.

- ST_MakeBBOX
`Geometry st_makeBBOX(Double lowerX, Double lowerY, Double upperX, Double upperY)`

Constructs a geometry based on the given boundary coordinates.

- ST_MakePolygon
`Polygon st_makePolygon(LineString shell)`

Constructs a polygon defined by a given shell. The input shell must be a closed linestring.

- ST_MakePoint
`Point st_makePoint(Double x, Double y)`

Constructs a point based on the given x-axis and y-axis.

- ST_MakeLine
`LineString st_makeLine(Seq[Point] points)`

Constructs a linestring based on the given points.

- ST_MakePointM
`Point st_makePointM(Double x, Double y, Double m)`

Constructs a point based on the given x-axis, y-axis, and m-axis.

- ST_MLineFromText
`MultiLineString st_mLineFromText(String wkt)`

Constructs a multi-linestring from a given WKT representation.

- ST_MPolyFromText
`MultiPolygon st_mPolyFromText(String wkt)`

Constructs a multi-polygon from a given WKT representation.

- ST_Point
`Point st_point(Double x, Double y)`

Constructs a point based on the given x-axis and y-axis. This function is equivalent to ST_MakePoint.

- ST_PointFromGeoHash
`Point st_pointFromGeoHash(String geohash, Int prec)`

Returns the point at the geometric center of the bounding box defined by a Base32-encoded GeoHash value. The prec parameter specifies the precision of the GeoHash value.

- ST_PointFromText
`Point st_pointFromText(String wkt)`

- ST_PointFromWKB
`Point st_pointFromWKB(Array[Byte] wkb)`

Constructs a point from a given WKB representation.

- ST_Polygon
`Polygon st_polygon(LineString shell)`

Constructs a polygon from a given linestring.

- ST_PolygonFromText
`Polygon st_polygonFromText(String wkt)`

Constructs a polygon from a given WKT representation.

## Geometry accessor functions

- ST_Boundary
`Geometry st_boundary(Geometry geom)`

Returns the boundary of an ST_Geometry.

- ST_CoordDim
`Int st_coordDim(Geometry geom)`

- ST_Dimension
`Int st_dimension(Geometry geom)`

Processes the ST_Geometry element and returns the dimension of the geometry. The dimension is an integer. This function is used to evaluate the dimension of the geometry.

- ST_Envelope
`Geometry st_envelope(Geometry geom)`

Processes the ST_Geometry element and returns the minimum bounding box for the supplied geometry. This bounding box can be used as an ST_Geometry.

- ST_ExteriorRing
`LineString st_exteriorRing(Geometry geom)`

Returns an ST_LineString that represents the exterior ring of an ST_Polygon geometry.

- ST_GeometryN
`Int st_geometryN(Geometry geom, Int n)`

Returns an ST_LineString that represents the N

^{th}interior ring of a given ST_Polygon geometry. - ST_IsClosed
`Boolean st_isClosed(Geometry geom)`

Returns a value that indicates whether a linestring is closed. TRUE is returned if the linestring is closed.

- ST_IsCollection
`Boolean st_isCollection(Geometry geom)`

Returns a value that indicates whether a geom object is a collection of geometry objects.

- ST_IsEmpty
`Boolean st_isEmpty(Geometry geom)`

Returns a value that indicates whether a geometry is empty. This function is used to verify an ST_Geometry. If the ST_Geometry is empty. 1 (TRUE) is returned. If it is not empty, 0 (FALSE) is returned.

- ST_IsRing
`Boolean st_isRing(Geometry geom)`

Returns a value that indicates whether a given ST_LineString is a ring. If the ST_LineString is a ring, 1 is returned. If the ST_LineString is not a ring, 0 is returned.

- ST_IsSimple
`Boolean st_isSimple(Geometry geom)`

Returns a value that indicates whether a given ST_LineString, ST_MultiPoint, or ST_MultiLineString is simple.

- ST_IsValid
`Boolean st_isValid(Geometry geom)`

Returns a value that indicates whether a given geom object is a valid collection of geometry objects.

- ST_NumGeometries
`Int st_numPoints(Geometry geom)`

Returns the number of geometries of a given type in a geometry collection, such as the number of ST_MultiPoint, ST_MultiLineString, or ST_MultiPolygon geometries. This function returns the count of various elements in a geometry collection.

- ST_NumPoints
`Int st_numPoints(Geometry geom)`

Returns the number of points in a given ST_LineString.

- ST_PointN
`Point st_pointN(Geometry geom, Int n)`

Returns the N

^{th}point in a given ST_LineString. - ST_X
`Float st_X(Geometry geom)`

Returns a double-precision number that indicates the x-axis of a point.

- ST_Y
`Float st_y(Geometry geom)`

Returns a double-precision number that indicates the y-axis of a point.

## Geometry cast functions

- ST_CastToPoint
`Point st_castToPoint(Geometry g)`

Converts a geometry to a point.

- ST_CastToPolygon
`Polygon st_castToPolygon(Geometry g)`

Converts a geometry to a polygon.

- ST_CastToLineString
`LineString st_castToLineString(Geometry g)`

Converts a geometry to a linestring.

- ST_ByteArray
`Array[Byte] st_byteArray(String s)`

Converts a string to a byte array by using UTF-8 encoding.

## Geometry editor functions

`Array[Byte] st_asBinary(Geometry geom)`

Returns a new geometry whose coordinates are translated from deltaX and deltaY.

## Geometry output functions

- ST_AsBinary
`Array[Byte] st_asBinary(Geometry geom)`

Returns the byte array representation of a geometry.

- ST_AsGeoJSON
`String st_asGeoJSON(Geometry geom)`

Returns the GeoJSON representation of a geometry.

- ST_AsLatLonText
`String st_asLatLonText(Point p)`

Returns the Degrees, Minutes, and Seconds representation of a point. The point is projected in latitude and longitude.

- ST_AsText
`String st_asText(Geometry geom)`

Returns the WKT representation of a geometry.

- ST_GeoHash
`String st_geoHash(Geometry geom, Int prec)`

Returns the GeoHash representation of a geometry. The prec argument specifies the precision.

## Spatial relationship functions

- ST_Contains
`Boolean st_contains(Geometry a, Geometry b)`

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

- ST_Covers
`Boolean st_covers(Geometry a, Geometry b)`

Returns true if no point in Geometry B is outside Geometry A.

- ST_Crosses
`Boolean st_crosses(Geometry a, Geometry b)`

Returns true if Geometry A and Geometry B are partially intersected. This means that the geometries have some, but not all interior points in common.

- ST_Disjoint
`Boolean st_disjoint(Geometry a, Geometry b)`

Returns true if Geometry A and Geometry B are disjoint. This function is equivalent to NOT ST_Intersects.

- ST_Equals
`Boolean st_equals(Geometry a, Geometry b)`

Returns true if Geometry A and Geometry B are spatially equal.

- ST_Intersects
`Boolean st_intersects(Geometry a, Geometry b)`

Returns true if Geometry A and Geometry B share any portion of the space (intersected).

- ST_Overlaps
`Boolean st_overlaps(Geometry a, Geometry b)`

Returns true if Geometry A and Geometry B that are equal in size share some points, and the intersection point and the geometries are equal in size.

- ST_Touches
`Boolean st_touches(Geometry a, Geometry b)`

Returns true if Geometry A and Geometry B have at least one point in common, but they do not have any interior intersection.

- ST_Within
`Boolean st_within(Geometry a, Geometry b)`

Returns true if Geometry A completely lies in the interior of Geometry B.

- ST_Relate
`String st_relate(Geometry a, Geometry b)`

Returns the DE-9IM matrix pattern that shows the dimension of intersections between the interior, boundary, and exterior of two geometries.

- ST_RelateBool
`Boolean st_relateBool(Geometry a, Geometry b, String mask)`

Returns true if the mask of the DE-9IM matrix pattern matches that of the DE-9IM matrix pattern returned by ST_Relate (a,b).

- ST_Area
`Double st_area(Geometry g)`

Returns the area of a geometry.

- ST_Centroid
`Point st_centroid(Geometry g)`

Returns the geometric center of a geometry.

- ST_ClosestPoint
`Point st_closestPoint(Geometry a, Geometry b)`

Returns the point on Geometry A that is closest to Geometry B.

- ST_Distance
`Double st_distance(Geometry a, Geometry b)`

Returns the 2-dimensional Cartesian distance between two geometries in projected units, such as EPSG:4236.

- ST_DistanceSphere
`Double st_distanceSphere(Geometry a, Geometry b)`

Returns the minimum distance between two longitude/latitude geometries. It assumes a spherical earth.

- ST_Length
`Double st_length(Geometry geom)`

Returns the 2-dimensional length of a line geometry or the perimeter of a plane geometry, such as EPSG:4236. The units are determined by the spatial reference system of the geometry. It returns 0.0 for other types of geometries, such as point.

- ST_LengthSphere
`Double st_lengthSphere(LineString line)`

Returns the approximate 2-dimensional length of a linestring. It assumes a spherical earth. The returned length is measured in meters. The approximation is within 0.3% of ST_LengthSpheroid and this function increases the computation efficiency.

## Geometry processing functions

- ST_antimeridianSafeGeom
`Geometry st_antimeridianSafeGeom(Geometry geom)`

Attempts to convert the geometry into an equivalent form of "antimeridian-safe" if the geometry spans the antimeridian. For example, the output geometry is covered by BOX (-180 -90,180,90). In some cases, this method may fail. The input geometry will be returned and an error will be logged.

- ST_BufferPoint
`Geometry st_bufferPoint(Point p, Double buffer)`

Returns a geometry that covers all points within a given radius of Point p. The radius is measured in meters.

- ST_ConvexHull
`Geometry st_convexHull(Geometry geom)`

The convex hull of a geometry that represents the minimum convex geometry that encloses all geometries in the aggregated rows. This function is an aggregate function.