Skip to content

[GH-2765] Implement GeoSeries: relate_pattern, contains_properly, build_area, polygonize#2766

Merged
jiayuasu merged 4 commits intomasterfrom
geopandas-tier2-batch-fg
Mar 20, 2026
Merged

[GH-2765] Implement GeoSeries: relate_pattern, contains_properly, build_area, polygonize#2766
jiayuasu merged 4 commits intomasterfrom
geopandas-tier2-batch-fg

Conversation

@jiayuasu
Copy link
Member

@jiayuasu jiayuasu commented Mar 18, 2026

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

Implement 4 GeoSeries functions for the geopandas compatibility module.

Binary predicates:

  • relate_pattern(other, pattern, align) delegates to ST_Relate (3-arg form returning boolean). Tests a DE-9IM pattern against the spatial relationship of two geometries.
  • contains_properly(other, align) delegates to ST_Relate with DE-9IM pattern T**FF*FF*. Sedona has no ST_ContainsProperly, so this uses the equivalent DE-9IM matrix pattern.

Aggregation methods:

  • build_area(node) delegates to ST_Union_Aggr + ST_BuildArea. Aggregate operation matching geopandas semantics: all linework in the GeoSeries is combined, then ST_BuildArea builds polygons from the combined linework, and the result is exploded into individual polygons. When node=True (default), linework is noded via ST_Union_Aggr; when node=False, it is collected via ST_Collect_Agg.
  • polygonize(node, full) delegates to ST_Union_Aggr + ST_Polygonize. Same aggregate pattern as build_area. full=True raises NotImplementedError.

Each function follows the established pattern from #2701, #2710, #2726, and #2732:

  • base.py: Docstring with examples + _delegate_to_geometry_column call
  • geoseries.py: ST function call implementation
  • test_geoseries.py: Unit test with expected values + GeoDataFrame delegation check
  • test_match_geopandas_series.py: Comparison test against real geopandas output

How was this patch tested?

8 new tests (4 unit tests + 4 match tests) all passing locally.

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the documentation.

…a, polygonize

Tier 2 batch F/G: implements 4 remaining Tier 2 GeoSeries functions.

- relate_pattern(other, pattern): delegates to ST_Relate 3-arg form
- contains_properly(other): implemented via ST_Relate with DE-9IM
  pattern T**FF*FF* (no ST_ContainsProperly in Sedona)
- build_area(node=True): aggregate operation matching geopandas semantics;
  collects all linework, builds areas, explodes into polygons
- polygonize(node=True, full=False): aggregate operation matching geopandas
  semantics; collects all linework, polygonizes, explodes results

Includes unit tests and geopandas match tests for all 4 functions.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements four missing GeoSeries methods in Sedona’s GeoPandas-compatibility layer, wiring them to Sedona SQL functions and extending the test suite to validate behavior against real GeoPandas outputs (GH-2765).

Changes:

  • Added GeoSeries aggregation methods build_area() and polygonize() backed by ST_BuildArea / ST_Polygonize with optional noding via ST_Union_Aggr vs ST_Collect_Agg.
  • Added GeoSeries binary predicates relate_pattern() and contains_properly() backed by the 3-arg ST_Relate predicate form.
  • Added unit and “match GeoPandas” tests for the new methods.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
python/sedona/spark/geopandas/base.py Adds GeoSeries API surface + docstrings delegating to the geometry column implementation.
python/sedona/spark/geopandas/geoseries.py Implements Sedona-backed logic for the four new GeoSeries methods.
python/tests/geopandas/test_geoseries.py Adds unit tests for new methods and GeoDataFrame delegation checks.
python/tests/geopandas/test_match_geopandas_series.py Adds comparison tests to ensure Sedona GeoSeries matches GeoPandas outputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…a/polygonize

- Replace driver-side shapely.get_parts() with Spark-side
  explode(ST_Dump(...)) to keep results distributed
- Pass crs=self.crs to returned GeoSeries to preserve SRID/CRS
- Import InternalField at module level
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements four missing GeoSeries APIs in Sedona’s GeoPandas-compatibility layer, mapping them to Sedona SQL functions and adding both unit tests and GeoPandas parity (“match”) tests for correctness.

