Geocodifica in lotti in R


Risposte:


18

Le condizioni dell'API cambiano costantemente, ma ora dovrebbe funzionare.

OSM :

devtools::install_github("hrbrmstr/nominatim")
library(nominatim)
b1 <- osm_geocode("Berlin, Germany")
b1[c("lat", "lon")]

Yahoo :

devtools::install_github("trestletech/rydn")
library(rydn)
options(RYDN_KEY="yourAPIkey", RYDN_SECRET="yourSecret")
b2 <- find_place("Berlin, Germany")  
b2[c("latitude", "longitude")]

Bing : taRifx.geo (funziona con Google) e presumibilmente funziona con Bing, ma non sono mai riuscito a farlo funzionare, quindi ho scritto la mia funzione.

bGeoCode <- function(str, BingMapsKey){
    require(RCurl)
    require(RJSONIO)
    u <- URLencode(paste0("http://dev.virtualearth.net/REST/v1/Locations?q=", str, "&maxResults=1&key=", BingMapsKey))
    d <- getURL(u)
    j <- fromJSON(d,simplify = FALSE) 
    if (j$resourceSets[[1]]$estimatedTotal > 0) {
      lat <- j$resourceSets[[1]]$resources[[1]]$point$coordinates[[1]]
      lng <- j$resourceSets[[1]]$resources[[1]]$point$coordinates[[2]]
    }
    else {    
      lat <- lng <- NA
    }
    c(lat,lng)
}  

bGeoCode("Berlin, Germany", "yourAPIKeyHere")

Google :

library(ggmap)  
geocode("Berlin, Germany", source="google")
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.