Geospatial
The geospatial module of the SDK can help users do geospatial analysis in Databricks.
Registering Sedona module
Registration is only required when using the Apache Sedona Python API (e.g. GeoDataFrame.pipe(spark.createDataFrame)). For more information on usage, you may refer to this page.
You can find more information of Sedona related functions here.
- Function signature
- Sample usage
def register_sedona() -> None:
"""
Returns
-------
None
"""
from datahive.geospatial import register_sedona
register_sedona()
Convert GeoJSON to Dataframe
- Function signature
- Sample usage
def read_geojson_raw(geojson_str, output_type="spark"):
"""
Function to transform raw geojson string into dataframe.
Geojson format: https://datatracker.ietf.org/doc/html/rfc7946#section-1.5
Parameters
----------
geojson_str : str
String representation of geojson
output_type : str, optional
`spark` or `geopandas` dataframe (default is spark)
Returns
-------
dataframe
Geojson in table format. `geometry` column in WKT format.
"""
from datahive.geospatial import read_geojson_raw
ion_geojson = """
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
103.83090734481812,
1.3038701802027275
],
[
103.83163958787918,
1.3033928705724311
],
[
103.83213311433792,
1.3030094138937842
],
[
103.83267492055893,
1.3036207993397597
],
[
103.83268296718596,
1.303679792664403
],
[
103.83271515369415,
1.3037361044730127
],
[
103.83260250091551,
1.3039264920070623
],
[
103.83283317089081,
1.3044198906198512
],
[
103.83183807134628,
1.3049830084836378
],
[
103.83090734481812,
1.3038701802027275
]
]
]
}
}
]
}
"""
ion_sparkdf = read_geojson_raw(geojson_str=ion_geojson)