17 Geo/Spatial coding and visualization in R
There’s much effort across many GC departments to analyze and visualize geo-data. This discussion is the place to share your results, ideas or problems related to the problem.
Below is a great resource to start, which also provides a nice explanation on why R is believed to be the best language to do this kind of work.
Geocomputation with R, a book on geographic data analysis, visualization and modeling.
The online version of the book is hosted at https://geocompr.robinlovelace.net and kept up-to-date by GitHub Actions
17.2 Federal Geospatial Platform
Yukon’s open geospatial data is now searchable on the Federal Geospatial Platform (FGP) (https://gcgeo.gc.ca/) and on Government of Canada Open Maps Portal. Check it out !
With the addition of Yukon’s resources, the FGP now offers over 5,000 datasets available to discover and download, for public servants and Canadians, all in one location.
Wondering how to create a map with your data? We can help you do so, from A to Z, at no cost. Contact us at firstname.lastname@example.org
Check codes and notes for the two Tutorials that we had on this subject this summer:
17.4 Dealing with memory issues
A blog post that illustrates a few ways to avoid overloading R’s memory when working with large spatial objects (here’s looking at you, 30-m land cover map of North America!).
The two other posts on that blog also have some really nice tips for general R coding.
17.5 Canadian geo-data
Useful code and R packages from public domain to work with Canadian geo-data.
From https://mountainmath.ca - https://github.com/mountainMath/mountainmathHelpers - tongfen: Convenience functions for making data on different geometries, especially Canadian census geometries, comparable. - cancensus : R wrapper for calling CensusMapper APIs - cansim: Wrapper to access CANSIM data - CanCovidData: Collection of data import and processing functions focused on Canadian data
17.6 Code snippets
17.6.1 Using simplemaps.com
# 1.a https://simplemaps.com/data/us-cities ---- load("datasets/geoCa/uszips.rda") dtUS <- as.data.table(uszips) %>% mutate(across(where(is.character), as.factor)) %>% mutate(across(where(is.logical), as.factor)); dtUS %>% print(2); dtUS %>% summary saveRDS(dtUS, "citiesUS_simplemaps.Rds") # 1.b https://simplemaps.com/data/canada-cities ---- dtCaCitiesGeoPop <- readRDS("citiesCa-simplemaps.Rds") %>% setDT # dtCa2<- read_excel("geoCa/canadacities.xlsx", sheet=1) %>% data.table() #%T>% print() dtCaSimplemaps <- fread("geoCa/canadacities.csv")
17.6.2 Using Google API
18.104.22.168 Using googleway
require(googleway) set_key("your_google_key_of_39_characters") x= google_geocode(address = "Southern Saskatchewan", simplify = TRUE) x$results$geometry
17.6.3 Using tidygeocoder
17.6.4 Using Open Street map
17.6.5 Using Open Database of Addresses / Educational Facilities
urlAddresses = c( Alberta = "ODA_AB_v1.zip", BritishColumbia = "ODA_BC_v1.zip", Manitoba = "ODA_MB_v1.zip", NewBrunswick = "ODA_NB_v1.zip", NorthwestTerritories = "ODA_NT_v1.zip", NovaScotia = "ODA_NS_v1.zip", Ontario = "ODA_ON_v1.zip", PrinceEdwardIsland = "ODA_PE_v1.zip", Quebec = "ODA_QC_v1.zip", Saskatchewan = "ODA_SK_v1.zip" ) dtUrlAddresses <- data.table(province=names(urlAddresses),url=urlAddresses) %>% setkey(province) dtUrlAddresses$url <- str_c(strHome, dtUrlAddresses$url) dtUrlAddresses[, url:=str_c(strHome, url) ] dtAddress <- fread (urlAddresses["Alberta"])
17.6.6 Getting Postal codes
NOT AVAILABLE TO PUBLIC, ONLY VIA UNIVERSITY
Home Maps and geography Geographic products Postal code products:
Postal code products
Postal Code OM Conversion File
https://www150.statcan.gc.ca/n1/en/catalogue/92-154-X - Postal Code OM Conversion File, June 2017
https://www150.statcan.gc.ca/n1/en/catalogue/92-178-X - Postal Codes OM by Federal Ridings File (PCFRF)
https://www150.statcan.gc.ca/n1/en/catalogue/82F0086X - Postal Code OM Conversion File Plus (PCCF+), August 2015 - Update
The Data Liberation Initiative (DLI) is a partnership between post-secondary institutions and Statistics Canada for improving access to Canadian data resources.
Please consult the list of participating institutions and their contacts. If your institution is already a member, please contact the person listed to gain access to products available through the DLI.
University of Ottawa Chantal Ripp Data Research Librarian 613-562-5800 ext.3881 email@example.com