-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeocode.R
39 lines (31 loc) · 1.07 KB
/
geocode.R
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
35
36
37
38
39
library(ggmap)
load('address_pubmed.RData')
addresses<-address_gather_pubmed_df$address
address_lat_lng<-list()
load('address_lat_lng.RData')
start<-length(address_lat_lng)+1
rest_idx<-start:nrow(address_gather_pubmed_df)
geocodeIdx<-function(idx){
llply(idx, function(i){
address_lat_lng[[i]]<<-geocode(addresses[i], source = 'google',
output='all', messaging = F)
#if(address_lat_lng[[i]]$status == 'OVER_QUERY_LIMIT'){
if(geocodeQueryCheck()<200){
break
}
Sys.sleep(0.2)
}, .progress = 'text')
}
#geocodeIdx(rest_idx)
#save(address_lat_lng, file='address_lat_lng.RData')
status<-sapply(address_lat_lng, function(x){unlist(x['status'])})
retry_idx<-which(status == 'OVER_QUERY_LIMIT' |is.na(status))
zero_idx<-which(status == 'ZERO_RESULTS')
#geocodeIdx(retry_idx)
#save(address_lat_lng, file='address_lat_lng.RData')
addresses[zero_idx]<-addresses[zero_idx] %>%
gsub(' &| "', '') %>%
gsub('\\(.*?\\)', '') %>%
gsub('\\. Tel.*', '')
geocodeIdx(zero_idx)
save(address_lat_lng, file='address_lat_lng.RData')