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

Spatial constructor functions

  • ST_GeomFromGeoHash
    Geometry st_geomFromGeoHash(String geohash, Int prec)

    Returns a GeoHash value from a given GeoHash code. The prec argument specifies the precision of the 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 defined by lowerLeft and upperRight.

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

    Constructs a geometry defined by 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 defined by the given X-coordinate and Y-coordinate.

  • ST_MakeLine
    LineString st_makeLine(Seq[Point] points)

    Constructs a linestring defined by the given point objects.

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

    Constructs a point defined by the given X-coordinate, Y-coordinate, and M-coordinate.

  • ST_MLineFromText
    MultiLineString st_mLineFromText(String wkt)

    Constructs a multi-linestring defined by a given WKT representation.

  • ST_MPolyFromText
    MultiPolygon st_mPolyFromText(String wkt)

    Constructs a multi-polygon defined by a given WKT representation.

  • ST_Point
    Point st_point(Double x, Double y)

    Constructs a point defined by the given X-coordinate and Y-coordinate. This function is similar 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 argument 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 a 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, which 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, as a geometry.

  • ST_ExteriorRing
    LineString st_exteriorRing(Geometry geom)

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

  • ST_GeometryN
    Int st_geometryN(Geometry geom, Int n)

    Returns an ST_LineString that represents the Nth 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 the 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. Value 1 (TRUE) is returned if the geometry is empty and value 0 (FALSE) is returned if it is not empty.

  • ST_IsRing
    Boolean st_isRing(Geometry geom)

    Returns a value that indicates whether a given ST_LineString is a ring. Value 1 is returned if the ST_LineString is a ring and value 0 is returned if it is not a ring.

  • 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.

  • 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 Nth point in a given ST_LineString.

  • ST_X
    Float st_X(Geometry geom)

    Returns a double-precision number that indicates the X-coordinate of a point.

  • ST_Y
    Float st_y(Geometry geom)

    Returns a double-precision number that indicates the Y-coordinate 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

ST_Translate
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 here 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, and the input geometry will be returned and then 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)

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