Save as txt files
To save a Spatial DataFrame to some permanent storage such as Hive tables and HDFS, you can simply convert each geometry in the Geometry type column back to a plain String and save the plain DataFrame to wherever you want. Use the following code to convert the Geometry column in a DataFrame back to a WKT string column:ST_AsGeoJSON is also available. We would like to invite you to contribute more functions
Save GeoParquet
WherobotsDB can directly save a DataFrame with the Geometry column as a GeoParquet file. You need to specifygeoparquet as the write format. The Geometry type will be preserved in the GeoParquet file.
CRS Metadata
WherobotsDB supports writing GeoParquet files with custom GeoParquet spec version and crs. The default GeoParquet version is1.1.0. You can set the file version and CRS explicitly:
geoparquet.crs and geoparquet.crs.<column_name> can be one of the following:
"null": Set thecrsfield tonull, declaring an unknown CRS.""(empty string): Omit thecrsfield. This implies that the CRS is OGC:CRS84 for CRS-aware implementations."{...}"(PROJJSON string): Thecrsfield will be set as the PROJJSON object representing the Coordinate Reference System (CRS) of the geometry.
null CRS metadata. Explicit CRS metadata takes precedence; for a column with a fixed native SRID, it must agree with that SRID. The reader restores recognized CRS identifiers as geometry SRIDs.
GeoParquet stores coordinates in (x, y) order, regardless of the axis order declared by the CRS. The reader and writer preserve coordinate order. Use ST_FlipCoordinates to swap the axis order of your geometries.
Write GeoParquet 2.0
On Spark 4.1 and later, setgeoparquet.version to 2.0.0 to write Parquet GEOMETRY logical types and row-group geospatial statistics. The default remains 1.1.0. Spark 3.5 and 4.0 reject the 2.0 option.
All GeoParquet versions now write standard ISO WKB geometry bytes. Three-dimensional type codes differ from the EWKB encoding used by earlier releases; update any consumer that decodes geometry bytes directly and only accepts EWKB. Existing EWKB files remain readable.
For a DataFrame df whose geometry columns contain longitude/latitude coordinates labelled with SRID 4326, use an empty CRS option to declare OGC:CRS84. A fixed native column with SRID 0 must first be labelled with the correct SRID using ST_SetSRID:
geoparquet.crs or geoparquet.crs.<column_name>. On Spark 4.2, a fixed native geometry column can supply its SRID. For a GeoParquet 2.0 write, an explicit identifier for such a column must match that SRID and must not name a registry version. GeoParquet 1.1 retains its existing CRS validation.
GeoParquet 2.0 adds no covering column by default because the Parquet library writes geospatial statistics. You can still declare a covering column that you provide with the options below.
Covering Metadata
WherobotsDB supports writing thecovering field to geometry column metadata. The covering field specifies a bounding box column to help accelerate spatial data retrieval. The bounding box column should be a top-level struct column containing xmin, ymin, xmax, ymax columns. If the DataFrame you are writing contains such columns, you can specify .option("geoparquet.covering.<geometryColumnName>", "<coveringColumnName>") option to write covering metadata to GeoParquet files:
geoparquet.covering option and omit the geometry column name:
Sort then Save GeoParquet
To maximize the performance of WherobotsDB GeoParquet filter pushdown, we suggest that you sort the data by their geohash values (see ST_GeoHash) and then save as a GeoParquet file. An example is as follows:Save as GeoJSON
The GeoJSON data source in WherobotsDB can be used to save a Spatial DataFrame to a single-line JSON file, with geometries written in GeoJSON format.- If there’s a column named “geometry” with geometry type, Sedona will use this column
- Otherwise, Sedona will use the first geometry column found in the root schema
Save to PostGIS
Unfortunately, the Spark SQL JDBC data source doesn’t support creating geometry types in PostGIS using the ‘createTableColumnTypes’ option. Only the Spark built-in types are recognized. This means that you’ll need to manage your PostGIS schema separately from Spark. One way to do this is to create the table with the correct geometry column before writing data to it with Spark. Alternatively, you can write your data to the table using Spark and then manually alter the column to be a geometry type afterward. Postgis uses EWKB to serialize geometries. If you convert your geometries to EWKB format in WherobotsDB you don’t have to do any additional conversion in Postgis.Save to GeoPandas
WherobotsDB DataFrame can be directly converted to a GeoPandas DataFrame.- Python
dataframe_to_arrow method in Sedona.
Save to Snowflake / other data warehouses
The following examples write a DataFrame to a Snowflake table. For the connection options insfOptions, see Load data from Snowflake.
- Scala
- Java
Save to an AWS RDS PostGIS instance
WherobotsDB dataframes can be saved to PostGIS tables hosted in an AWS RDS instance for persistent storage. A map of configuration and context options must be passed to establish connection with the RDS instance. If you’re unable to establish connection with the RDS instance, double check if the instance is accessible by the server running this code. For more information on intra or inter VPC connection with the RDS instance, consult here. The SedonaContext object also needs to be passed aSaveMode parameter using mode which specifies how to handle collisions with existing tables if any.
- Python
- Scala
- Java

