Access shapefiles for all countries and their sub-divisions through the shapeR API.
shapeR aims to simplify GIS mapping by giving access through simple R functions to shapefiles from different sources.
The list of available shapefiles is shown in the following table:
Region | Source |
---|---|
World | https://www.naturalearthdata.com/ |
Countries | https://gadm.org/download_world.html |
shapeR provides the R user with a consistent process to collect shapefiles. It provides access to the shapefiles for the entire world, all countries and their sub-divisions.
This tutorial presents how to use the shapeR R package and its functions.
Some examples are provided below.
#Loading the statCanR library
library(shapeR)
# The ISO code for Canada will be produced
shaper_country(country = "Canada")
First, the shaper_data() function takes as an input the country we’re interested in. We specify this argument with the country ISO code obtained from the function shaper_country(), as such: “CAN” for Canada, “USA” for United States, “FRA” for France or “ITA” for Italy.
The second argument is dedicated for the shapefile’s level (0 to 5). The level of a shapefile defines its degree of granularity: 0 being the borders of the country and 5 being its administrative areas.
For example, we can now extract the shapefile for Canada with the level 1 (regions).
# Get data with sqs_statcan_data function
mydata <- shaper_data(country_code = "CAN", level = 1)
head(mydata)
#Loading the statCanR library
library(shapeR)
# The ISO code for Canada will be produced
shaper_country(country = "Canada")
# Get data with sqs_statcan_data function
mydata <- shaper_data(country_code = "CAN", level = 1)
Command | Detail |
---|---|
shaper_country() | Search for a country’s ISO code |
shaper_data() | Retrieve a shapefile for a country’s level |
This tutorial uses the shapeR package documentation developped by the team of the professor Thierry Warin.
For attribution, please cite this work as
Warin (2020, April 5). Thierry Warin, PhD: [API] shapeR. Retrieved from https://warin.ca/posts/api-shaper/
BibTeX citation
@misc{warin2020[api], author = {Warin, Thierry}, title = {Thierry Warin, PhD: [API] shapeR}, url = {https://warin.ca/posts/api-shaper/}, year = {2020} }