If there was an OSM editing championship, this is how we could find the winners… :)
First, let’s load packages osmar, leaflet and dplyr
library(osmar)
library(leaflet)
library(dplyr)
Then, using osmar, let’s load some OSM data for Belgrade, Serbia
nbgd <- get_osm(center_bbox(20.45,44.81, 3000, 3000),all=True)
bg_mappers<-as.data.frame(nbgd$way$attrs)
colnames(bg_mappers)<-c("id","visible","timestamp","version","changeset","user","uid")
Then, using dplyr we can list users with the most edits
select(bg_mappers,user,id) %>% count(user)%>%arrange(desc(n))
## # A tibble: 124 × 2
## user n
## <fctr> <int>
## 1 nikicam 3489
## 2 Nikola Smolenski 707
## 3 vakulya 178
## 4 kmilos 167
## 5 Dusan Juranovic 154
## 6 mpele 154
## 7 Nilko 135
## 8 sve_je_uzalud 119
## 9 Janjko 82
## 10 Ignjat 67
## # ... with 114 more rows
Osmar package offers a variety of possibilities for handling the OSM data. After we select ways edited by these users we will select nodes that are not a part of any way…
gold_way_ids <- find(nbgd, way(attrs(user=="nikicam")))
gold_way_ids <- find_down(nbgd, way(gold_way_ids))
gold_ways <- subset(nbgd, ids = gold_way_ids)
gold_ways
## osmar object
## 23927 nodes, 3489 ways, 0 relations
gold_node_ids <- find(nbgd, node(attrs(user=="nikicam")))
m<-match(gold_node_ids, gold_ways$ways$refs$ref)
gold_node_ids<-gold_node_ids[is.na(m)]
gold_nodes <- subset(nbgd, node_ids = gold_node_ids)
gold_nodes
## osmar object
## 2223 nodes, 0 ways, 0 relations
silver_way_ids <- find(nbgd, way(attrs(user=="Nikola Smolenski")))
silver_way_ids <- find_down(nbgd, way(silver_way_ids))
silver_ways <- subset(nbgd, ids = silver_way_ids)
silver_ways
## osmar object
## 4299 nodes, 707 ways, 0 relations
silver_node_ids <- find(nbgd, node(attrs(user=="Nikola Smolenski")))
m<-match(silver_node_ids, silver_ways$ways$refs$ref)
silver_node_ids<-silver_node_ids[is.na(m)]
silver_nodes <- subset(nbgd, node_ids = silver_node_ids)
silver_nodes
## osmar object
## 1806 nodes, 0 ways, 0 relations
bronze_way_ids <- find(nbgd, way(attrs(user=="vakulya")))
bronze_way_ids <- find_down(nbgd, way(bronze_way_ids))
bronze_ways <- subset(nbgd, ids = bronze_way_ids)
bronze_ways
## osmar object
## 1474 nodes, 178 ways, 0 relations
bronze_node_ids <- find(nbgd, node(attrs(user=="vakulya")))
m<-match(bronze_node_ids, bronze_ways$ways$refs$ref)
bronze_node_ids<-bronze_node_ids[is.na(m)]
bronze_nodes <- subset(nbgd, node_ids = bronze_node_ids)
bronze_nodes
## osmar object
## 790 nodes, 0 ways, 0 relations
Then we can map the polygons and point using the leaflet package
leaflet()%>%addTiles()%>%
setView(20.45, lat=44.81, zoom=12)%>%
addPolygons(data=as_sp(gold_ways,"lines"),col="blue")%>%
addPolygons(data=as_sp(silver_ways,"lines"),col="green")%>%
addPolygons(data=as_sp(bronze_ways,"lines"),col="yellow")
For nodes we will create markers of different color
icon.gold <- makeAwesomeIcon(icon= 'flag', markerColor = 'darkblue',
iconColor = 'white', library='ion')
icon.silver <- makeAwesomeIcon(icon= 'flag', markerColor = 'blue',
iconColor = 'white', library='ion')
icon.bronze <- makeAwesomeIcon(icon= 'flag', markerColor = 'lightblue',
iconColor = 'white', library='ion')
leaflet()%>%addTiles()%>%
setView(20.45, lat=44.81, zoom=12)%>%
addAwesomeMarkers(data=as_sp(gold_nodes,"points"),
popup = ~(gold_nodes$nodes$tags$v),icon=icon.gold,
clusterOptions = markerClusterOptions())%>%
addAwesomeMarkers(data=as_sp(silver_nodes,"points"),
popup = ~(silver_nodes$nodes$tags$v),icon=icon.silver,
clusterOptions = markerClusterOptions())%>%
addAwesomeMarkers(data=as_sp(bronze_nodes,"points"),
popup = ~(bronze_nodes$nodes$tags$v),icon=icon.bronze,
clusterOptions = markerClusterOptions())