Skip to content

GeoPandas: Preserve CRS metadata for empty geometry results #3189

Description

@jiayuasu

Expected behavior

Distributed GeoSeries and GeoDataFrame objects should preserve explicitly
assigned CRS metadata when their geometry rows are empty, all null, or carry
SRID 0.

Explicit set_crs values should take precedence over inherited lineage
metadata. Copies, GeoPandas conversion, and construction from an existing
geometry column should retain that metadata, while switching to a different
active geometry column must not leak the previous column's CRS.

Actual behavior

Sedona normally derives CRS from the SRID stored in geometry rows. Empty and
all-null results have no non-null geometry from which to recover that SRID, so
CRS can be lost after construction, copy, conversion, or a distributed
operation that removes every row.

The same fallback mechanism is currently being introduced independently by
#3183, #3184, and #3185. Keeping it in those feature PRs duplicates shared
state-management code and creates avoidable merge conflicts.

Steps to reproduce the problem

from sedona.spark.geopandas import GeoDataFrame, GeoSeries
import pyspark.pandas as ps

series = GeoSeries([None], name="shape", crs="EPSG:4326")
with ps.option_context("compute.ops_on_diff_frames", True):
    frame = GeoDataFrame({"value": [1]}).set_geometry(series)

assert series.crs == "EPSG:4326"
assert frame.crs == "EPSG:4326"
assert frame.copy().crs == "EPSG:4326"
assert frame.to_geopandas().crs == "EPSG:4326"

The shared implementation should also cover zero-row derived results,
duplicate-index construction, explicit CRS removal or replacement, deep
GeoSeries copies, and active-geometry switches.

Settings

Sedona version = 1.9.1-SNAPSHOT

Apache Spark version = 3.4+

API type = Python GeoPandas API

Python version = 3.8+

Environment = Standalone

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions