[API] shapeR

API & Databases R Courses

Access shapefiles for all countries and their sub-divisions through the shapeR API.

Thierry Warin https://warin.ca/aboutme.html (HEC Montréal and CIRANO (Canada))https://www.hec.ca/en/profs/thierry.warin.html
04-05-2020

Database description

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

Functions

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.

shaper_country()

#Loading the statCanR library
library(shapeR)

# The ISO code for Canada will be produced
shaper_country(country = "Canada")

shaper_data()

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)

tl;dr

#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)

Code learned this week

Command Detail
shaper_country() Search for a country’s ISO code
shaper_data() Retrieve a shapefile for a country’s level

References

This tutorial uses the shapeR package documentation developped by the team of the professor Thierry Warin.


Citation

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}
}