Driving time interpolation map in R (using OSRM, leaflet, raster, ggmap)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to this video my name is Martin and this is a map of the driving times to the closest hospitals so basically it's an interpolation of how far is it from any point on the map to the closest hospital so you see their parts like pee nearby hospitals where you're going to take less than 20 minutes and other parts where you might have an hour or or even more and in this video I want to show you how to make this awesome app and we're going to use our leaflet we're going to use OS RM which is to calculate driving times from any point and let's get started so basically and save this so basically I made a post add up a little summary that I published on our pubs and what are you looking at here is basically the video version of this so if you're not interested in watching videos just head over to there to the text which I will link in a description and for this what we're going to use is we're going to use Hospital data of Switzerland okay now let's go step by step as I wrote you here surprised you can also do it there and a GG map or a GG plot map of the driving times which is basically static and for preparation we're going to use OS RM or SRM is a the open source routing machine and based on open street maps and it allows you to to calculate the shortest path and driving driving time or driving pass from point A to point B so that's what we're going to use and what you can use is you're going to use the OS RM package and which is a variable in our that I already have installed and by default by default okay it's interesting you already have it by default you don't have the localhost you have a Rooter project always run which is basically a public server for you to test and thing and if you're gonna use a lot if you're gonna have a lot of requests which we will need for having a random point interpolation and your advice you have your own server running and which sounds more difficult than it is because there is a docker image that you can get from docker hub and which is the OEM back-end and you have to download the weights and which you can find from your Frederick that de and here you can find for I advise you against downloading the whole continent just because it's 11 Europe is 19 gig go for one country that you're going to need and so it's only think it's 200 join in 90 megabyte so that's what we have done we have data I have Switzerland and in Mike and basically there to run the docker image it's it's well-documented so I just copied it but it's it's also what you find on the Orion back-end and how to run blahblahblah so mine is and dr. contain your list and I usually mine is already running up and running so all is fine if I didn't had I see now I saw that we already have that the localhost else who would do it we'll define it localhost and get optionally after localhost let's do it a bit that's better and we gonna use of course some data and we're going to use the hospital data from Switzerland which just to when I wrote up that thing on North pubs we had the 2016 data now last week 2017 was published so we can download this which I already have in my data folder I have my excel sheet that we are going to read in and using Excel rate for reading X and Excel we have now so team we should check out the maximum number of rows let's open this quickly and that's so the last row it's just a summary of whole of Switzerland we are not going to use this but the total number of rows is a hundred one hundred and eighty one net sorry to him yeah two hundred and eighty one so turn it eighty one so fewer than last year so you're gonna have these hospitals then we have in like we the data that is provided by the Swiss government as various other fields that are of great interest if you're doing other things like how many days to patients stay on average or how many births did happen but we're not necessarily requiring these at the moment okay so now my video of me doesn't work any more anywhere where were you we so we had imported the data we see it you have hospitals and next what are we gonna do this is not working we're gonna select the emergency hospitals we can load all of deaths with hospitals for emergency service that fills my standards so we need a emergency in acute medicine an F stands for emergency in German and CTS that we want one Hospital is at least equipped with a computed tomography otherwise I in my opinion other emergency um so is this what when you run and you see you have 84 and hospitals that offer emergency service and now the next step is that we're gonna use um cheechee map package at the beginning and then I use GT map to and geocode now I already have geocoded emergency hospital over geocoded let's load this because mu I made another video on geocoding with over the Google API M but it does cost you couple of cents per request for request so I already have it decoded from previously so that's what we can use in emergency hospitals geocoded and just how are we gonna select we can select the institution the address the city wart the long shirt that's and latitude and first you're gonna have two emergency hospitals of 2017 and we're going to left join this with what we already have no it's because GG map ism is interfering with the select left applier and now it will work exactly and you see that not all of them have a have coordinates it's because in the previous data set they wouldn't have coordinates or they wouldn't be classified as emergency hospital so I happen you cared at them just yet so we're gonna filter for the non of volunteered that's not working today and we can save this as missing geo code and only the missing geo code yuichi occurred now we're gonna create a new a new field address and of this I'm not gonna read in register yes then it's not displayed at all and missing J code address so let's run this and you see you got the five that we're missing geocodes is now J coded 84 columns that's already four rows that's correct so that's our new original hospitals with Geo rhythm next we yeah as I say it's advisable to save them and because next time you don't want to run and Google and geocoding again and just save it for this reason I'm gonna save this as 2017 got it here and next we're going to load the leaflet leaflet and we're gonna make a basic map basic map I have now what we are and so I have icons of hospitals that I put in my data and folder that I'm gonna use here for the leaflet map we have basic tiles that we're going to use cartodb now we human also use Open Street Map or any other tile and that you wish and we're just going to plot the decorated hospitals and what's the icon so let's do this and never preview so here it is that's the basic map that we're going to build on from now on now for a driving time surface and we want to request random dots so the idea behind is that we're gonna request random dots on a map and request for these random dots the driving time to all hospitals and then of course take the one that has the shortest time it shirts are basically here and here maybe we want them in their range and we're gonna use we say yeah that's one today and we're gonna use hundred and hundred points for the moment and we put random point which is generate random locations or in this range so you see you have like idea plus image and latitude and we can plot them where are these anyway yeah they're all over the place and for each of these point now we're gonna make requests and to our own OS or M server and using our own table let's use of this random points points oh yes we have to have no me as a data frame not a table and that we do and at first and we have the hospital what do we do here there's a hospital and yes sir these are the destination so the source where you live from it's the random points you go to all of the hospitals that we also need s data frame and we just have the driving time let's have this oh yeah it so this is for so let's see you have now one hundred and hundred locations for all of their already for hospitals how long does it take takes a couple of seconds and not even a second four hundred points and so hundred times 84 8400 and roots it just calculated and background and took less than a second summary oh yeah so basically you have always a source destination in the duration and out of these durations of course we want to have the smallest we're going to use the driving time and we're going to use the minimum of each row we're gonna convert it back to table and we're gonna say we're gonna make a new string and that we can plot and say hey this is that pop up and it's just a character of the meantime and we're gonna save this as min distance that's what you do now and we use a legend colors the minimal driving times and we add the base map basic map that we already have we're gonna add the marker points that is the minimal distance that we just have and we also can control have a layer control and which is this thing you can control and you see you have these points that we previously had it's just points and we have two driving time so from here it in the nearest hospital it's just here but it's like mountain roads it gonna take you 63 minutes and whereas if you live in Zurich there is nothing history now random point was chosen for Zurich but nearby suruc say you're gonna live here and near the German border it's gonna take you a bit less than half an hour to reach there to the Schaffhausen hospital and now what we gonna do is not going to do this for 100 points but we're gonna use it for one and for 10000 points and so we run all of this just because 10000 points is this we don't need to really see it but who cares we have it in a for loop we're gonna just run now and of course it takes you see per request of 100 it gonna take a bit less than a second as previous the next step after this is done is to calculate again the minimum distance that we can do yeah and we can see that there will be less minimum distances than the previous 10,000 points is because as you seen here and all points that we prove is that outside of Switzerland because we only download the data for Switzerland all points for example if we had a random point here it will be put here so we're gonna set they calculate the minimum distances and I have indistinct how many or they know yeah five hundred and fifty and save them again as many distance because why not and let's plot these or add these to the map and to map again with some colors and you see you already that you have this a lot of five thousand points and with the hospital now we don't have two hospitals but we know more or less say let's say zoom into Basel they have a bit of opacity let's put the opacity yeah it's better so let's click on this random point oh it's only going take 11 minutes from here we want to have interpolation so this is we're going to use the SP and the wrestler and package and for so let's load these two guys and we say it's pollution oh I was going to use s F and G stat [Music] which we all have and so I made this function and to calculate and what we're going to use is we're going to define the grid resolution so a lower grade resolution will be mean that individual grade the individual pixels are smaller on the original map and but I find 500 is it could compromise and we're going to input the data and maybe we have some computation on the change you have to change the coordinate system and what it will use is a nearest neighbor interpolation yeah so let's use this function if you're interested just look at a code done you know again did we save it you should saving it always good and again we're gonna use oh yes so basically that restaurant we have we can also plot so if we plot this you're gonna see this is the whole thing but of course so its own has some shape and country borders and so we're gonna use em from GAE diem from that you hack you can download and what is it this function is from it's from the raster package you can just download you can define the country code and define Switzerland it downloads it from whatever source we have now you see the shape and we're gonna shape it and what's the mask weather from the raster package and according to the borders of Switzerland so if you have this and we plot it you're gonna see it has now the proper shape that we want and I know map colors you find and make our map and you see that again you have parts where it's gonna take you forever to reach nearest hospital and parts where it's it's actually very close of course nearby hospital hospitals and we could have added a a legend a legend let's add this also to the final map and yeah you have it moist driving times larger and here we go also in the in my write-up I told you how to make it as a GT map static map which is not very hard we're gonna use we would also use maps and to get static map of Switzerland so with GT map you cannot used the Open Street Map and stuff you're going to use maps get the map and basically plot it have a nice plot and so yeah thanks for watching and see you next time
Info
Channel: Martin Geissmann
Views: 5,747
Rating: 4.9587631 out of 5
Keywords: driving time, driving time interpolation, driving time raster, driving time map, r leaflet, r raster, r map, ggmap, rstat, rstudio, osrm server, osrm backend, osrm, osrm docker, r osrm, nearest neighbor, r interpolation map, r raster map, raster interpolation
Id: zbEZDNlFJRY
Channel Id: undefined
Length: 23min 49sec (1429 seconds)
Published: Wed Apr 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.