Changes:

  • Add aggregate GeoSeries methods build_area(node) and polygonize(node, full) backed by ST_(Union/Collect)_Aggr + ST_(BuildArea/Polygonize) and Spark-side ST_Dump exploding.
  • Add binary predicate methods relate_pattern(other, pattern, align) and contains_properly(other, align) backed by ST_Relate(..., pattern).
  • Add unit tests and GeoPandas comparison tests for the above methods.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
python/sedona/spark/geopandas/geoseries.py Implements the four new GeoSeries methods using Sedona SQL functions and Spark-side explosion into polygons.
python/sedona/spark/geopandas/base.py Adds public GeoSeries API surface (docstrings + delegation) for the new methods.
python/tests/geopandas/test_geoseries.py Adds unit tests for build_area/polygonize + contains_properly/relate_pattern.
python/tests/geopandas/test_match_geopandas_series.py Adds GeoPandas parity tests for build_area/polygonize + contains_properly/relate_pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Replace sdf.head(1) is None (never true) with sdf.take(1)
- Single Spark action instead of two
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements four missing GeoSeries methods in Sedona’s GeoPandas-compatibility layer by delegating to corresponding Sedona ST_* functions, and adds unit + “match GeoPandas output” tests to validate behavior.

Changes:

  • Add GeoSeries aggregation methods build_area(node) and polygonize(node, full) backed by ST_Union_Aggr/ST_Collect_Agg + ST_BuildArea/ST_Polygonize and ST_Dump.
  • Add GeoSeries binary predicate methods contains_properly(other, align) and relate_pattern(other, pattern, align) backed by 3-arg ST_Relate.
  • Add unit tests and GeoPandas comparison tests for the new methods.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
python/sedona/spark/geopandas/geoseries.py Implements the Spark-side logic for build_area, polygonize, contains_properly, and relate_pattern.
python/sedona/spark/geopandas/base.py Adds GeoPandas-style public API surface + docstrings delegating to the geometry column implementation.
python/tests/geopandas/test_geoseries.py Adds unit tests for new GeoSeries methods, including empty-series and GeoDataFrame delegation checks.
python/tests/geopandas/test_match_geopandas_series.py Adds GeoPandas output parity tests for build_area, polygonize, contains_properly, and relate_pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jbampton jbampton added sedona-geopandas python Pull requests that update Python code labels Mar 18, 2026
@jiayuasu jiayuasu requested a review from Copilot March 19, 2026 06:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements four missing GeoSeries methods in Sedona’s GeoPandas-compatibility layer by delegating to Sedona SQL functions, with corresponding unit tests and GeoPandas match tests to validate behavior and API parity.

Changes:

  • Added aggregate constructors build_area(node) and polygonize(node, full) backed by ST_Union_Aggr/ST_Collect_Agg + ST_BuildArea/ST_Polygonize and Spark-side ST_Dump explosion.
  • Added binary predicates relate_pattern(other, pattern, align) and contains_properly(other, align) backed by 3-arg ST_Relate.
  • Added/updated unit tests and GeoPandas parity (“match”) tests for the new methods.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
python/sedona/spark/geopandas/base.py Adds public GeoSeries/GeoDataFrame API docstrings and delegation hooks for build_area, polygonize, contains_properly, relate_pattern.
python/sedona/spark/geopandas/geoseries.py Implements Spark execution for the four methods using Sedona ST functions and row-wise/aggregate patterns.
python/tests/geopandas/test_geoseries.py Adds unit tests for build_area, polygonize, contains_properly, relate_pattern.
python/tests/geopandas/test_match_geopandas_series.py Adds GeoPandas comparison tests for build_area, polygonize, contains_properly, relate_pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jiayuasu jiayuasu added this to the sedona-1.9.0 milestone Mar 20, 2026
@jiayuasu jiayuasu merged commit 02f7605 into master Mar 20, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests that update Python code sedona-geopandas

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement GeoSeries: relate_pattern, contains_properly, build_area, polygonize

3 participants