GEOMETRY and GEOGRAPHY data types and allows users to use the spatial functions in WherobotsDB for manipulating them. This document describes how to create, write, and query tables with geometry and geography columns.
Readable as geometry by other engines
The geometry type is recorded in the table schema and in the Parquet files, so an Apache Iceberg engine outside Wherobots that supports geospatial types sees a geometry column instead of a binary column it has to decode itself.
One CRS per column, enforced
A column carries exactly one Coordinate Reference System (CRS). A value whose Spatial Reference Identifier (SRID) disagrees with it is rejected instead of being stored under the wrong CRS.
org_catalog throughout this page is an example catalog name. Replace it with the name of the catalog you are writing to.Creating Table with Geometry Column
Besides the primitive types supported by Apache Iceberg, Havasu has aGEOMETRY data type to represent geospatial data. Declare the column with its CRS in parentheses, as an SRID:
- Python
- Scala
- Java
id, with a geometry column in SRID 4326, which is World Geodetic System 1984 (WGS84) longitude and latitude. A geometry column requires a declared CRS: write geometry(4326), not geometry.
Error: bare GEOMETRY in a column definition does not declare a CRS
Error: bare GEOMETRY in a column definition does not declare a CRS
The column was declared as
geometry with no CRS in parentheses. Add the SRID:DESCRIBE command:
- Python
- Scala
- Java
DESCRIBE TABLE shows the type as geometry without the CRS. To see the CRS, run SHOW CREATE TABLE, which renders the column as geom GEOMETRY(4326):
- Python
- Scala
- Java
A geometry column created without a CRS, which is how tables were created before
geometry(<srid>) was available, renders as geom GEOMETRY with no parentheses in SHOW CREATE TABLE. DESCRIBE TABLE shows geometry for both kinds of column. To see a table’s Apache Iceberg format version, run SHOW TBLPROPERTIES org_catalog.test_db.test_table ('format-version').Tables created without a CRS keep working: reads, spatial filter push-down, and every ST_ function behave the same. They do not check the SRID of written values, and other Iceberg engines read the column as binary. Wherobots upgrades the read-only public tables it manages, such as those in the wherobots_open_data catalog, automatically. To upgrade your own tables, see Upgrade Existing Geometry Tables.Writing Data
INSERT INTO
User can insert data into a Havasu table usingINSERT INTO table_name VALUES. Every value has to carry the SRID of the column:
- Python
- Scala
- Java
INSERT INTO table_name SELECT ... to insert result set of a query into the table:
- Python
- Scala
- Java
Matching the column CRS
Geometry constructors such asST_GeomFromText and ST_Point return SRID 0, which is a distinct CRS rather than “unset”, so a geometry(4326) column rejects it. Which function you need depends on the SRID your values already carry:
ST_SetSRID relabels without touching the coordinates. Applying it to metre coordinates declares them as longitude and latitude, which puts the data in the wrong place. Use ST_Transform when the coordinates are in another CRS.
Error: Cannot write geometry with SRID ...
Error: Cannot write geometry with SRID ...
A value disagrees with the column CRS. The message names the fix:
Writing DataFrame to Havasu table
User can write a DataFrame containing geometry data to a Havasu table. The same SRID rule applies to the DataFrame’s values:- Python
- Scala
- Java
INSERT INTO table_name SELECT ... statement.
Creating a table from a query or a DataFrame
CREATE TABLE ... AS SELECT and writeTo(...).create() create a table from the result of a query or a DataFrame. When the geometry comes from a geometry(<srid>) column read from a table, the new column has the same declared CRS. To choose the CRS of the new column yourself, for example for a geometry computed with an ST_ function, create the table with CREATE TABLE first and then write to it with INSERT INTO ... SELECT or writeTo(...).append(), as shown in Working with Geometry Data.
Updating data in Havasu table
Havasu supports UPDATE queries that update matching rows in tables. Update queries accept a filter to match rows to update. Spatial filters are also supported in Havasu.- Python
- Scala
- Java
Deleting data from Havasu table
Havasu supports DELETE FROM queries to remove data from tables. Delete queries accept a filter to match rows to delete. Spatial filters are also supported in Havasu.- Python
- Scala
- Java
Merging DataFrame into Havasu table using MERGE INTO
Havasu supports MERGE INTO by rewriting data files that contain rows that need to be updated in an overwrite commit.
The syntax is identical to the open source Apache Iceberg, please refer to Apache Iceberg - MERGE INTO for more information.
Querying Data
User can load data from a Havasu table usingsedona.table(...):
- Python
- Scala
- Java
- Python
- Scala
- Java
- Python
- Scala
- Java
- Python
- Scala
- Java
.format("havasu.iceberg"), this will load an isolated table reference that will not automatically refresh tables used by queries.
- Python
- Scala
- Java
Working with Geometry Data
User can use anyST_ functions provided by WherobotsDB to manipulate the data in a geometry column. For example, user can use ST_Buffer to create a buffer around the geometry column:
- Python
- Scala
- Java
ST_Buffer keeps the SRID of its input, so the buffered values match a geometry(4326) column:
- Python
- Scala
- Java
writeTo(...).append() on the resulting DataFrame of the query:
- Python
- Scala
- Java
Geography Columns
GEOGRAPHY(<srid>) interprets coordinates on a sphere rather than a plane, so ST_Distance, ST_Area, and ST_Length return spherical results in meters without projecting first.
ST_GeogFromWKT without the SRID argument, and stores it under the column CRS. There is no cast from GEOMETRY to GEOGRAPHY; use ST_GeomToGeography to convert, and ST_GeogToGeometry in the other direction. See the geography function reference for the full list.

