Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as R by radek ( 5 years ago )
library(osmdata)
library(ggmap)
library(sp)
library(RgoogleMaps)
library(dplyr)
register_google(" your Google API key ")
ggl=get_googlemap(c(22.555,51.245), zoom=12, scale=2)
loc=getbb("lublin")
loc[1,1]=22.43
loc[2,1]=51.16
loc[2,2]=51.31
loc[1,2]=22.65
# kościoły ----------------------------------------------------------------
q = opq(loc) %>%
add_osm_feature(key='building', value="church")
church1=osmdata_sp(q)
idx=which((church1$osm_polygons$denomination=="roman_catholic"))
dta=c()
name=c()
# extract single points from polygons
for( i in idx){
dta=rbind(dta, church1$osm_polygons@polygons[[i]]@Polygons[[1]]@coords[1,])
}
kosciol=as.data.frame(dta)
kosciol=kosciol[-47,] # usuwamy kosciol w budowie na gnieznienskiej
kosciol=rbind(kosciol, c(22.4919,51.2229)) # dodajemy kosciol na krysztalowej
kosciol$name="Kościół"
# supermarket -------------------------------------------------------------
q1 <- opq(loc) %>%
add_osm_feature('shop', 'supermarket')
shop <- osmdata_sp(q1)
dta=data.frame()
name=c()
# extract single points from polygons
for( i in 1:nrow(shop$osm_polygons)){
dta=rbind(dta, shop$osm_polygons@polygons[[i]]@Polygons[[1]]@coords[1,])
name=c(name, shop$osm_polygons$name[i])
}
colnames(dta)=c('lon','lat')
dta$name=name
rm(name)
# other supermarkets as single points
shop1=shop$osm_points
shop1=shop1[is.na(shop1$name)==F,]
datashops=as.data.frame(shop1@coords)
datashops$name=shop1$name
datashops=rbind(datashops,dta)
# merging data, map -------------------------------------------------------------------
data=rbind(datashops,kosciol) %>%
filter(name%in% c( "Stokrotka", "Kościół"))
data$name=factor(data$name, levels=c( "Stokrotka", "Kościół"))
ggmap(ggl)+
geom_point(filter(data, name %in% c("Kościół", "Stokrotka")),
mapping=aes(x=lon, y=lat, color=name, fill=name, shape=name, size=name))+
scale_color_manual(values = c( "#00b815", 'black'))+
scale_fill_manual(values = c( "#00b815", 'black'))+
scale_shape_manual(values = c(16,43))+
scale_size_manual(values = c(3,6))+
theme_void()+
theme( legend.position = c(0.2,0.15),
legend.title = element_blank(),
legend.background = element_rect( fill="white", color='black', size=1),
legend.margin = margin(rep(8,4)),
legend.key.width = unit(0.05, "cm"),
legend.key.height = unit(0.05, "cm"))
data %>%
group_by(name) %>%
summarise("sum"=n())
Revise this Paste
Parent: 116407