Geometry constructors

st_point

st_point(x, y)

Create a new Mosaic Point geometry from two DoubleType values.

Parameters:
  • x (Column: DoubleType) – x coordinate (DoubleType)

  • y (Column: DoubleType) – y coordinate (DoubleType)

Return type:

Column: InternalGeometryType

Example:

df = spark.createDataFrame([{'lon': 30., 'lat': 10.}])
df.select(st_point('lon', 'lat').alias('point_geom')).show(1, False)
+---------------------------+
|point_geom                 |
+---------------------------+
|{1, [[[30.0, 10.0]]], [[]]}|
+---------------------------+

st_makeline

st_makeline(col)

Create a new Mosaic LineString geometry from an Array of Mosaic Points.

Parameters:

col (Column: ArrayType[InternalGeometryType]) – Point array

Return type:

Column: InternalGeometryType

Example:

df = spark.createDataFrame([
    {'lon': 30., 'lat': 10.},
    {'lon': 10., 'lat': 30.},
    {'lon': 40., 'lat': 40.}
    ])
(
    df.select(st_point('lon', 'lat').alias('point_geom'))
    .groupBy()
    .agg(collect_list('point_geom').alias('point_array'))
    .select(st_makeline('point_array').alias('line_geom'))
).show(1, False)
+-------------------------------------------------------+
|line_geom                                              |
+-------------------------------------------------------+
|{3, [[[40.0, 40.0], [30.0, 10.0], [10.0, 30.0]]], [[]]}|
+-------------------------------------------------------+

st_makepolygon

st_makepolygon(col)

Create a new Mosaic Polygon geometry from a closed LineString.

Parameters:

col (Column: InternalGeometryType) – closed LineString

Return type:

Column: InternalGeometryType

Example:

df = spark.createDataFrame([{'wkt': 'LINESTRING (30 10, 40 40, 20 40, 10 20, 30 10)'}])
df.select(st_makepolygon(st_geomfromwkt('wkt')).alias('polygon_geom')).show(1, False)
+-----------------------------------------------------------------------------------+
|polygon_geom                                                                       |
+-----------------------------------------------------------------------------------+
|{5, [[[30.0, 10.0], [40.0, 40.0], [20.0, 40.0], [10.0, 20.0], [30.0, 10.0]]], [[]]}|
+-----------------------------------------------------------------------------------+

st_geomfromwkt

st_geomfromwkt(col)

Create a new Mosaic geometry from Well-known Text.

Parameters:

col (Column: StringType) – Well-known Text Geometry

Return type:

Column: InternalGeometryType

Example:

df = spark.createDataFrame([{'wkt': 'LINESTRING (30 10, 40 40, 20 40, 10 20, 30 10)'}])
df.select(st_geomfromwkt('wkt')).show(1, False)
+-------------------------------------------------------------------------------------+
|convert_to(wkt)                                                                      |
+-------------------------------------------------------------------------------------+
|{3, [[[30.0, 10.0], [40.0, 40.0], [20.0, 40.0], [10.0, 20.0], [30.0, 10.0]]], [[[]]]}|
+-------------------------------------------------------------------------------------+

st_geomfromwkb

st_geomfromwkb(col)

Create a new Mosaic geometry from Well-known Binary.

Parameters:

col (Column: BinaryType) – Well-known Binary Geometry

Return type:

Column: InternalGeometryType

Example:

import binascii

hex = '0000000001C052F1F0ED3D859D4041983D46B26BF8'
binary = binascii.unhexlify(hex)
df = spark.createDataFrame([{'wkb': binary}])
df.select(st_geomfromwkb('wkb')).show(1, False)
+--------------------------------------+
|convert_to(wkb)                       |
+--------------------------------------+
|{1, [[[-75.78033, 35.18937]]], [[[]]]}|
+--------------------------------------+

st_geomfromgeojson

st_geomfromgeojson(col)

Create a new Mosaic geometry from GeoJSON.

Parameters:

col (Column: StringType) – GeoJSON Geometry

Return type:

Column: InternalGeometryType

Example:

import json

geojson_dict = {
        "type":"Point",
        "coordinates":[
            -75.78033,
            35.18937
        ],
        "crs":{
            "type":"name",
            "properties":{
                "name":"EPSG:4326"
            }
        }
    }
df = spark.createDataFrame([{'json': json.dumps(geojson_dict)}])
df.select(st_geomfromgeojson('json')).show(1, False)
+--------------------------------------+
|convert_to(as_json(json))             |
+--------------------------------------+
|{1, [[[-75.78033, 35.18937]]], [[[]]]}|
+--------------------------------------+