-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pulling in OSMand data for the spatial sampling section #11
Comments
Hi @pbkeating Do you mean this:
I don't think this has yet been added to the Epi R handbook, but I tagged @aspina7 as he might have more news on this. In the meantime, there is a nice blog which shows how it can be done here. The below code seems to work, but would be greate if someone (Joreike?) could check that it makes sense:
# Load packages -----------------------------------------------------------
# Ensures the package "pacman" is installed
if (!require("pacman")) install.packages("pacman", quiet = TRUE)
# Install and/or load required packages
pacman::p_load(
leaflet,
mapedit,
sf,
osmdata,
here,
dplyr,
rio
)
# Import shape files ------------------------------------------------------
# Import the polygon for Kario camp:
kario_polygon <- sf::read_sf(here::here("data",
"SDN_Kario_17Feb2019_polygon",
"SDN_Kario_17Feb2019_polygon.shp"))
# Get buildings from OSM --------------------------------------------------
# Get a boundary box for Kario camp from the shapefile:
kario_bbox <- sf::st_bbox(kario_polygon)
# Get the builing points within the boundary box:
households <- osmdata::opq(bbox = kario_bbox) %>%
# Get the buildings in this boundary box:
add_osm_feature(key = "building") %>%
# Convert the building points to a simple feature object:
osmdata::osmdata_sf()
# Remove households that are in the boundary box but outside the polygon:
households_trimmed <- households$osm_polygons %>%
# Convert to a simple features object:
sf::st_as_sf() %>%
# Trim to points which are inside the Kario camp polygon:
sf::st_intersection(y = kario_polygon) %>%
# Get centroids (points) for each building polygon:
mutate(points = st_centroid(geometry)) %>%
# Remove the empty ID column:
select(-id)
# Create leaflet map ------------------------------------------------------
# Create a leaflet map of Kario camp:
kario_map <- leaflet() %>%
# Add the background tiles of your choice
addProviderTiles("OpenStreetMap.HOT") %>%
# Plot the polygon of Kario camp ontop of the background map tiles:
addPolygons(
data = kario_polygon,
color = "red",
fillOpacity = 0
) %>%
# Plot the points representing buildings ontop:
addCircleMarkers(
data = households_trimmed$points,
radius = 5
)
# View the map:
kario_map
|
@aspina7 and @pbkeating note this process gives 2609 households, is that the expected number? |
Hi!
Awesome work on the spatial sampling!
Would it be possible to integrate pulling underlying OSMand data on households (where available) into the script based on the osmand package https://github.com/ropensci/osmdata ?
Suggestion from Jorieke, GIS specialist on the team.
Thanks,
P
The text was updated successfully, but these errors were encountered: