class: inverse, center, middle, title-slide # Visualising predicted travel time differences<br> between transport modes ## MelbURN Presentation ### Belinda Maher<br>Senior Public Transport Planner <br>Department of Transport<br><br><a href="https://www.youtube.com/watch?v=wAWelatBN-M&t=4s" class="uri">https://www.youtube.com/watch?v=wAWelatBN-M&t=4s</a> ### 19/5/2020 --- background-position: center top; background-size:98% background-image: url("img/Destination 1 Spring St.png") .pull-left[ # A Proof of Concept ] .pull-right[ <i>Needs a lot more work!</i> ] ??? Start at the end Public Transport predicted travel time from origin minus the predicted driving travel time To show relative PT accesibility --- layout:true <div class="my-footer"><span>     Belinda Maher - Visualising Travel Time Differences Between Modes       https://belinda-maher-melburn.netlify.com/ </span> </div> <div class="my-css"> <style type="text/css"> .tiny {font-size: 60%;} </div> </style> <!-- Add icon library --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> --- .pull[ #About Me ] .pull-right[ <div text-align: center;> <img src="img/Prefontaine.jpg"> <span style=" text-align: center;"> <p>Contact<br> <a href="mailto:belinda.maher@gmail.com" class="fa fa-envelope"> belinda.maher@gmail.com</a><br>(links to previous talk):<br> <a href="http://about.me/minga" class="fa fa-globe"> http://about.me/minga</a> <br> <a href="https://twitter.com/surgisse" class="fa fa-twitter"> @Surgisse</a><br> <a href="https://www.linkedin.com/in/belindamaher/" class="fa fa-linkedin"> belindamaher</a><br> <a href="https://github.com/surgissant/" class="fa fa-github"> surgissant</a> </span> </div> ] I ❤️ -- - Data - R - Maps - Trains -- - (particularly new railway lines!) <img src="img/2025 Network.png" width=800> .tiny[https://transport.vic.gov.au/about/planning/transport-strategies-and-plans/] --- .pull[ #My Background ] .pull-left[ ####Study Science, Programming, Statistics & Operations Research ####Work - 2001 - Lots of (boring) things not involving transport<br> - 2009 - KiwiRail (Wellington) - Auckland Electrification & Track Upgrades - 2016 - Public Transport Victoria - Operational Performance Analyst - <em>R-Ladies Talk - Visualising Spatial Data in R </em> - 2018 - Department of Transport - Transport System Analyst - Senior Public Transport Planner] .pull-right[ ] --- .pull[ # Strategic Transport Network Planning] .pull-left[.full-width[ ####What we do: - Look at transport modelling outputs (into the distant <br> future) of predicted population, employment &<br>associated trip distribution - Assess which corridors will be strategically important - Try to be mode agnostic #### What I actually do: - Data interpreter for non-techncial people <br> - Make a lot of graphs & maps for transport planners - Sometimes get to look at some operational data ]] .pull-right[ <img src="img/1962 Loop.jpg" width=560 />] --- layout:false background-position: middle; background-size: 70% background-image: url("img/rail plan.png") .pull-left[ # 1969 Melbourne Transportation Plan ] ??? I can't show you what we're currently working on, but here's something from 50 years ago. Still haven't build Doncaster Line! Source: https://menafn.com/1099389511/50-years-on-from-the-Melbourne-Transportation-Plan-what-can-we-learn-from-its-legacy --- layout:true <div class="my-footer"><span>     Belinda Maher - Visualising Travel Time Differences Between Modes       https://belinda-maher-melburn.netlify.com/ </span></div> <div class="my-css"> <style type="text/css"> .tiny {font-size: 60%;}</div></style> --- .pull-left[ #The Problem ] .pull-right[ <img src="img/Airport Isochrone.PNG" width="550"/> ] .pull-left[ #### This project came from a meeting about access to jobs ] -- .pull-left[ Think about workers getting to the airport: ] -- .pull-left[ - Quick to drive from the West - Free parking for staff in some cases<p> ] -- .pull-left[ vs. - Poor public transport options in the West - reliability - connections/interchanges - directness - frequency/waiting times ] ??? Image source: https://maps.openrouteservice.org --- .pull-left[ #Modal Choice ] .pull-right[ <img src="img/Compare directions.png" height=400 /> ] .pull-left[ ####Mode selection is a choice which a user always makes - <i>If driving is faster and more reliable than public <br>transport for your trip, are you going to choose PT?</i> - Modal choice using Google Maps - <i>"If only we could get some data on this!"</i> ] -- .pull-left[ - Famous last words: "I can do that!" ] --- .pull-left[ #Comparing PT accessibility - Googleway - <i>How to compare public transport accessibility to driving accessibility at a very detailed level on the current network?</i> ] -- .pull-right[ <img src="img/Googleway logo.png"/> ] .pull-left[ - Answer: library(googleway)! <p> Dave Cooley's MelbURN talk which inspired this project:<br> http://demos.symbolix.com.au/GooglewayRMeetupPresentation.html ] --- .pull-left[ #Talk Plan ####0. Transport/Map Jargon ####1. Generating Origin Points - Need many origin points to query ####2. Running the queries in batches - API is limited to 100 OD pairs per call ####3. Extracting the results (nested lists!#@*!) ####4. Using Leaflet to plot the results ####5. Adjusting the scale/outlier removal ####6. Where to next? - Limitations and further work to do ] .pull-right[ <img src="img/Isochrone.jpg" width="550" style="display: block; margin: auto;"/>] ??? Melbourne Isochrone --- .pull-left[ # Transport/Map Jargon - PT - Public Transport<br> (in this case including walking to stops) - PV - Private Vehicle - <b>O</b>-<b>D</b> pair - describes a trip between <b>O</b>rigin and <br><b>D</b>estination locations - Centroid - geometric (in this case) centre of a polygon ] .pull-right[ <img src="/img/Empty train.jpg" width=550/> ] --- .pull-left[ #More Transport/Map Jargon - Shapefile - used by GIS software to store points, <br> lines and /or polygons - Mode - eg driving, walking, public transport, cycling - Mode Shift - moving from choosing one mode to another - Isochrones & Choropleths - next two slides ] .pull-right[ <img src="img/FSS outside.jpg" height=500/> ] --- .pull-left[ #What is an Isochrone? <figure> <img src="img/1954 CBD Isochrone.png" width=60%> <figcaption> <i>CBD Walking Isochrone - Metropolitan Planning Scheme 1954</i> </figcaption> </figure> <div> iso = equal <br> chrone = time <p> <em>An isochrone is defined as "a line drawn on a map connecting points at which something occurs or arrives at the same time".</em> <p>.tiny[<i>Source: Wikipedia</i>]<p><p> </div> ] ??? Image Source: https://www.planning.vic.gov.au/policy-and-strategy/planning-for-melbourne/melbournes-strategic-planning-history/melbourne-metropolitan-planning-scheme-1954-report]] --- layout:false background-position: middle background-size: 95% background-image: url("/img/Driving Isochrone CBD.png") .pull-left[ #CBD Driving Isochrone ] <div class="my-footer">.tiny[Source: <nbsp;>https://maps.openrouteservice.org] </div> --- layout:true <div class="my-footer"><span>     Belinda Maher - Visualising Travel Time Differences Between Modes       https://belinda-maher-melburn.netlify.com/ </span></div> <div class="my-css"> <style type="text/css"> .tiny {font-size: 60%;}</div></style> --- .pull-left[ #What is a Choropleth? .pull-left[ <img src="img/melb-2011-pt-share-to-central-sa2.png" width="600" style="display: block; margin: auto;"/> SA2 Census Journey to Work data - Loader (2014)] ] .pull-right[ <span style="text-align: justified"> <blockquote>a type of thematic map in which areas are <br>shaded or patterned in proportion to a <br> statistical variable that represents an aggregate <br> summary of a geographic characteristic within <br>each area. <p> <i>.cite[Source - Wikipedia]</i> </span> </blockquote> ] .pull-left[.tiny[https://chartingtransport.com/2013/03/03/how-commuters-got-to-workplaces-in-melbourne-2006-and-2011/ ]] --- .pull[ # Sunshine Choropleth - Early prototype .centre[ <img src="img/Sunshine VITM Choropleth.png" height=550>] ] ??? Talk about trying VITM polygons --- .pull-left[ #1. Generating Origin Points <br> <br> - Generate a hex grid of lots of origin points<br> to query travel time to your destination from <br><br> ####Need to consider: <br> - Excluding the River or areas with no residents <br> - Curvature of the Earth ] .pull-right[ ####Talk Plan 1. <b>Generating Origin Points</b> 2. Running the queries 3. Extracting the results 4. Using Leaflet to plot the results 5. Adjusting the scale 6. Where to next? ] --- background-position: top; background-image: url("/img/100 Polka dots Sunshine.png") background-size: cover; .pull[ # First go at mapping 100 points ] <!-- .centre[ <img src="img/100 Polka dots Sunshine.png" height=570/> ] --> ??? 100 points with transport networks underneath -Polka Dot Map --- .pull-left[ #1. Generating Origin Points MelbourneSPDF is a spatial polygons data frame of<br> Metropolitan Melbourne ```r library(magrittr) library(leaflet) library(sp) size <- 0.005 hex_points <- spsample( MelbourneSPDF, type = "hexagonal", cellsize = size) length(hex_points) [1] 36639 ``` ] .pull-right[  ] --- .pull-left[ #1. Generating Origin Points MelbourneSPDF is a spatial polygons data frame of<br> Metropolitan Melbourne ```r library(magrittr) library(leaflet) library(sp) size <- 0.005 hex_points <- spsample( MelbourneSPDF, type = "hexagonal", cellsize = size) length(hex_points) [1] 36639 ``` ] .pull-right[ <img src="img/Zoom dots.png" width="550" style="display: block; margin: auto;"/> ] --- .pull-left[ #1. Generating Origin Points MelbourneSPDF is a spatial polygons data frame of<br> Metropolitan Melbourne ```r library(magrittr) library(leaflet) library(sp) size <- 0.005 hex_points <- spsample( MelbourneSPDF, type = "hexagonal", cellsize = size) #Want to create polygons around these points? hex_grid <- HexPoints2SpatialPolygons( hex_points, dx = size) ``` ] .pull-right[  ] -- .pull-left[ ```r #how do we map this in leaflet? #call leaflet (opens interactively in Viewer window) leaflet() %>% addTiles() %>% # or addTiles(url=tileURL)%>% addCircles(data=hex_points) ``` ] --- .pull-left[ #1. Generating Origin Points ###Selecting the closest x points You don't want to run up hundreds of dollars of google API costs! How to filter the huge number of points you've generated? - Initially I though this was a complex problem, but there's a simple solution: - Calculate the (rough) distance from each point to the destination - Sort by distance - Take the first x points from your data frame - This effectively fans out origin points from the destination until<br> you get to your API calls budget - avoids messing around with selecting spatial areas to include or exclude ] .pull-right[ ####Talk Plan 1. <b>Generating Origin Points</b> 2. Running the queries 3. Extracting the results 4. Using Leaflet to plot the results 5. Adjusting the scale 6. Where to next? ] --- .pull-left[ #1. Filter the Origin Points ###Calculate distance from your origin centroid & sort ```r #adds dist_km column to centroid_points #from https://gis.stackexchange.com/questions/233373/distance-between-coordinates-in-r library(data.table) library(geosphere) setDT(centroid_points)[, dist_km := distGeo(matrix(c(lon, lat), ncol = 2), matrix(c(long=origin_centroid[[1]][2],lat=origin_centroid[[1]][1]), ncol = 2))/1000] #arrange centroid_points in order of distance centroid_points<-arrange(centroid_points,dist_km) ``` ] --- .pull-left[ #2. Running the queries (API Key & split) - Set up the API Key (boring!) - Activate a free trial, but watch your spending: https://cloud.google.com/free - We'll be using the Distance Matrix API, which is limited to 100 OD pairs per call - So we need to chunk our code to send <=100 points per call - I did this with the split() function - first assigning a 'tranche' number to each point ```r #assign a tranche number to every point centroid_points$tranche<-factor( ceiling(as.numeric(rownames(centroid_points))/100) ) #split the list into tranches of 100 centroid_split<-split(centroid_points,centroid_points$tranche) #result: a list of data frames ``` ] .pull-right[ ####Talk Plan 1. Generating Origin Points 2. <b>Running the queries</b> 3. Extracting the results 4. Using Leaflet to plot the results 5. Adjusting the scale 6. Where to next? ] ??? if you want you can limit your API key so that it can only call Google Distance Matrix --- .pull-left[ #Prepare the origin points - Reformat for the API calls ] .pull-left[ ```r library(purrr) #fixing the format tranches<-totalpoints/100 #initiate origins origins<-list() for(i in 1:tranches){ origins[[i]]<-map2( (centroid_split[[i]]$lat), (centroid_split[[i]]$lon), ~c(.x,.y) ) } ``` ] .pull-right[ <img src="/img/Empty tram.jpg" width=650> ] --- .pull-left[ #2. Running the queries ```r APIcall<-function(tranche, origins, destinations, output){ #calls to google_distance by mode transit <- google_distance(origins = origins[[tranche]], destinations=destinations, key = map_key, mode="transit", departure_time=depart ) transit$time<-("depart.at"=paste0(depart)) #(repeat for driving) ``` ... ```r #encapsulate all output into a list chunked by tranche number output$transit[[tranche]] <- transit output$driving[[tranche]] <- driving return(output) } ``` ] .pull-right[ ####Talk Plan 1. Generating Origin Points 2. <b>Running the queries</b> 3. Extracting the results 4. Using Leaflet to plot the results 5. Adjusting the scale 6. Where to next? ] --- .pull-left[ #3. Extracting the results this is how I feel about nested lists: ] .pull-right[ ####Talk Plan 1. Generating Origin Points 2. Running the queries 3. <b>Extracting the results</b> 4. Using Leaflet to plot the results</b> 5. Adjusting the scale 6. Where to next? ] .pull-left[ (ARGHHHH!!!) ] <br><br> .centre[ <iframe src="https://giphy.com/embed/Wn5uhn1as7ZYnD2Zx4" width="360" height="460" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p> ] --- .pull-left[ #3. Extracting the results ####(Nested lists and accessors) - You *could* use a really ugly for loop<br>(this is *definitely not* what I did when I was in a hurry) ;) - Use the googleway accessor functions: - this will make life slightly easier - I would advise using functional programming - (do as I say, not as I do!) <br> Links:<br> <a href="https://www.symbolix.com.au/blog-main/fhcs36y9h8zftenfhwpsredbeyf3zf">Symbolix Googleway Accessor Vignette blog</a> <a href="https://www.rdocumentation.org/packages/googleway/versions/2.7.1/topics/access_result">Googleway access_result documentation</a> <a href="https://cran.r-project.org/web/packages/googleway/vignettes/googleway-vignette.html#google-distance-api">Googleway Vignette #google-distance-api</a> ] .pull-right[ ####Talk Plan 1. Generating Origin Points 2. Running the queries 3. <b>Extracting the results</b> 4. Using Leaflet to plot the results 5. Adjusting the scale 6. Where to next? ] --- .pull-left[ #4. Using Leaflet to plot the results <br> library(magrittr) is your friend! - you can build up maps layer by layer ####Leaflet 101 - Background Tiles - Adding Points Markers - Adding Polylines - (You can add Polygons too, and tooltips) ] .pull-right[ ####Talk Plan 1. Generating Origin Points 2. Running the queries 3. Extracting the results 4. <b>Using Leaflet to plot the results</b> 5. Adjusting the scale 6. Where to next? ] --- .pull[ # 4. Leaflet - change the base map The default Leaflet basemap is OpenStreetMaps ```r library(leaflet) leaflet() %>% addTiles() %>% setView(lat = -37.82 , lng = 144.96, zoom = 13) ``` <div id="htmlwidget-77c6834f0d327c4c0a8f" style="width:100%;height:504px;" class="leaflet html-widget"></div> <script type="application/json" data-for="htmlwidget-77c6834f0d327c4c0a8f">{"x":{"options":{"crs":{"crsClass":"L.CRS.EPSG3857","code":null,"proj4def":null,"projectedBounds":null,"options":{}}},"calls":[{"method":"addTiles","args":["//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",null,null,{"minZoom":0,"maxZoom":18,"tileSize":256,"subdomains":"abc","errorTileUrl":"","tms":false,"noWrap":false,"zoomOffset":0,"zoomReverse":false,"opacity":1,"zIndex":1,"detectRetina":false,"attribution":"© <a href=\"http://openstreetmap.org\">OpenStreetMap<\/a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA<\/a>"}]}],"setView":[[-37.82,144.96],13,[]]},"evals":[],"jsHooks":[]}</script> ] --- .pull[ # 4. Leaflet - CartoDB I like CartoDB much better - just add the tileURL 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png' into the addTiles() ] ```r library(leaflet) leaflet() %>% addTiles('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png') %>% setView(lat = -37.82 , lng = 144.96, zoom = 13) ``` <div id="htmlwidget-a1b9a4a08dfa86f9b66f" style="width:100%;height:504px;" class="leaflet html-widget"></div> <script type="application/json" data-for="htmlwidget-a1b9a4a08dfa86f9b66f">{"x":{"options":{"crs":{"crsClass":"L.CRS.EPSG3857","code":null,"proj4def":null,"projectedBounds":null,"options":{}}},"calls":[{"method":"addTiles","args":["http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",null,null,{"minZoom":0,"maxZoom":18,"tileSize":256,"subdomains":"abc","errorTileUrl":"","tms":false,"noWrap":false,"zoomOffset":0,"zoomReverse":false,"opacity":1,"zIndex":1,"detectRetina":false}]}],"setView":[[-37.82,144.96],13,[]]},"evals":[],"jsHooks":[]}</script> ??? More info on basemaps:<br> https://rstudio.github.io/leaflet/basemaps.html More Carto Basemaps<br> https://carto.com/help/building-maps/basemap-list/ --- .pull[ # 4. Leaflet - adding points ] ```r library(leaflet) leaflet() %>% addTiles(tileURL)%>% addCircles(data=centroid_points, lat=~lat, lng=~lon, color="#0072CE") ``` <div id="htmlwidget-642ee42bfb533cbf2e32" style="width:100%;height:504px;" class="leaflet html-widget"></div> <script type="application/json" data-for="htmlwidget-642ee42bfb533cbf2e32">{"x":{"options":{"crs":{"crsClass":"L.CRS.EPSG3857","code":null,"proj4def":null,"projectedBounds":null,"options":{}}},"calls":[{"method":"addTiles","args":["http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",null,null,{"minZoom":0,"maxZoom":18,"tileSize":256,"subdomains":"abc","errorTileUrl":"","tms":false,"noWrap":false,"zoomOffset":0,"zoomReverse":false,"opacity":1,"zIndex":1,"detectRetina":false}]},{"method":"addCircles","args":[[-37.8168710787844,-37.8125409517655,-37.8125409517655,-37.8168710787844,-37.8168710787844,-37.8125409517655,-37.8125409517655,-37.8212012058033,-37.8212012058033,-37.8082108247465,-37.8082108247465,-37.8082108247465,-37.8168710787844,-37.8168710787844,-37.8212012058033,-37.8212012058033,-37.8125409517655,-37.8125409517655,-37.8082108247465,-37.8082108247465,-37.8255313328222,-37.8038806977276,-37.8038806977276,-37.8255313328222,-37.8255313328222,-37.8212012058033,-37.8212012058033,-37.8168710787844,-37.8168710787844,-37.8038806977276,-37.8038806977276,-37.8255313328222,-37.8255313328222,-37.8082108247465,-37.8082108247465,-37.8125409517655,-37.8125409517655,-37.8038806977276,-37.8038806977276,-37.8298614598412,-37.8298614598412,-37.8212012058033,-37.8212012058033,-37.7995505707087,-37.7995505707087,-37.8255313328222,-37.7995505707087,-37.8255313328222,-37.8168710787844,-37.8168710787844,-37.8298614598412,-37.8298614598412,-37.8082108247465,-37.8082108247465,-37.7995505707087,-37.7995505707087,-37.8038806977276,-37.8038806977276,-37.8298614598412,-37.8298614598412,-37.8125409517655,-37.8125409517655,-37.8212012058033,-37.8212012058033,-37.8255313328222,-37.8255313328222,-37.8341915868601,-37.7995505707087,-37.7995505707087,-37.8341915868601,-37.8341915868601,-37.7952204436898,-37.7952204436898,-37.8168710787844,-37.8168710787844,-37.8298614598412,-37.8298614598412,-37.7952204436898,-37.7952204436898,-37.8341915868601,-37.8341915868601,-37.8082108247465,-37.8038806977276,-37.8082108247465,-37.8038806977276,-37.8125409517655,-37.8125409517655,-37.7952204436898,-37.7995505707087,-37.7952204436898,-37.7995505707087,-37.8255313328222,-37.8255313328222,-37.8341915868601,-37.8341915868601,-37.8212012058033,-37.8212012058033,-37.8298614598412,-37.8298614598412,-37.838521713879,-37.838521713879,-37.8168710787844,-37.8168710787844,-37.7908903166709,-37.7952204436898,-37.7952204436898,-37.838521713879,-37.838521713879,-37.7908903166709,-37.7908903166709,-37.8038806977276,-37.8038806977276,-37.8082108247465,-37.8082108247465,-37.8341915868601,-37.8341915868601,-37.7995505707087,-37.7995505707087,-37.7908903166709,-37.7908903166709,-37.838521713879,-37.838521713879,-37.8125409517655,-37.8125409517655,-37.8255313328222,-37.8255313328222,-37.8298614598412,-37.8298614598412,-37.8212012058033,-37.8212012058033,-37.7952204436898,-37.7952204436898,-37.7908903166709,-37.7908903166709,-37.838521713879,-37.838521713879,-37.8341915868601,-37.8341915868601,-37.8168710787844,-37.8168710787844,-37.8428518408979,-37.8038806977276,-37.8038806977276,-37.8428518408979,-37.8428518408979,-37.7995505707087,-37.7995505707087,-37.7865601896519,-37.7865601896519,-37.8082108247465,-37.8082108247465,-37.7908903166709,-37.7908903166709,-37.8428518408979,-37.7865601896519,-37.8428518408979,-37.7865601896519,-37.7952204436898,-37.7952204436898,-37.838521713879,-37.838521713879,-37.8255313328222,-37.8255313328222,-37.8298614598412,-37.8298614598412,-37.8125409517655,-37.8125409517655,-37.7865601896519,-37.7865601896519,-37.8428518408979,-37.8428518408979,-37.8212012058033,-37.8212012058033,-37.8341915868601,-37.8341915868601,-37.7908903166709,-37.7908903166709,-37.7865601896519,-37.7865601896519,-37.8038806977276,-37.7995505707087,-37.8168710787844,-37.8038806977276,-37.7995505707087,-37.8168710787844,-37.8428518408979,-37.838521713879,-37.8428518408979,-37.838521713879,-37.8471819679168,-37.8471819679168,-37.8082108247465,-37.7952204436898,-37.8082108247465,-37.7952204436898,-37.782230062633,-37.8471819679168,-37.8471819679168,-37.782230062633,-37.782230062633,-37.8298614598412,-37.8298614598412,-37.8255313328222,-37.8255313328222,-37.7865601896519,-37.7865601896519,-37.782230062633,-37.782230062633,-37.8471819679168,-37.8471819679168,-37.8341915868601,-37.8125409517655,-37.8341915868601,-37.7908903166709,-37.8125409517655,-37.7908903166709,-37.8428518408979,-37.8428518408979,-37.8212012058033,-37.8212012058033,-37.782230062633,-37.782230062633,-37.838521713879,-37.838521713879,-37.8471819679168,-37.8471819679168,-37.7995505707087,-37.7995505707087,-37.8038806977276,-37.8038806977276,-37.7952204436898,-37.8168710787844,-37.7952204436898,-37.8168710787844,-37.7865601896519,-37.7865601896519,-37.8082108247465,-37.782230062633,-37.8082108247465,-37.782230062633,-37.8515120949358,-37.8428518408979,-37.8428518408979,-37.7908903166709,-37.7908903166709,-37.8515120949358,-37.8515120949358,-37.8471819679168,-37.8298614598412,-37.8471819679168,-37.8298614598412,-37.8341915868601,-37.7778999356141,-37.7778999356141,-37.8341915868601,-37.8255313328222,-37.8255313328222,-37.8515120949358,-37.8515120949358,-37.7778999356141,-37.7778999356141,-37.8125409517655,-37.8125409517655,-37.838521713879,-37.838521713879,-37.8212012058033,-37.8212012058033,-37.782230062633,-37.782230062633,-37.7865601896519,-37.7778999356141,-37.7778999356141,-37.7865601896519,-37.8515120949358,-37.8515120949358,-37.7995505707087,-37.8471819679168,-37.7995505707087,-37.8471819679168,-37.7952204436898,-37.7952204436898,-37.8038806977276,-37.8038806977276,-37.8428518408979,-37.8428518408979,-37.7778999356141,-37.7778999356141,-37.8168710787844,-37.8168710787844,-37.7908903166709,-37.7908903166709,-37.8515120949358,-37.8082108247465,-37.8082108247465,-37.782230062633,-37.782230062633,-37.8298614598412,-37.8341915868601,-37.8298614598412,-37.8341915868601,-37.8558422219547,-37.8558422219547,-37.8255313328222,-37.8255313328222,-37.7865601896519,-37.838521713879,-37.7778999356141,-37.7778999356141,-37.7865601896519,-37.838521713879,-37.8471819679168,-37.8558422219547,-37.8558422219547,-37.7735698085952,-37.7735698085952,-37.7735698085952,-37.8515120949358,-37.8125409517655,-37.8125409517655,-37.8212012058033,-37.8558422219547,-37.7735698085952,-37.7735698085952,-37.8212012058033,-37.8428518408979,-37.7952204436898,-37.7995505707087,-37.7952204436898,-37.7995505707087,-37.782230062633,-37.782230062633,-37.7778999356141,-37.7778999356141,-37.7908903166709,-37.7735698085952,-37.8038806977276,-37.7735698085952,-37.7908903166709,-37.8038806977276,-37.8558422219547,-37.8515120949358,-37.8168710787844,-37.8168710787844,-37.8471819679168,-37.8341915868601,-37.7865601896519,-37.7865601896519,-37.8341915868601,-37.8082108247465,-37.8082108247465,-37.8298614598412,-37.8298614598412,-37.7735698085952,-37.7735698085952,-37.838521713879,-37.838521713879,-37.8558422219547,-37.8255313328222,-37.8255313328222,-37.7778999356141,-37.7778999356141,-37.8601723489736,-37.8428518408979,-37.8601723489736,-37.8601723489736,-37.782230062633,-37.782230062633,-37.8125409517655,-37.8125409517655,-37.7692396815762,-37.7692396815762,-37.7735698085952,-37.7735698085952,-37.8601723489736,-37.8515120949358,-37.8212012058033,-37.7952204436898,-37.8212012058033,-37.7692396815762,-37.7692396815762,-37.7952204436898,-37.7995505707087,-37.7995505707087,-37.8558422219547,-37.7908903166709,-37.7908903166709,-37.8471819679168,-37.8601723489736,-37.7692396815762,-37.7692396815762,-37.8038806977276,-37.8038806977276,-37.7865601896519,-37.7865601896519,-37.7778999356141,-37.7778999356141,-37.8168710787844,-37.8341915868601,-37.8168710787844,-37.8341915868601,-37.7735698085952,-37.7735698085952,-37.7692396815762,-37.7692396815762,-37.838521713879,-37.838521713879,-37.8601723489736,-37.8298614598412,-37.8298614598412,-37.8082108247465,-37.8082108247465,-37.8558422219547,-37.782230062633,-37.8515120949358,-37.782230062633,-37.8428518408979,-37.8255313328222,-37.8255313328222,-37.7692396815762,-37.7692396815762,-37.8601723489736,-37.8645024759925,-37.8645024759925,-37.8471819679168,-37.8125409517655,-37.7952204436898,-37.8125409517655,-37.7952204436898,-37.7908903166709,-37.7735698085952,-37.7735698085952,-37.7908903166709,-37.8645024759925,-37.8212012058033,-37.7995505707087,-37.8212012058033,-37.7649095545573,-37.7995505707087,-37.7778999356141,-37.7778999356141,-37.7649095545573,-37.7649095545573,-37.7865601896519,-37.7865601896519,-37.8645024759925,-37.8558422219547,-37.7692396815762,-37.7649095545573,-37.7692396815762,-37.7649095545573,-37.8038806977276,-37.8038806977276,-37.8601723489736,-37.8515120949358,-37.8341915868601,-37.838521713879,-37.8341915868601,-37.838521713879,-37.782230062633,-37.7649095545573,-37.7649095545573,-37.782230062633,-37.8645024759925,-37.8168710787844,-37.8168710787844,-37.8298614598412,-37.8298614598412,-37.8428518408979,-37.8082108247465,-37.8082108247465,-37.7735698085952,-37.7735698085952,-37.7692396815762,-37.7649095545573,-37.7692396815762,-37.7649095545573,-37.8255313328222,-37.8255313328222,-37.8645024759925,-37.8471819679168,-37.7778999356141,-37.7778999356141,-37.8558422219547,-37.8601723489736,-37.7908903166709,-37.7952204436898,-37.7908903166709,-37.7952204436898,-37.8125409517655,-37.8125409517655,-37.7865601896519,-37.7865601896519,-37.7995505707087,-37.7649095545573,-37.7649095545573,-37.7995505707087,-37.8212012058033,-37.8212012058033,-37.8515120949358,-37.8688326030115],[144.974477547914,144.971977547914,144.976977547914,144.969477547914,144.979477547914,144.966977547914,144.981977547914,144.971977547914,144.976977547914,144.974477547914,144.969477547914,144.979477547914,144.964477547914,144.984477547914,144.966977547914,144.981977547914,144.961977547914,144.986977547914,144.964477547914,144.984477547914,144.974477547914,144.971977547914,144.976977547914,144.969477547914,144.979477547914,144.961977547914,144.986977547914,144.959477547914,144.989477547914,144.966977547914,144.981977547914,144.964477547914,144.984477547914,144.959477547914,144.989477547914,144.956977547914,144.991977547914,144.961977547914,144.986977547914,144.971977547914,144.976977547914,144.956977547914,144.991977547914,144.974477547914,144.969477547914,144.959477547914,144.979477547914,144.989477547914,144.954477547914,144.994477547914,144.966977547914,144.981977547914,144.954477547914,144.994477547914,144.964477547914,144.984477547914,144.956977547914,144.991977547914,144.961977547914,144.986977547914,144.951977547914,144.996977547914,144.951977547914,144.996977547914,144.954477547914,144.994477547914,144.974477547914,144.959477547914,144.989477547914,144.969477547914,144.979477547914,144.971977547914,144.976977547914,144.949477547914,144.999477547914,144.956977547914,144.991977547914,144.966977547914,144.981977547914,144.964477547914,144.984477547914,144.949477547914,144.951977547914,144.999477547914,144.996977547914,144.946977547914,145.001977547914,144.961977547914,144.954477547914,144.986977547914,144.994477547914,144.949477547914,144.999477547914,144.959477547914,144.989477547914,144.946977547914,145.001977547914,144.951977547914,144.996977547914,144.971977547914,144.976977547914,144.944477547914,145.004477547914,144.974477547914,144.956977547914,144.991977547914,144.966977547914,144.981977547914,144.969477547914,144.979477547914,144.946977547914,145.001977547914,144.944477547914,145.004477547914,144.954477547914,144.994477547914,144.949477547914,144.999477547914,144.964477547914,144.984477547914,144.961977547914,144.986977547914,144.941977547914,145.006977547914,144.944477547914,145.004477547914,144.946977547914,145.001977547914,144.941977547914,145.006977547914,144.951977547914,144.996977547914,144.959477547914,144.989477547914,144.956977547914,144.991977547914,144.949477547914,144.999477547914,144.939477547914,145.009477547914,144.974477547914,144.941977547914,145.006977547914,144.969477547914,144.979477547914,144.944477547914,145.004477547914,144.971977547914,144.976977547914,144.939477547914,145.009477547914,144.954477547914,144.994477547914,144.964477547914,144.966977547914,144.984477547914,144.981977547914,144.946977547914,145.001977547914,144.951977547914,144.996977547914,144.939477547914,145.009477547914,144.941977547914,145.006977547914,144.936977547914,145.011977547914,144.961977547914,144.986977547914,144.959477547914,144.989477547914,144.936977547914,145.011977547914,144.944477547914,145.004477547914,144.949477547914,144.999477547914,144.956977547914,144.991977547914,144.936977547914,144.939477547914,144.934477547914,145.011977547914,145.009477547914,145.014477547914,144.954477547914,144.946977547914,144.994477547914,145.001977547914,144.971977547914,144.976977547914,144.934477547914,144.941977547914,145.014477547914,145.006977547914,144.974477547914,144.966977547914,144.981977547914,144.969477547914,144.979477547914,144.936977547914,145.011977547914,144.934477547914,145.014477547914,144.951977547914,144.996977547914,144.964477547914,144.984477547914,144.961977547914,144.986977547914,144.939477547914,144.931977547914,145.009477547914,144.944477547914,145.016977547914,145.004477547914,144.949477547914,144.999477547914,144.931977547914,145.016977547914,144.959477547914,144.989477547914,144.941977547914,145.006977547914,144.956977547914,144.991977547914,144.934477547914,145.014477547914,144.931977547914,145.016977547914,144.936977547914,144.929477547914,145.011977547914,145.019477547914,144.946977547914,145.001977547914,144.929477547914,144.954477547914,145.019477547914,144.994477547914,144.974477547914,144.944477547914,145.004477547914,144.939477547914,145.009477547914,144.969477547914,144.979477547914,144.951977547914,144.931977547914,144.996977547914,145.016977547914,144.934477547914,144.971977547914,144.976977547914,145.014477547914,144.929477547914,145.019477547914,144.964477547914,144.984477547914,144.966977547914,144.981977547914,144.926977547914,145.021977547914,144.936977547914,145.011977547914,144.926977547914,145.021977547914,144.949477547914,144.999477547914,144.941977547914,144.961977547914,144.986977547914,145.006977547914,144.959477547914,144.989477547914,144.929477547914,144.946977547914,145.019477547914,145.001977547914,144.931977547914,145.016977547914,144.926977547914,145.021977547914,144.939477547914,145.009477547914,144.956977547914,144.991977547914,144.924477547914,145.024477547914,144.934477547914,145.014477547914,144.994477547914,144.924477547914,145.024477547914,144.944477547914,145.004477547914,144.926977547914,144.929477547914,145.021977547914,145.019477547914,144.971977547914,144.976977547914,144.924477547914,145.024477547914,144.936977547914,144.931977547914,144.951977547914,144.996977547914,145.011977547914,145.016977547914,145.006977547914,144.966977547914,144.981977547914,144.974477547914,144.969477547914,144.979477547914,144.999477547914,144.921977547914,145.026977547914,144.921977547914,144.986977547914,144.964477547914,144.984477547914,145.026977547914,145.014477547914,144.926977547914,144.924477547914,145.021977547914,145.024477547914,144.939477547914,145.009477547914,144.946977547914,145.001977547914,144.929477547914,144.959477547914,144.921977547914,144.989477547914,145.019477547914,145.026977547914,144.991977547914,145.004477547914,144.919477547914,145.029477547914,145.011977547914,144.924477547914,144.931977547914,145.016977547914,145.024477547914,144.919477547914,145.029477547914,144.921977547914,145.026977547914,144.954477547914,144.994477547914,144.926977547914,145.021977547914,144.996977547914,144.919477547914,145.029477547914,144.941977547914,145.006977547914,144.974477547914,145.019477547914,144.969477547914,144.979477547914,144.934477547914,145.014477547914,144.916977547914,145.031977547914,144.971977547914,144.976977547914,144.949477547914,144.999477547914,144.984477547914,145.009477547914,144.916977547914,144.921977547914,145.031977547914,144.966977547914,144.981977547914,145.026977547914,144.919477547914,145.029477547914,145.001977547914,144.924477547914,145.024477547914,145.016977547914,144.989477547914,144.961977547914,144.986977547914,144.916977547914,145.031977547914,144.926977547914,145.021977547914,144.936977547914,145.011977547914,144.914477547914,144.919477547914,145.034477547914,145.029477547914,144.944477547914,145.004477547914,144.956977547914,144.991977547914,144.921977547914,145.026977547914,144.994477547914,144.916977547914,145.031977547914,144.914477547914,145.034477547914,145.006977547914,144.929477547914,145.014477547914,145.019477547914,145.024477547914,144.914477547914,145.034477547914,144.951977547914,144.996977547914,144.999477547914,144.971977547914,144.976977547914,145.021977547914,144.911977547914,144.916977547914,145.036977547914,145.031977547914,144.919477547914,144.939477547914,145.009477547914,145.029477547914,144.981977547914,144.911977547914,144.914477547914,145.036977547914,144.974477547914,145.034477547914,144.931977547914,145.016977547914,144.969477547914,144.979477547914,144.921977547914,145.026977547914,144.986977547914,145.011977547914,144.946977547914,144.964477547914,145.001977547914,144.984477547914,144.911977547914,145.036977547914,145.004477547914,145.019477547914,144.914477547914,144.916977547914,145.034477547914,145.031977547914,144.924477547914,144.959477547914,144.989477547914,145.024477547914,144.991977547914,144.909477547914,145.039477547914,144.911977547914,145.036977547914,145.029477547914,144.909477547914,145.039477547914,144.934477547914,145.014477547914,144.941977547914,144.954477547914,145.006977547914,144.994477547914,144.909477547914,145.039477547914,144.996977547914,145.026977547914,144.926977547914,145.021977547914,145.016977547914,145.009477547914,144.914477547914,144.911977547914,145.034477547914,145.036977547914,144.906977547914,145.041977547914,144.916977547914,145.031977547914,144.909477547914,144.949477547914,144.999477547914,145.039477547914,144.906977547914,145.041977547914,145.024477547914,144.979477547914],10,null,null,{"interactive":true,"className":"","stroke":true,"color":"#0072CE","weight":5,"opacity":0.5,"fill":true,"fillColor":"#0072CE","fillOpacity":0.2},null,null,null,{"interactive":false,"permanent":false,"direction":"auto","opacity":1,"offset":[0,0],"textsize":"10px","textOnly":false,"className":"","sticky":true},null,null]}],"limits":{"lat":[-37.8688326030115,-37.7649095545573],"lng":[144.906977547914,145.041977547914]}},"evals":[],"jsHooks":[]}</script> --- .pull-left[ # PTV shapefiles Can be found at:<br> https://www.ptv.vic.gov.au/footer/data-and-reporting/datasets/ Or download the whole lot in one go (more than you need)<br> https://discover.data.vic.gov.au/dataset/public-transport-a-collection-of-ptv-datasets <br><br> Of the many files, you might be interested in these:<br> <i>Paths:<br> <a href="https://discover.data.vic.gov.au/dataset/ptv-train-corridor-centreline">Train Corridor Centreline</a><br> <a href="https://discover.data.vic.gov.au/dataset/ptv-metro-tram-routes">Metro Tram Routes</a><br> <a href="https://discover.data.vic.gov.au/dataset/ptv-metro-bus-routes">Metro Bus Routes</a><br> Stops/Stations as shapefiles:<br> <a href="https://discover.data.vic.gov.au/dataset/ptv-metro-train-stations">Metro Train Stations</a><br> <a href="https://discover.data.vic.gov.au/dataset/ptv-metro-tram-stops">Metro Tram Stops</a><br> <a href="https://discover.data.vic.gov.au/dataset/ptv-metro-bus-stops">Metro Bus Stops</a><br> </i> You can also get all the stops easily out of GTFS text files if you don't want to deal with shapefiles (see my <a href="https://bit.ly/BM-R-Mapping-Slides">R Ladies talk</a>) ] --- .pull-left[ # 4. Leaflet - adding polylines (paths) and polygons ] .pull-left[ ```r #addPolylines leafletmap%<>% addPolylines(data=metro_lines, weight=0.6, color="#0072CE" ) #addPolygons leafletmap %<>% addPolygons(data=SA2polygons, color=~pal(as.numeric(SA2_5DIG16)), label=~paste(SA2_NAME16, SA2_5DIG16,sep=" - "), labelOptions = labelOptions(noHide = F), fillOpacity=0.5 ) ``` ] .pull-right[ <img src="/img/Polygons snip.png" width=600/> ] --- .pull-left[ # Add legend & scale bar ####Legend ```r #where I have used this palette in leaflet library(RColorBrewer) pal <- colorNumeric( palette = "RdYlGn",reverse=TRUE, domain=as.numeric(outputmins$diff.mins)) leafletmap%<>% addLegend("bottomright", data=outputmins, pal = pal, values = ~diff.mins, title = "Minutes Difference (PT-PV)", opacity = 1) ``` ####Scalebar ```r leafletmap%<>%addScaleBar(position = "bottomleft", options = scaleBarOptions(maxWidth = 100, metric = TRUE, imperial = FALSE, updateWhenIdle = TRUE)) ``` ] .pull-right[  ] --- layout:false background-position: middle background-size: 92% background-image: url("img/Sea of Green.png") .pull-left[ # 5. Adjusting the scale ] --- layout:true <div class="my-footer"><span>     Belinda Maher - Visualising Travel Time Differences Between Modes       https://belinda-maher-melburn.netlify.com/ </span></div> <div class="my-css"> <style type="text/css"> .tiny {font-size: 60%;}</div> </style> --- .pull-left[ # 5. Adjusting the scale - Points in the river - Other outliers make it not sensible to use the default scale <img src="/img/1 Spring Street 2019-08-20 171831.png" width=750/> ] .pull-right[ ####Talk Plan 1. Generating Origin Points 2. Running the queries 3. Extracting the results 4. Using Leaflet to plot the results 5. <b>Adjusting the scale</b> 6. Where to next? ] --- layout:false background-size: 100% background-image: url("img/Outliers.png") .pull[ #5. Outliers] --- layout:false background-position: center top; background-size:85% background-image: url("img/Melton to Sunshine 2019-08-22 151730.png") .pull-left[ #Melton Example ] --- layout:true <div class="my-footer"><span>     Belinda Maher - Visualising Travel Time Differences Between Modes       https://belinda-maher-melburn.netlify.com/ </span></div> <div class="my-css"> <style type="text/css"> .tiny {font-size: 60%;}</div> </style> --- .pull[ # 6. Where to next? ] .pull-left[ - Applications: Bus Planning - Lining up arrival not departure - More points, closer together and for all of Melbourne - and multiple time samples over peak hour - Automating querying and storing for other destinations - Perceived reliability and number of changes - Plotting paths taken by these predicted trips - googlepolylines and google directions API - Better visualisation of the data (I'm not really a mapping person) - See also: <a href="https://www.conveyal.com/analysis">Conveyal</a> and <a href="https://remix.github.io/ca-transit-car/">Remix</a> ] .pull-right[ ####Talk Plan 1. Generating Origin Points 2. Running the queries 3. Extracting the results 4. Using Leaflet to plot the results 5. Adjusting the scale 6. <b>Where to next?</b> ] --- layout:false background-size: 100% background-image: url("img/Remix Jane.png") .pull[ # Remix Example ] --- .pull-left[ #Questions? <img src="img/FSS.jpg" width=840> ] <!-- Add icon library --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> .pull-right[ <span style="text-align: center;"> <br> .small[<p style="text-align: center;"> <img src="/img/Red Rattler.jpg" width=200 /><br> <a href="mailto:belinda.maher@gmail.com" class="fa fa-envelope"> belinda.maher@gmail.com</a> <br> <a href="http://about.me/minga" class="fa fa-globe"> http://about.me/minga</a><br> <a href="https://twitter.com/surgisse" class="fa fa-twitter"> @Surgisse</a><br> <a href="https://www.linkedin.com/in/belindamaher/" class="fa fa-linkedin"> belindamaher</a><br> <a href="https://github.com/surgissant/" class="fa fa-github"> surgissant</a></span> </p> <br> (be nice, <br> this is a proof of concept)!]] --- count:false FIN --- count:false .pull-left[ #Loading Shapefiles ] .pull-left[ To avoid some of the frustrations of dealing with shapefiles: (When you know where your shapefile is but not what it's called) ```r library(rgdal) files <- dir(filepath) shapefile <- grep("shp$", files, value=TRUE)# find the shapefile in the file list (looks for *.shp) shape <- readOGR(dsn=paste0(filepath,"\\",shapefile), GDAL1_integer64_policy = TRUE, stringsAsFactors=FALSE) ``` ] <!--# get the first layer from it layer <- ogrListLayers(paste0(filepath,shapefile))[1] layer=layer,--> ??? If you don't specify a layer it will default to the first one --- layout:false count:false background-image: url("img/Destination 1 Spring St Fullscreen.png") background-size: 100%