2017-11-06 1 views
1

Ich möchte eine Reihe von Standorten mit Open Street Map geokodieren (nominatim Paket).R - Verknüpfen Sie das Ergebnis der Open-Street-Map-Geokodierung mit Eingabedaten

Ein Problem tritt auf, wenn Sie Standorte haben, die nicht in Längen-/Breitengrad übersetzt werden. Tatsächlich gibt es keine Möglichkeit, den Eingabevektor und den Ausgabedatenrahmen zu verknüpfen. Hier

ein Beispiel:

library(nominatim) 

Location <- c("Washington", "Seattle", "Fzoieozepfvfmd", "Houston") 
LonLat <- osm_geocode(Location, key = "enter your own OSM key") 

View(LonLat) 
# 3 observations only while there is 4 locations in the input vector 
# no key to join the output data frame with the input vector 

Die Ausgangsdatenrahmen LonLat:

structure(list(place_id = c("2661769953", "151183715", "2691789858" 
), licence = c("Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", 
"Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright", 
"Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" 
), osm_type = c("relation", "relation", "relation"), osm_id = c("5396194", 
"237385", "2688911"), lat = c(38.8949549, 47.6038321, 29.7589382 
), lon = c(-77.0366456, -122.3300624, -95.3676974), display_name = c("Washington, District of Columbia, United States of America", 
"Seattle, King County, Washington, United States of America", 
"Houston, Harris County, Texas, United States of America"), class = c("place", 
"place", "place"), type = c("city", "city", "city"), importance = c(0.82665678197628, 
0.80154398538761, 0.80088985079359), icon = c("http://ip-10-98-161-100.mq-us-east-1.ec2.aolcloud.net:8000/nominatim/v1/images/mapicons/poi_place_city.p.20.png", 
"http://ip-10-98-174-147.mq-us-east-1.ec2.aolcloud.net:8000/nominatim/v1/images/mapicons/poi_place_city.p.20.png", 
"http://ip-10-98-183-183.mq-us-east-1.ec2.aolcloud.net:8000/nominatim/v1/images/mapicons/poi_place_city.p.20.png" 
), bbox_left = c(38.7916303, 47.4810022, 29.5370705), bbox_top = c(38.9958524, 
47.7341357, 30.1103506), bbox_right = c(-77.1197662, -122.4596959, 
-95.9097418), bbox_bottom = c(-76.9093659, -122.2244329, -95.0120524 
)), .Names = c("place_id", "licence", "osm_type", "osm_id", "lat", 
"lon", "display_name", "class", "type", "importance", "icon", 
"bbox_left", "bbox_top", "bbox_right", "bbox_bottom"), row.names = c(NA, 
-3L), class = "data.frame") 
+0

Können Sie hier das Ergebnis von 'LonLat' anzeigen? –

+0

Ich habe den Ausgabedatenrahmen in der Frage mit der Funktion 'dput()' hinzugefügt. – Kumpelka

Antwort

2

Sie können versuchen, durch die Orte zu gehen lapply() mit und lat und lon Werte erhalten von der tibble aus zurück osm_geocode():

LonLat <- data.table::rbindlist(
    lapply(Location, function(x, key) { 

    lon_lat <- osm_geocode(x, key = key) 

    lat <- ifelse(is.null(lon_lat$lat), NA, lon_lat$lat) 
    lon <- ifelse(is.null(lon_lat$lon), NA, lon_lat$lon) 

    return(list(Location = x, Lat = lat, Lon = lon)) 

    } , key = "enter your key")) 

Diese Rückkehr:

  Location Lat Lon 
1:  Washington NA NA 
2:  Seattle NA NA 
3: Fzoieozepfvfmd NA NA 
4:  Houston NA NA 

Hinweis: NA s vorhanden sind, weil ich keine richtige API-Schlüssel angegeben haben.

+1

Genau das, was ich brauchte, danke. – Kumpelka

Verwandte Themen