The function st_as_sf() makes it possible to transform a data.frame container of geographic coordinates into an object sf. Here we use the data.frameplaces2 created in the previous point.
OpenStreetMap (OSM) is a participatory mapping project that aim s to buil a free geographic database on a global scale. OpenStreetMap lets you view, edit and use geographic data around the world.
Terms of use
OpenStreetMap is open data : you are free to use it for ant purpose as long as you credit OpenStreetMap and its contributers. If you modify or rely data in any way, you may distribute the result only under the same license. (…)
Contributors
(…) Our contributors incloude enthusiastic mapmakers, GIS professional, engineers running OSM servers, humanitarians mapping disaster-stricken areas and many mmore.(…)
The package maptiles(Giraud 2021) allows downlaoding and displaying raster basemaps.
The function get_tiles() allow you to download OSM background maps and the function plot_tiles() allows to display them.
Renders are better if the input data used the same coordinate system as the tiles (EPSG:3857).
library(sf)library(osmdata)library(sf)country <-st_read("data_cambodia/cambodia.gpkg", layer ="country", quiet =TRUE)ext <-opq(bbox =st_bbox(st_transform(country, 4326))) #Define the bounding boxquery <-add_osm_feature(opq = ext, key ='amenity', value ="hospital") #Health Center Extractionhospital <-osmdata_sf(query)hospital <-unique_osmdata(hospital) #Result reduction (points composing polygon are detected)
The result contains a point layer and a polygon layer. The polygon layer contains polygons that represent fast food-food place. To obtain a coherent point layer we can use the centroids of the polygons.
hospital_point <- hospital$osm_pointshospital_poly <- hospital$osm_polygons #Extracting centroids of polygonshospital_poly_centroid <-st_centroid(hospital_poly)cambodia_point <-intersect(names(hospital_point), names(hospital_poly_centroid)) #Identify fields in Cambodia boundaryhospitals <-rbind(hospital_point[, cambodia_point], hospital_poly_centroid[, cambodia_point]) #Gather the 2 objects
The package osmextract(Gilardi and Lovelace 2021) allows to extract data from an OSM database directly. This package make it possible to work on very large volumes of data.
The package mapedit(Appelhans, Russell, and Busetto 2020) allows you to digitize base map directly in R. Although it can be practical in some cases, in package cannot replace the functionalities of a GIS for important digitization tasks.
Appelhans, Tim, Florian Detsch, Christoph Reudenbach, and Stefan Woellauer. 2022. “Mapview: Interactive Viewing of Spatial Data in r.”https://CRAN.R-project.org/package=mapview.
Cambon, Jesse, Diego Hernangómez, Christopher Belanger, and Daniel Possenriede. 2021. “Tidygeocoder: An r Package for Geocoding” 6: 3544. https://doi.org/10.21105/joss.03544.
Cheng, Joe, Bhaskar Karambelkar, and Yihui Xie. 2022. “Leaflet: Create Interactive Web Maps with the JavaScript ’Leaflet’ Library.”https://CRAN.R-project.org/package=leaflet.