Skip to content

[GH-3146] Write GeoParquet 2.0 files with the Parquet GEOMETRY type - #3553

Merged
jiayuasu merged 5 commits into
apache:masterfrom
jiayuasu:feature/geoparquet-2.0-write
Nov 19, 2026
Merged

jiayuasu merged 5 commits into
apache:masterfrom
jiayuasu:feature/geoparquet-2.0-write

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

Setting geoparquet.version to a 2.x version used to change only the version string in the geo metadata. It now writes the layout GeoParquet 2.0 requires, on Spark 4.1 and 4.2:

  • A geometry column carries the GEOMETRY logical type of the Parquet format, and the CRS is a property of that type: absent for OGC:CRS84, authority:code for a CRS with an identifier, inline PROJJSON for a CRS without one, and srid:0 for an unknown CRS. An identifier that names a version of its registry also keeps inline PROJJSON, because authority:code has no place for the version: PROJ writes IAU_2015:49900 as authority IAU, code 49900 and version 2015. A CRS whose authority is named srid or projjson, in any case, stays inline as well, because the Parquet format reads srid:<number> as an SRID and projjson:<key> as a reference to a file metadata key. The geo metadata repeats the CRS as PROJJSON, or null for an unknown CRS.
  • Geometries are stored as ISO WKB, which the logical type requires. The writer does that for every version since [GH-3545] Store ISO WKB in GeoParquet files #3558, so this PR adds no conversion of its own.
  • parquet-java writes geospatial statistics (bounding box and geometry types) for each row group once the column is annotated, so no covering column is generated for a 2.x file. geoparquet.covering still declares a covering column the user provides.
  • The Spark schema metadata of a 2.x file keeps a native geometry type, as Spark's own writer does, so Spark 4.2's spark.read.parquet returns a geometry column for a file written from a native column. A GeometryUDT column is recorded there as binary, as in a 1.x file: Spark's own reader returns its WKB on Spark 4.1 and 4.2, and Spark 4.1 can still open the file. The Parquet column has the GEOMETRY type in both cases, and the geoparquet reader returns a geometry column for both.

Limits of this PR:

  • The default version stays 1.1.0. A version string whose major part is not 2 is written as before. The version is stored without the spaces around it.
  • A native Spark geometry type (Spark 4.2) names the SRID of the column, and the CRS comes from it. A CRS option for such a column must resolve to the same SRID. It is rejected when the identifier that gives the SRID, id or an entry of ids, names a version of its registry: the SRID stands for what the code means today, and a code can mean another CRS in another version. This holds for 1.x writes of a native column as well, which have the same two statements of the CRS in the Spark schema metadata and the geo metadata. Native columns need Spark 4.2, which no Sedona release supports yet. The check is on the identifier only. Sedona does not compare the rest of the definition with the SRID and writes it as given, so a definition of another CRS under a plain EPSG:<code> identifier is not detected. A GeometryUDT column (Spark 4.1) has an SRID on each geometry only, so a 2.x write of such a column needs geoparquet.crs or geoparquet.crs.<column_name> for now. Taking the CRS from the data is the next PR.
  • The geometry types in the row-group statistics come from parquet-java, which skips empty geometries and takes the Z and M dimensions from the first coordinate. They can differ from the stored WKB for an empty geometry and for a geometry whose first Z value is NaN. The bounding boxes and the geo metadata are not affected, and Spark's own writer produces the same statistics.
  • The Parquet library of Spark 3.5 and 4.0 has no GEOMETRY type. A 2.x write is rejected on the driver there, with a message that names geoparquet.version 1.1.0 as the alternative.

Not in this PR: the default version, CRS inference for GeometryUDT columns, geography columns, and reading on Spark 3.5/4.0.

Behaviour of the GeoParquet writer that this PR does not change, for 1.x and 2.x files alike. Each is left to a change of its own:

  • M coordinates are not written. The writer keeps X, Y and Z.
  • The PROJJSON that Sedona generates from an SRID comes from proj4sedona. PROJ does not accept it for every code: EPSG:3857 and EPSG:2154 fail on the conversion method, and EPSG:4979 has two axes. PROJJSON given through geoparquet.crs is written as given.
  • The bbox of a column in the geo metadata has four values, also for a column with Z, and the spatial filter of the reader reads four values.

How was this patch tested?

