question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sjoin one-to-one option if intersection overlaps several polygon

See original GitHub issue

I have a grid poly (qk) which I want to join attributes from admin boundaries (ph). For each poly in qk I want to take attributes of the first located feature in ph I (one-to-one).

I can’t find an ption in sjoin to do this, instead it always (one-to-many).

See example code here and viz in QGIS below:

Screenshot 2020-01-16 19 43 56

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
brendan-wardcommented, Jul 21, 2022

@cyrchi you can first do sjoin_nearest then apply additional predicates to the pairs of geometries from your source and target data frames to further filter the results to remove those that only intersect at the boundary, or use a centroid (or some other representative geometry) of your source and target geometries and take the one with the least distance per source (left) geometry.

We’d have to develop additional functionality at a lower level (i.e., shapely) to get at the concept of joining to nearest but not overlapping geometries, if that is a common activity to be doing with sjoin_nearest.

1reaction
Greenallcommented, Feb 9, 2022

@martinfleis Looking at your implementation I’m sure it is faster. Was not aware of query_bulk.

notice you don’t do any CRS transformation within the method but guess that’s actually the right call since if you are not using projected CRS then geopandas will raise anyway.

Tobler looks like a useful lib - wasn’t aware of it before - thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spatially joining only features by largest overlap with sjoin in ...
Therefore I want to ask how to filter out and restrict to a single area, like selecting only output file entries with the...
Read more >
Spatial Join (Analysis)—ArcGIS Pro | Documentation
Join one to one—If multiple join features are found that have the same spatial ... For this option, the target features can only...
Read more >
Spatial Join's hidden trick or how to transfer attribute values in ...
Run the tool. The resulting dataset should display zones that each of the property boundary polygons intersect, stored as text values separated ...
Read more >
How Spatial Join Works in GIS - GISGeography
The spatial join tool inserts the columns from one feature table to another based on location or proximity. It can affix one or...
Read more >
Spatial Join gives <Null> to joined features - Esri Community
Join one to one. Intersect / within etc. all give same result. Join_count gives me 0. Also, when I use the polygon data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found