Nearest Join
Joins to each feature the attributes of the nearest feature in another layer, optionally with the distance.
Pitfall. Distances in a geographic CRS are in degrees.
Pitfall. Ties (two features at the same distance) give two rows in some engines and one in others.
| Also called | Join By Nearest, Near, closest feature join, sjoin_nearest, Spatial Join (closest) |
|---|---|
| Group | vector/joins |
| Checks | crs.agreement, crs.measure, join.unmatched |
| Pitfalls | 2 listed above |
| Columbus tool | Not stated |
| Notes | Not stated |
| Status | active |
| Broader | Not stated |
| Narrower | Not stated |
| Related |
Parameters
| Name | Type | Required | Default | Values | Note |
|---|---|---|---|---|---|
max_distance | length | no | Not stated | Not stated | Only join features within this distance, in the CRS's units. |
distance_field | string | no | Not stated | Not stated | Name of a new attribute holding the distance. |
how | enum | no | left | left, inner | left keeps features with no match within max_distance. |
Inputs and outputs
| Direction | Name | Type | Geometry | Note |
|---|---|---|---|---|
| Input | left | vector | Not stated | Not stated |
| Input | right | vector | Not stated | Not stated |
| Output | output | vector | Not stated | Not stated |
In each engine
| Engine | Tool | Parameters | Differences |
|---|---|---|---|
geopandas | geopandas.GeoDataFrame.sjoin_nearest |
|
|
geopandas | geopandas.sjoin_nearest |
|
|
grass | v.distance |
|
|
qgis | native:joinbynearest |
|
Preset: {"NEIGHBORS":1} |
sf | sf::st_nearest_feature |
|
|