GeoParquetNativeTypesSuite has a new block that writes 2.x files and reads the footer back: the GEOMETRY annotation and its crs for the default CRS, an EPSG CRS, an unknown CRS and a CRS without an identifier, the CRS taken from the SRID of a native column, the row-group geospatial statistics, ISO WKB for a geometry with Z, the geo metadata, a version given with spaces around it, a 1.1.0 file that keeps plain binary and its covering column, and the rejection on a Parquet library without the geospatial types. ParquetGeospatialTypesTest covers the mapping from a CRS to the crs property, including an identifier with a registry version and an authority named srid or projjson, the rejection of a CRS option on a native column when the identifier that gives the SRID, in id or in ids, names a registry version, and the version rule. NativeGeoParquetCrsSuite in the spark-4.2 module reads Sedona's 2.0 output with Spark's own Parquet reader for SRID 4326, 3857 and 0. It also reads a 1.1 and a 2.0 file whose CRS is PROJJSON without an identifier: schema inference fails on Spark 4.2, and an explicit GeometryUDT schema returns the geometry with SRID 0. GeoParquetNativeTypesSuite does the same for the Parquet fixtures whose CRS cannot be resolved.

The GeoParquet suites pass locally on Spark 4.1 / Scala 2.13, Spark 4.2 / Scala 2.13 (including the GeoParquet suites of the spark-4.2 module) and Spark 3.5 / Scala 2.12.

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation.

…type

Setting geoparquet.version to a 2.x version now writes the layout that
GeoParquet 2.0 requires. The option used to change only the version
string in the file metadata.

A geometry column carries the GEOMETRY logical type, with the CRS as a
property of the type: absent for OGC:CRS84, authority:code for a CRS
with an identifier, inline PROJJSON for one without, and srid:0 for an
unknown CRS. The GeoParquet metadata repeats the CRS as PROJJSON.
Geometries are stored as ISO WKB, which the logical type requires; the
writer used the EWKB flag bit for a Z coordinate. The Parquet library
writes geospatial statistics for each row group once the column is
annotated, so no covering column is generated.

The Spark schema metadata of such a file keeps the native geometry
type, as Spark's own writer does, so that Spark 4.2's Parquet reader
returns a geometry column.

A native Spark geometry type names the SRID of the column. A
GeometryUDT column has an SRID on each geometry only, so for now a 2.x
write of such a column needs geoparquet.crs. The Parquet library of
Spark 3.5 and 4.0 has no GEOMETRY type, and a 2.x write is rejected on
the driver there.

The default version stays 1.1.0. Any version string that is not 2.x is
written as before.
The crs property of a GEOMETRY column was shortened to authority:code
whenever the PROJJSON had an id. That form has no place for the version of
the id, so IAU_2015:49900, which PROJ writes as authority IAU, code 49900
and version 2015, became IAU:49900. Such a CRS is now written as inline
PROJJSON.
…m the version

A CRS whose authority is named srid or projjson was shortened to
srid:<code> or projjson:<code>, which the Parquet format reads as an SRID
or as a reference to a file metadata key. Such a CRS now stays inline
PROJJSON.

A native geometry column rejects a CRS option whose identifier names a
version of its registry. The SRID of the column stands for the current
meaning of the code, and the two cannot be compared.

The version option decided the layout with the spaces around it ignored
but was stored with them. It is now trimmed before it is stored.

The tutorial shows the CRS option a 2.x write needs on Spark 4.1 and
states what Spark's own Parquet reader returns for a file written from a
GeometryUDT column.
@jiayuasu
jiayuasu force-pushed the feature/geoparquet-2.0-write branch from abd6f96 to dc80b46 Compare November 18, 2026 21:05
A native geometry column rejected a CRS option whose id names a version
of its registry, but Sedona also takes the SRID from an entry of ids, and
a version there was let through. The check is now on the identifier that
gives the SRID, in id or in ids. A version on another identifier is no
reason to reject the option.

The error told the user to remove the version, which makes the write
succeed with the same definition. It now asks which CRS the coordinates
are in.

The tutorial states the rule for native columns in the section on CRS
options, since it holds for every GeoParquet version. It no longer lists
ISO WKB as a difference from 1.1 files, and it names the columns that the
reader cannot load on Spark 4.2.
The tutorial said that such a column fails to load on Spark 4.2. It fails
while Sedona infers a native geometry type for it. A schema with Sedona's
own geometry type reads the column, and the geometries have SRID 0. The
tutorial now says so and shows the schema.

The tests read such columns with an explicit schema, from the Parquet
fixtures whose CRS cannot be resolved and from a 2.0 file with PROJJSON
without an identifier.
@jiayuasu
jiayuasu merged commit c706b9e into apache:master Nov 19, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update GeoParquet writer and reader to support GeoParquet 2.0.0

1 participant