Skip to content

[GH-3182] GeoPandas: Add point-only inner sjoin_nearest - #3184

Merged
jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/geopandas-sjoin-nearest
Sep 24, 2026
Merged

jiayuasu merged 1 commit into
apache:masterfrom
jiayuasu:feature/geopandas-sjoin-nearest

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Yes, I have read the Contributor Rules and Contributor Development Guide.

Is this PR related to a ticket?

Partially addresses #3182 with an initial supported subset.

What changes were proposed in this PR?

Add sjoin_nearest to the top-level GeoPandas API, tools, and GeoDataFrame for distributed point-only inner joins. The implementation uses existing ST_KNN(left, right, 1, false) and the unchanged Sedona KNN engine.

Supported behavior:

  • how="inner", exclusive=False, and default left / right suffixes.
  • Optional new distance_col and positive finite max_distance.
  • Unique flat string columns and single-level indexes, including duplicate index values.
  • Left active geometry, per-column CRS metadata, left index, right index and attributes.
  • Null and empty geometries do not match; empty results preserve their schema and CRS.

Unsupported options, non-point non-empty geometries, and ambiguous output columns fail explicitly. Distances are planar and ignore Z. Output row order is unspecified.

Tie behavior follows spark.sedona.join.knn.includeTieBreakers, without changing the session setting. Its default false selects one nearest candidate with unspecified tie selection. With true, equidistant candidates are included, but existing Sedona behavior can omit distinct rows with identical candidate geometries. This API does not promise GeoPandas' complete all-row tie behavior.

max_distance filters the nearest results; it does not prune the KNN search. A non-deterministic partition-ID guard keeps that filter above KNN execution, preventing Spark from pushing it into a join where existing planning can select a distance join or discard the condition in a broadcast KNN plan. The extra-condition planner bug is tracked in #3398. Input validation collects only scalar summaries; geometries remain distributed.

How was this patch tested?

  • Spark 4.1.2 / Scala 2.13: nearest and existing spatial-join suites, 59 passed.
  • Spark 3.5.4 / Scala 2.12: fresh shaded JAR build and the same suites, 59 passed.
  • Tests cover regular KNN and both broadcast directions, session ties on/off, cutoff boundaries, duplicate indexes and query geometries, null/empty inputs, named-index suffixes, special column names, unsupported options, and active/secondary geometry CRS on empty outputs.
  • Repository pre-commit checks.

Did this PR include necessary documentation updates?

Yes. English and Chinese GeoPandas tutorials describe the supported subset and tie semantics. The 2.0.0 release notes include the new API.

@jiayuasu
jiayuasu marked this pull request as draft July 28, 2026 02:46
@jiayuasu jiayuasu mentioned this pull request Aug 12, 2026
66 of 77 tasks
@jiayuasu jiayuasu changed the title [GH-3182] GeoPandas: Implement distributed sjoin_nearest [GH-3182] GeoPandas: Add point-only inner sjoin_nearest Sep 24, 2026
Implement distributed point nearest joins using existing ST_KNN behavior,
with optional distance output and a maximum-distance result filter.
Preserve geometry CRS metadata and document the supported API subset.
Add GeoPandas comparisons and regular/broadcast KNN execution coverage.
@jiayuasu
jiayuasu force-pushed the feature/geopandas-sjoin-nearest branch from 14bb592 to 43d8733 Compare September 24, 2026 07:46
@jiayuasu jiayuasu linked an issue Sep 24, 2026 that may be closed by this pull request
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Sep 24, 2026
@jiayuasu
jiayuasu marked this pull request as ready for review September 24, 2026 08:03
@jiayuasu
jiayuasu merged commit 969e52d into apache:master Sep 24, 2026
34 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.

GeoPandas: implement distributed sjoin_nearest

1 participant