There is a ton of spatial data on the City of Toronto Open Data Portal. Spatial resources are retrieved the same way as all other resources, by using get_resource()
, and may require the sf
package.
We can look at bicycle parking in Toronto. The result is an sf
object with WGS84 projection.
library(opendatatoronto)
library(dplyr)
bike_parking_racks <- search_packages("Bicycle Parking Racks") %>%
list_package_resources() %>%
filter(name == "bicycle-parking-racks-wgs84") %>%
get_resource()
#> Reading layer `BICYCLE_PARKING_RACK_WGS84' from data source `/tmp/RtmpHpqrqQ/BICYCLE_PARKING_RACK_WGS84.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 178 features and 29 fields
#> geometry type: POINT
#> dimension: XY
#> bbox: xmin: -79.59575 ymin: 43.60368 xmax: -79.25724 ymax: 43.82304
#> epsg (SRID): 4326
#> proj4string: +proj=longlat +ellps=WGS84 +no_defs
bike_parking_racks
#> Simple feature collection with 178 features and 29 fields
#> geometry type: POINT
#> dimension: XY
#> bbox: xmin: -79.59575 ymin: 43.60368 xmax: -79.25724 ymax: 43.82304
#> epsg (SRID): 4326
#> proj4string: +proj=longlat +ellps=WGS84 +no_defs
#> # A tibble: 178 x 30
#> ADD_PT_ID ADD_NUM LN_NAM_FUL ADD_FULL POSTAL_CD MUN CITY CNTL_ID LO_NUM
#> <dbl> <fct> <fct> <fct> <fct> <fct> <fct> <dbl> <int>
#> 1 30072958 1190 Dundas St… 1190 Du… M4M 0C5 form… Toro… 7.58e6 1190
#> 2 30085026 60 Lisgar St 60 Lisg… <NA> form… Toro… 1.40e7 60
#> 3 10154425 1 St Clair … 1 St Cl… M4T 2V7 form… Toro… 1.02e7 1
#> 4 856375 100 Queen St W 100 Que… M5H 2N1 form… Toro… 1.15e6 100
#> 5 51630 5 Bartonvil… 5 Barto… M6M 2B1 YORK Toro… 2.01e7 5
#> 6 310564 150 Borough Dr 150 Bor… M1P 4N7 SCAR… Toro… 1.08e5 150
#> 7 367443 71 New Fores… 71 New … M1V 2Z6 SCAR… Toro… 2.01e7 71
#> 8 379258 95 River Gro… 95 Rive… M1W 3T8 SCAR… Toro… 2.01e7 95
#> 9 394585 24 Victoria … 24 Vict… M4E 3R9 SCAR… Toro… 1.13e5 24
#> 10 772775 315 Bloor St W 315 Blo… M5S 1A3 form… Toro… 1.14e6 315
#> # … with 168 more rows, and 21 more variables: LO_NUM_SUF <fct>, HI_NUM <int>,
#> # HI_NUM_SUF <fct>, LN_NAM_ID <dbl>, WARD_NAME <fct>, X <dbl>, Y <dbl>,
#> # LONGITUDE <dbl>, LATITUDE <dbl>, MI_PRINX <dbl>, OBJECTID <dbl>,
#> # CAPACITY <dbl>, MULTIMODAL <fct>, SEASONAL <fct>, SHELTERED <fct>,
#> # SURFACE <fct>, STATUS <fct>, LOCATION <fct>, NOTES <fct>, MAP_CLASS <fct>,
#> # geometry <POINT [°]>
If we want to plot this data on a map of Toronto, data to map the different neighbourhoods of Toronto is also available from the portal!
neighbourhoods <- list_package_resources("https://open.toronto.ca/dataset/neighbourhoods/") %>%
get_resource()
neighbourhoods[c("AREA_NAME", "geometry")]
#> Simple feature collection with 140 features and 1 field
#> geometry type: POLYGON
#> dimension: XY
#> bbox: xmin: -79.63926 ymin: 43.581 xmax: -79.11545 ymax: 43.85546
#> epsg (SRID): 4326
#> proj4string: +proj=longlat +datum=WGS84 +no_defs
#> # A tibble: 140 x 2
#> AREA_NAME geometry
#> <chr> <POLYGON [°]>
#> 1 Wychwood (94) ((-79.43592 43.68015, -79.43492 43.68037, -79.43395 43…
#> 2 Yonge-Eglinton (100) ((-79.41096 43.70408, -79.40962 43.70436, -79.40852 43…
#> 3 Yonge-St.Clair (97) ((-79.39119 43.68108, -79.39141 43.68097, -79.39322 43…
#> 4 York University Heig… ((-79.50529 43.75987, -79.50488 43.75996, -79.5049 43.…
#> 5 Yorkdale-Glen Park (… ((-79.43969 43.70561, -79.44011 43.70559, -79.44102 43…
#> 6 Lambton Baby Point (… ((-79.50552 43.66281, -79.50577 43.66291, -79.50617 43…
#> 7 Lansing-Westgate (38) ((-79.43998 43.76156, -79.44004 43.76177, -79.44043 43…
#> 8 Lawrence Park North … ((-79.39008 43.72768, -79.39199 43.72726, -79.39397 43…
#> 9 Lawrence Park South … ((-79.41096 43.70408, -79.41165 43.70394, -79.41208 43…
#> 10 Leaside-Bennington (… ((-79.37749 43.71309, -79.37762 43.71385, -79.37798 43…
#> # … with 130 more rows
Then, we can plot the bike racks along with a map of Toronto: