Sf: st_nearest binary predicate?

Created on 28 Feb 2019  路  3Comments  路  Source: r-spatial/sf

Would be a good addition for use in st_join and looks like it can rely on st_nearest_feature.

Most helpful comment

You can already use st_nearest_feature in st_join.

library(sf)
library(mapview)

st_join(breweries, franconia, join = st_nearest_feature)

Simple feature collection with 225 features and 14 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: 9.462785 ymin: 48.90074 xmax: 11.93539 ymax: 50.44162
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
First 10 features:
                                                 brewery                    address zipcode       village  state founded number.of.types number.seasonal.beers NUTS_ID
1                                     Brauerei Rittmayer     Aischer Hauptstrasse 5   91325     Adelsdorf Bayern    1422               2                     1   DE257
2                                       Brauhaus Leikeim            Gewerbegebiet 4   96264 Altenkunstadt Bayern    1887              11                     1   DE24C
3  Ammerndorfer Bier Dorn-Braeu H. Murmann GmbH & Co. KG             Marktplatz 1-2   90614    Ammerndorf Bayern    1730              10                     0   DE258
4                          Wittelsbacher Turm Braeu GmbH       Wittelsbacher Turm 1   97688 Bad Kissingen Bayern      NA               6                     0   DE265
5                                    Arnsteiner Brauerei    Schweinfurter Strasse 9   97450      Arnstein Bayern    1885               5                     0   DE26A
6                                     Aufsesser Brauerei                 Im Tal 70b   91347       Aufsess Bayern    1886               7                     0   DE246
7                                       Brauhaus Doebler                Kornmarkt 6   91438 Bad Windsheim Bayern    1867               8                     0   DE25A
8                                     Ambraeusianum GmbH      Dominikanerstrasse 10   96049       Bamberg Bayern    2004               3                     3   DE241
9                         Brauerei Faessla GmbH & Co. KG Obere Koenigsstrasse 19-21   96052       Bamberg Bayern    1694               5                     0   DE241
10        Kaiserdom Specialitaeten Brauerei GmbH Bamberg       Breitaeckerstrasse 9   96049       Bamberg Bayern    1718               5                     1   DE241
    SHAPE_AREA SHAPE_LEN CNTR_CODE                          NAME_ASCI      district                  geometry
1  0.070179547 2.8476550        DE                 Erlangen-Hochstadt Mittelfranken POINT (10.88922 49.71979)
2  0.065241246 1.8021299        DE                        Lichtenfels   Oberfranken POINT (11.23873 50.12579)
3  0.038202003 1.0959424        DE                   Furth, Landkreis Mittelfranken  POINT (10.85194 49.4208)
4  0.143463358 2.6788579        DE                      Bad Kissingen  Unterfranken POINT (10.07837 50.16197)
5  0.165801021 3.0223493        DE                      Main-Spessart  Unterfranken   POINT (9.97323 49.9772)
6  0.159489736 3.6242023        DE                Bayreuth, Landkreis   Oberfranken POINT (11.22899 49.88405)
7  0.157685336 2.7758529        DE Neustadt a. d. Aisch-Bad Windsheim Mittelfranken  POINT (10.41602 49.5021)
8  0.006736012 0.3926225        DE          Bamberg, Kreisfreie Stadt   Oberfranken POINT (10.88484 49.89223)
9  0.006736012 0.3926225        DE          Bamberg, Kreisfreie Stadt   Oberfranken POINT (10.89281 49.89734)
10 0.006736012 0.3926225        DE          Bamberg, Kreisfreie Stadt   Oberfranken POINT (10.85234 49.90443)

Is there anything else that's missing?

All 3 comments

You can already use st_nearest_feature in st_join.

library(sf)
library(mapview)

st_join(breweries, franconia, join = st_nearest_feature)

Simple feature collection with 225 features and 14 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: 9.462785 ymin: 48.90074 xmax: 11.93539 ymax: 50.44162
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
First 10 features:
                                                 brewery                    address zipcode       village  state founded number.of.types number.seasonal.beers NUTS_ID
1                                     Brauerei Rittmayer     Aischer Hauptstrasse 5   91325     Adelsdorf Bayern    1422               2                     1   DE257
2                                       Brauhaus Leikeim            Gewerbegebiet 4   96264 Altenkunstadt Bayern    1887              11                     1   DE24C
3  Ammerndorfer Bier Dorn-Braeu H. Murmann GmbH & Co. KG             Marktplatz 1-2   90614    Ammerndorf Bayern    1730              10                     0   DE258
4                          Wittelsbacher Turm Braeu GmbH       Wittelsbacher Turm 1   97688 Bad Kissingen Bayern      NA               6                     0   DE265
5                                    Arnsteiner Brauerei    Schweinfurter Strasse 9   97450      Arnstein Bayern    1885               5                     0   DE26A
6                                     Aufsesser Brauerei                 Im Tal 70b   91347       Aufsess Bayern    1886               7                     0   DE246
7                                       Brauhaus Doebler                Kornmarkt 6   91438 Bad Windsheim Bayern    1867               8                     0   DE25A
8                                     Ambraeusianum GmbH      Dominikanerstrasse 10   96049       Bamberg Bayern    2004               3                     3   DE241
9                         Brauerei Faessla GmbH & Co. KG Obere Koenigsstrasse 19-21   96052       Bamberg Bayern    1694               5                     0   DE241
10        Kaiserdom Specialitaeten Brauerei GmbH Bamberg       Breitaeckerstrasse 9   96049       Bamberg Bayern    1718               5                     1   DE241
    SHAPE_AREA SHAPE_LEN CNTR_CODE                          NAME_ASCI      district                  geometry
1  0.070179547 2.8476550        DE                 Erlangen-Hochstadt Mittelfranken POINT (10.88922 49.71979)
2  0.065241246 1.8021299        DE                        Lichtenfels   Oberfranken POINT (11.23873 50.12579)
3  0.038202003 1.0959424        DE                   Furth, Landkreis Mittelfranken  POINT (10.85194 49.4208)
4  0.143463358 2.6788579        DE                      Bad Kissingen  Unterfranken POINT (10.07837 50.16197)
5  0.165801021 3.0223493        DE                      Main-Spessart  Unterfranken   POINT (9.97323 49.9772)
6  0.159489736 3.6242023        DE                Bayreuth, Landkreis   Oberfranken POINT (11.22899 49.88405)
7  0.157685336 2.7758529        DE Neustadt a. d. Aisch-Bad Windsheim Mittelfranken  POINT (10.41602 49.5021)
8  0.006736012 0.3926225        DE          Bamberg, Kreisfreie Stadt   Oberfranken POINT (10.88484 49.89223)
9  0.006736012 0.3926225        DE          Bamberg, Kreisfreie Stadt   Oberfranken POINT (10.89281 49.89734)
10 0.006736012 0.3926225        DE          Bamberg, Kreisfreie Stadt   Oberfranken POINT (10.85234 49.90443)

Is there anything else that's missing?

That works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ekarsten picture ekarsten  路  4Comments

adrfantini picture adrfantini  路  4Comments

dkyleward picture dkyleward  路  4Comments

duleise picture duleise  路  3Comments

kendonB picture kendonB  路  3Comments