-
Notifications
You must be signed in to change notification settings - Fork 5
/
geocoordinates
34 lines (29 loc) · 953 Bytes
/
geocoordinates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Название файла лучше с расширением .r задавать
###
library(httr)
library(rjson)
library(plyr)
finder <- function (x, geolocation=TRUE) {
location <- GET("http://nominatim.openstreetmap.org/", path = "search",
query = list(q = iconv(x, "cp1251", "UTF-8"),
format = 'json',
polygon = 0,
addressdetails = 1,
email = '[email protected]')) # ещё можно добавить viewbox и bounded
geolocation <- unlist(content(location))
if(!is.null(geolocation)) {
lat <- (geolocation ["lat"])
lng <- (geolocation ["lon"])
osmID <- (geolocation ["osm_id"])
nameschool <- (geolocation ["address.school"])
data <- c(osmID, lat, lng, nameschool)
names(data) <- c("osmID", "lat", "lng", "nameschool")
return(data)
}
else {
return(c(NA,NA, NA,NA))
}
}
ournewbase <- with(school, data.frame(Name,
laply(Name, function(val){finder (val)})))
ournewbase