I found this website here that contains a geographical map on internet coverage across different parts of Canada over different years: https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/index.html
My Question: I want to try and extract all relevant geographical information (e.g. polygon boundaries, shadings, years) such that I would be able to recreate this map myself using R (e.g. using the "leaflet" library).
Here is what I have tried so far:
- I opened the map (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/index.html) and pressed "CTRL + SHIFT I"
- Then, I clicked on the "Network" tab
- Then, I clicked on Fetch/XHR
- Then, I clicked "CTRL + R"
This now shows me that there are several JSON/XML files associated with this map:
- LTEOverTheYearsYE2019_ENConfig.XML (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTEOverTheYearsYE2019_ENConfig.xml)
- LTE_YE2019.json (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2019.json)
- LTE_YE2018.json (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2018.json)
- LTE_YE2017.json (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2017.json)
- LTE_YE2016.json (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2016.json)
- LTE_YE2015.json (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2015.json)
- LTE_YE2014.json (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2014.json)
- LTEOverYearsByProv.json (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTEOverYearsByProv.json)
- LTEOverTheYearsYE2019_ENThematic.xml (https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTEOverTheYearsYE2019_ENThematic.xml)
Using R, I then downloaded all the JSON files and parsed them:
library(jsonlite)
library(httr)
urls <- c("https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2019.json",
"https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2018.json",
"https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2017.json",
"https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2016.json",
"https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2015.json",
"https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTE_YE2014.json",
"https://crtc.gc.ca/cartovista/LTEOverTheYearsYE2019_EN/map/LTEOverYearsByProv.json")
my_list <- list()
for (i in seq_along(urls)) {
response <- GET(urls[i])
content <- content(response, as = "text")
data <- fromJSON(content)
name <- sub(".*/(.*).json", "\\1", urls[i])
my_list[[name]] <- data
}
list2env(my_list, envir = .GlobalEnv)
When I start inspecting the results, it seems like the JSON files all have a similar format - for example, here is the LTE_YE2019
file :
> str(LTE_YE2019)
List of 5
$ scaleUpFactor : int 0
$ type : chr "FeatureCollection"
$ proj : chr "+proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,-0,-0,-0,0 +units=m +no_defs "
$ attributeDefinitions: chr [1, 1:2] "UniqueID" "String"
$ f :'data.frame': 1 obs. of 3 variables:
..$ t: chr "Feature"
..$ g:'data.frame': 1 obs. of 2 variables:
.. ..$ t: chr "Polygon"
.. ..$ c:List of 1
.. .. ..$ :List of 606
.. .. .. ..$ : int [1:57382] 672569 15968 -1136 -165 -1136 -164 -1137 -164 -1136 -164 ...
.. .. .. ..$ : int [1:12262] -1377281 534100 -1009 337 -1009 338 -1009 338 -1009 338 ...
.. .. .. ..$ : int [1:3282] -1465443 375186 -1048 359 -1048 359 -1048 360 -1048 359 ...
.. .. .. ..$ : int [1:2282] -843365 743147 -958 207 -958 206 -958 208 -958 207 ...
My Problem: From here, I am stuck - I do not know how to extract the geographical coordinates of the polygons from LTE_YE2019
- and then plot/shade these polygons on a map using leaflet. If I could figure this out, I could then repeat this for LTE_YE2018, LTE_YE2017, LTE_YE2016
, etc.
leaflet() %>%
addTiles() %>%
addPolygons(data = LTE_YE2019)
Can someone please show me how to do this?
Thanks!