Hacker News new | past | comments | ask | show | jobs | submit login
How to make fancy road trip maps with R and OpenStreetMap (andrewheiss.com)
364 points by sebg on June 2, 2023 | hide | past | favorite | 96 comments



To the author of this blog post (if he should read this):

This is amazing. Thanks so much for sharing.

And it’s even more amazing by noticing the fact that you and your wife go the extra mile and make it an adventure for your kids!

F*%k screens (iPads/iPhones). This kind of attention and adventure is what kids really need and deserve (imho).

I’m a proud father of 3 and I can imagine the joy and curiosity of your kids on this trip.

I wish you as family all the best and an unforgettable time with amazing and memorable moments!


Yeah the journal idea made me smile. Very thoughtful and constructive parenting.


Vaguely related, a few years ago I made a map of "how to drive from SF to NYC while passing through the minimum number of Republican-voting counties": https://github.com/louispotok/blue-road-trip


that route follows an ancient coastline - https://starkeycomics.com/2021/06/11/how-a-coastline-100-mil...


"How a coastline 100 million years ago influences modern election results in Alabama"

With some maps of Cretaceous sediments, fertile Black Belt Prairie soil, farm size 1997, slave population 1860, black population 2010, and Election Results.

A little bit about the soils from a different link:

"The Black Belt is the only region in Alabama with extensive regions of alkaline soils (soil pH> 7.0). Early settlers discovered these clayey soils held more nutrients and were generally more productive than the sandier Coastal Plain soils. For this reason, many of the large, antebellum cotton plantations were located in the Black Belt region of Alabama and Mississippi. Black Belt soil color is dark because of the humus, or decomposed organic matter, that often coats the clay particles. However, severe erosion due to intensive farming practices removed much of the dark, rich topsoil."

https://www.aces.edu/blog/topics/healthy-soils/alabama-soils...


That is really interesting, thanks for sharing!


I can't believe how even a topic about open maps API gets turned into politics. And then gets voted to the top. What was HN saying about Twitter's algorithm? Something about polarization, divisiveness, outrage, etc? It's not algorithms, it's you. You're making online discussion miserable for everybody.


I guess it's voted up because people found the comment interesting. It could have just been "I found a route following a given rule and wrote a blog on it, here's a link if you're interested" but your comment seems determined to turn it into a politics argument.

Meanwhile there is a more interesting subthread exploring an interesting historical and geological reason behind why some of the counties in question leaned Democratic you don’t seem too interested in. Strange…


"Avoid Republican-voting counties" was completely apolitical before I came in. This is an actual argument you thought makes sense. Ok...


The topic involves a political party, so no it's never going to be "completely apolitical". But that's not what I said - I said that you're the one who seemed keen to kick off an argument about politics. Also you complained about being miserable, if you don't seek out conflict you won't be so miserable.


I am an european who clicked on some topic about maps routing only to be greeted by the freaking US politics again. Specifically the side that makes everything political, argues that everything is and should be political, but then pretends that the political shit that comes out their keyboard is somehow not political until I point it out.

And I said by doing this you make online discussions miserable, not that I myself am miserable. If you aim to derail the argument with personal attacks in the form of keyboard psychoanalysis - reading comprehension is very much required.


"Specifically the side that makes everything political, argues that everything is and should be political, but then pretends that the political shit that comes out their keyboard is somehow not political until I point it out."

You might have gotten too much internet sun this week, throw some ointment on it and stay in the shade. You are the only person going political in this thread.


If seeing a pretty innocuous comment triggers this kind of response, then you might need to take a breather from the comments. Or click the `[-]` button to hide the reply if you don't want to. But engaging like this is about as productive as having an argument with a brick wall, it's not doing you any good.


I appreciate everybody's totally genuine concern about my mental health. May I suggest though that you do you and I do me? Take your own advice and follow it. I will continue to post what I think when I think. Over and out.


The whole point of this thread was that you wanted to change our behaviour to suit you. We were already following "you do you" and you didn't like it :-/


The comment that set you off did not comment on political ideologies, political actions, or political stories of the day. There's nothing in there about rightness, wrongness, justice, etc. No candidates were discussed, nobody was attacked, no divisiveness instigated. The commenter merely shared a project with obvious similarities to the posted subject derived from political voting patterns. The route is likely aligned to their values, but even that is an inference!

When everyone around you seemingly makes everything political, maybe it's sometimes the observer and not the observed?

> I appreciate everybody's totally genuine concern about my mental health.

It's probably more genuine than you think, however hard that is to believe.


For over a decade I ran a very famous /r/ with ~2,000,000 subscribers...

I made it a point to have the sub remain Apolitical - total disaster to the point where the corrupt reddit admins got involved and kicked me out of the sub (admins have tons of alt accounts they use to get mod status in /r/'s)

Its very hard to be apolitical at all these days because the constant barrage of damage control and distractions used to shield US lawmakers from corruption scrutiny. And it affects our lives on a daily basis.

Look at the news cycle today. Literally today ; talking about 'running out of money and raising the debt ceiling' - but zero acknowledgement of the ~250 BILLION dollars we have thus far sent to Ukraine for another proxy war. Fuck that.

We have fucking zombies slurping off the government tit (feinstein) and a crap ton of geriatric long time sitters with dementia and corrupt insider activities

https://i.imgur.com/fRlfeB2.png

https://i.imgur.com/aNoLw7X.png

https://i.imgur.com/JRxXvsF.png

https://i.imgur.com/88zALUY.png


>> Literally today ; talking about 'running out of money and raising the debt ceiling' - but zero acknowledgement of the ~250 BILLION dollars we have thus far sent to Ukraine

A lot of that money exists only on paper. Take a warehouse full of air defense missiles manufactured in 2000, with a cost of $3m per missile and a shelf life of 25 years. If you give 200 of them to Ukraine to defend its citizens from Russian terror attacks, then on paper that costs $600m. If you use "replacement value" as cost and new missiles cost $6m (because they're better), you can inflate their value to $1.2bn. If you do nothing and let them expire, they'll be worthless in 2 years and you'll just write that $600m or $1.2bn off. In either case, accounting reports lots of money spent, but no real money actually changes hands. That money was already spent decades ago and you aren't saving anything by withholding missiles. By giving air defense missiles to Ukraine instead of letting them sit in a warehouse until they become obsolete, you at least do something useful with them.


I need you to be hit with a $50,000,000 bunker bomb. Your logic is ready to bomb itself


May I humbly suggest coming back to the thread in a couple hours or tomorrow? There’s gotta be a language barrier thing here, you’re being extremely argumentative at length about a noun being used.

This last comment extends, at an uncomfortable level, the politics argument and name calling you started and you’re accusing others of, for no discernible reason.


I actually hesitated before posting for exactly this reason, and I don't think you're wrong to be sensitive to this. But you'll notice that there's actually no real political content in the link, nor was there any political discussion in the thread, so I think your response is a little bit of an overreaction.


The project itself is political


You don't get any roads without politics in the first place. Everything is "politics".

I don't see the issue with the comment, he didn't assign any judgement to the map. Which is where the politics problem usually arises.


What roads? It has nothing to do with roads - it's purely a map of contiguous democrat counties. Besides, that's moving the goalpast from "its not political" to "well yeah it is political but its ok". It's also a bad example precisely for the same reason you (presumably) think it's a good example people can relate to - everyone agrees we need roads.

Furthermore, clearly some things are too political to bring up in some places. This is not controversial. We can all agree we shouldn't let schools preach political propaganda to our children "because everything is political anyways." Or that churches shouldn't preach political propoganda "because everything is political anyways." This is one such case - it's a divisive partisan viewpoint that is only loosely related to the original topic and has nothing to do with hacker news. I assume the original poster meant no harm but it's still a negative contribution.


> it's purely a map of contiguous democrat counties

“Democratic counties”, right? I understand that it’s a common epithet used to deride an opposing party; but if one wishes to remain apolitical isn’t it better to apply the neutrality of using the party’s actual name and conventions of capitalization?


I don’t understand your “gotcha.” Its the Democrat party. Thats what the map is of.


> What roads?

The original post is about roads, those roads exist (or don't exist) due to political processes.

> Furthermore, clearly some things are too political to bring up in some places.

Can you please explain what is too political about that post? I don't really get what you take offense at? It's just the result of a vote?


Every single thing is political. What you eat? political Religious? political What TV show you watch? political What job you do? political. Welcome to modern America where every single thing is a political us vs them shit show. This is the county we as citizens have let be forced on us.

Simple fact most Red's don't want to associate with Blue's and it's the same on the other side. Sure individuals won't agree but they are a minority. If you don't like the project, then just move on it has NOTHING to do with you.


It's a negative contribution. Do you feel the same way about someone preaching political propoganda in a church, business, school, etc. that you aren't a member of simply because "every single thing is political?" And can't we agree that OP's post is not political? Or if it is, the degree is orders of magnitude less than the map of contiguous counties belonging to one party?

It seems to me that "everything is political" is just a way to provide cover for pushing partisan viewpoints places.


This is objectively useful: Now we can build an underground railroad for getting LGBT folks out of Florida and similar states.


It diminishes the horror of slavery to assert that LGBT people experience anything remotely comparable. There are no restrictions on travel for LGBT people (much less restrictions that vary by county based on one election cycle). No one is out there capturing LGBT people to return them to captivity. The majority of residents of every state have come to accept L, G, and B people, and at least 25% of residents of every state accept T people. There's no need for an underground railroad; our many above-ground (ie, not secret) transportation networks are more than capable of safely moving people who can afford to move.

Sure, some states are targeting Trans people with the worst offending state being Texas, whose recently indicated-and-stripped-of-power AG ken Paxton criminalized provision of gender affirming care to children as child abuse. But this map goes across the full length of the worst state for trans people, so I don't really see how that map helps LGBT people.


So edgy that you’re only posting it using a throwaway account. Stop trolling.


Is this edgy? I work in the gov and last week drafted a policy to inform and quickly relocate staff in such states based on their public-facing potential for harm. Quite a lot of our staff is in Florida right now, and legislation continues to roll through.. It's quite real to me. Also I just cycle through throwaway accounts because when I attached my comments to a username I began to self-censor how I speak. The lack of a username helps me think.


For what it's worth, I didn't think that was edgy. Sometimes it's a good idea to think about worse case scenarios


It's legit the focus of where I work :c (gestures broadly to everything)


To build an interstate underground tunnel for evacuating lgbt?

This feels like 1998 on IRC. I'm shaking my head and laughing at the same time.


I think you're taking "underground railroad" a little bit literally. The commenter seems to be claiming they work in politics and that their job has recently involved putting together some materials to work around some newly introduced (or proposed) spiteful laws targeting a specific group of the population.

I mean on the internet anyone can anonymously claim they're anything, but what this person in particular is claiming doesn't sound out of the realm of possibilities at all.


Indeed, I think the poster was referring to a metaphorical railroad. The term comes from https://en.wikipedia.org/wiki/Underground_Railroad


So your job is to create an undercover network to allow them to escape the clutches of evil republicans. I can certainly imagine that you don’t want to take responsibility for this drivel at work.


Traveling to other states for work is done at the gov expense (for our line of work). If there are extenuating circumstances to remove someone and bring them home quickly, we still have to abide by federal travel regulation to get them home. Otherwise they're stranded in another state trying to arrange airfare or a car + hotel(s) which can be very expensive on short notice:

https://www.gsa.gov/policy-regulations/regulations/federal-t...

My understanding is in Florida you can be arrested for dressing in opposition to the gender you were assigned at birth. If witnessed by a child this can be considered a sex crime, for which sex crimes involving children in Florida are eligible for the death penalty. Do I think this is likely to happen? Yes. The past 4-6 years have demonstrated we keep /hoping/ for de-escalation, but then examples are made that get national attention and evil things become normalized. Can and 'will happen' are subjective, but they did recently make it legal to seize trans kids.

https://www.reuters.com/world/us/desantis-signs-florida-ban-...

I'm part of an employee advocacy group. It is my role to be sensitive and address concerns some may consider isolated or minute. Things we never thought we'd have to discuss at work are now being discussed to keep (management), employees, and families aware of risks and safe.

What is your definition of evil?


If only the slaves that used the real Underground Railroad could have turned white as easily as crossdressing people can switch to clothing of the proscribed gender.

Try describing a concrete situation in which someone is accused under these laws you speak of, and then is able to escape by simply moving over the state border. Do you live in the world of the Dukes of Hazzard, where they can escape the Sheriff as long as they manage to cross the border? Do you think there are no extradition laws between the states?


You rediscovered the black belt. Also where cotton is produced: https://qph.fs.quoracdn.net/main-qimg-5dcb98887fb22c1d3a920a...


These are kind of people who inject fear mongering among the other people.


Did you traverse this?

Maybe return through maximally republican counties and compare?


Ha, no, just a fun exercise sparked by a conversation with a friend. It also doesn't take the road network into account, just county adjacencies.


Really informative post on how to do this "by hand"!

I use https://trips.furkot.com (which is free) for this kind of trip planning. It is fantastic to determine how much stuff you can fit in a day, taking into account when you want to start/end your day, driving time, stops for food, time spent at any road-side attractions, overnight stays, ticketed events (to ensure you arrive on time), etc. It's an incredible resource that seems to "fly under the radar".


Thanks for this. I've been using Roadtrippers, which is OK but full of intrusive ads even if you pay for the Pro subscription. Furkot looks much better.


I did something similar in Go for a big sailing trip this year. Just haven't had the time and energy to write a blog post about it.

https://j.avtolik.net/journey/2


Looks neat, is the code open to look at somewhere?


Sorry, this is part of my effort of learning Go and is also a WIP. So I am not yet comfortable sharing the code. I can share the libraries I used:

- go html/template for the front-end

- github.com/twpayne/go-gpx for parsing the gps tracks

- github.com/fogleman/gg for drawing the images

- github.com/dsoprea/go-exif/ for reading the exif of the photos, so I can show where are they taken on the route map


I found this repository to make storymaps with Google Sheets and Leaflet, that could be a nice addition: https://github.com/HandsOnDataViz/leaflet-storymaps-with-goo...


Why is there such a movement for making maps with R? The python ecosystem has more and better packages for making maps already. Notwithstanding that there are indeed some nice results, this new R toolchain movement towards maps feels like a waste of open source energy to me.


I feel like the R ecosystem was there first; but perhaps two completely separate groups of people.

Ecologists, researchers working with geological or geospatial data use R and have been using R for a long, long time. The 'old 'standard library 'maps' is decades old by now, with maps v3 now being 8 years old. maps v2 goes back to 2003, about the time of Python 2.3?

I can't even find the sources of maps v1. https://cran.r-project.org/src/contrib/Archive/maps/ I believe that maps v1 was for R's predecessor, S, so from the late 90s, about the time Python 1.5 came out. Was anybody even using Python then?

OP's post uses the slightly fancier tidyverse-versions of these decades-old libraries. I think it's safe to say that map-making libraries are older in R than in Python.


Can we, I don't know, let people enjoy programming languages they like without calling it a waste?


As someone proficient with R and Python, anything data viz-wise is substantially easier to do in R/ggplot2, particularly something complicated like this post.

Most of the R packages in this post aren't that new either.


My same experience, I have built fairly big projects with Python and I like it for general tasks but whenever I have something data analytics/visualization related I find myself reaching for R. There is so much functionality built into the language that just makes me so efficient.


I agree with that. I've been programming on and off in Python since 2008 and really like the language. I started using R just over a year ago after joining a new team. It took a while to adjust but I've gotten to prefer it for exploratory data analysis and data viz.


same here, I love me some ggplot.

Python for everything, but if I need to make something nice to look at, R makes my life so much easier, and the final touch in Affinity Designer/Photo.

In jupyter it's trivial to mix and match python and R anyway, all the wrangling in python and once it's clean, just basic tidyverse in R


You're welcome to demonstrate why python ecosystem would be better for this analysis, otherwise you're making unsubstantiated claims.


while I use Python far more than R (or Julia) I don't think that this is a particularly constructive comment.

"More and better" is simply subjective and not substantiated. In fact detailed and objective comparisons of capabilities, performance etc between these ecosystems are sorely lacking not just in map-making but practially concerning every comparison.

Still, the "waste of open source energy argument" is quite bit more complex and I'm frequently wondering about this.

For sure this "waste" happens everywhere in open source. About the only thing that approaches some optimal level of efficiency is the Linux kernel. From there on, distributions, desktops, toolchains, apps, libraries etc. is the epitomy of chaos.

This diversity creates resilience and a sort of competition for the survival of the fittest. The openness also facilitates fast diffusion and borrowing good ideas. But it is also true that open source resources are still scarce so development happens at maybe much lower speed than what would be possible if more coordination / less fragmentation was practiced.


The mapmaking R ecosystem absolutely has been around for ages, and from a cartographer's point of view it is better suited at making actual maps than Python.


As a non-cartographer, but someone who loves maps (who doesnt?) and programming is there anything in particular that makes R more suitable than Python? Not trying to start a Python/R flame war, genuinely curious as an outsider if there's some secret sauce that R has but which Python lacks.


IMO it mostly boils down to good practices in symbology, projection, legend, scaling, etc. being better implemented and easy-to-use for the map maker.

ggplot2 is an obvious heavy-weight, but other packages such as mapsf and tmap also are top notch in this regard.

on the other hand, my general map making experience in Python has not been very pleasant when I had to work towards creating a map following acceptable cartographic practices, ie. anything beyond throwing data on a webmap layer with subpar legend and symbology.


The secret sauce for R is that their statistical models/packages are cutting-edge, they have the best plotting library (ggplot2), and they have the best data wrangling packages (dplyr for tabular data).


very much this. I've spent years dabbling with other languages, nothing as ever been as clean as the tidyverse for data analysis


Interesting, I’ve used both for years and have found R to be way more intuitive for data exploration and visualization. R looks different than most programming languages, but once it clicks it’s actually really nice.


ggplot is the best! R has some fantastic packages especially for visualizations. And the community is great :)


There are a lot of R users and it's a nice language you should try it sometimes.


As an R user for nearly 15 years at this point: R isn't nice, it's an awful language, but it is very useful.


The tidyverse has made it pretty “nice”.


Why build react, angular and all, when jQuery was just fine, why is there such a moment in Js to always build the next framework, seems like a waste of open source energy.

....something....something...requirement.. different approach...


The only thing I don't like about OSRM (the public facing version, not sure if the Docker one has this limitation) is that the route planning is limited in the number of waypoints.

I'm planning a trip to the west coast and have 50 POIs (coordinates) collected from Wanderlog that I want to visit. I just run a small TSP algorithm over that list and have an ordered collection of points for which I want to calculate the route for.

Unfortunately it seems like OSRM doesn't like my 50+ waypoints, thus I can't really plot the trip.

I'll probably give it another try locally, and then make a PR. It also looks like the only way to get a route across waypoints is to make a GET request, so just imagine how long the request path will be with 50 points :'( That calls out for a new POST endpoint.


That’s the public instance. It’s a runtime flag to osrm-routed so if you set up your own instance, you can configure it how you like. (Or use the Node or upcoming Python bindings.)


Still, most likely passing 50+ waypoints in the URI might cause other issues


I can't speak for the most recent version, but I regularly pass 200+ waypoints to a fork of OSRM 4.9 and it works fine. If you were to use the Node/Python bindings and hence avoid any webserver limitations you should be ok.


Awesome, thanks!


I hope when you talk about "days", those are just travel days. Be sure to stop a while somewhere nice and explore if you have time.

As Rick Steves says, if you can't justify staying somewhere for at least one night, it might be a good idea just to keep moving!


Sometimes I hold events, and I want to put a little map on the flyer. It's a real pain to manually deal with some SVG of a larger map area, and clip it and style it to fit the space. Does anyone know of any solutions like this for this kind of problem?


A couple of years ago I rendered some maps in QGIS using OpenStreetMap data.

It was a complicated beast of functionality but if you learn the right 2 % of buttons it becomes a very competent tool for creating exactly the maps you need. It gives you the tools to show exactly the terrain features you care about (rivers, roads, streets, highways, trails, forests, buildings, railways, etc.) and you can choose to style them however you want.


Total agreement on QGIS: seems daunting at first, but if you know exactly what you want you can usually get there in half an hour.

I have been using this a lot for scout activities and keep grandma-style notes of which buttons to push for a particular use-case. So awesome to be able to do things like contour-only maps and atlas along a route.

For any Danes around: There is an official plugin from "Kortforsyningen" for QGIS, allowing you to pull all the high-quality public data directly into your maps.


Could datawrapper be useful to you? It is easily configurable and the maps look great, I think.

https://www.datawrapper.de/maps


Mapbox Studio should be able to do this


Related: The "Here Dragons Abound" blog [1] deals with pleasant layout of generated maps.

[1] https://heredragonsabound.blogspot.com


To the author: great write up and cool project

Would have loved to see the end result at the top of the article instead of having to scroll all the way down to the bottom for it

Thank you


This reminds me of a Bing (MSN?) maps plug-in a while ago that was built by, I think, an Indian guy who went over to MS, which would plot a summarized route map from point A to point B where the main roads in your route were labeled, esp where you had to turn or get on a diff road. This was before phones with GPS came about.

The roads looked somehwat like chicken scratch (straight, not many curves). Like if you were mapping directions in sand/dirt with a stick in explaining to someone how to get some place.

Ah, yes, it was Linedrive: https://somethingaboutmaps.wordpress.com/2011/03/08/remember...


Some of my friends & family use Polarsteps.com to share their routes (and photos), whose UI is comparatively slick. I'm afraid of the lock-in, though, and would be much more interested in an open-source solution. Does anyone happen to know any?


I’m driving SF to NY next week so will definitely spend some time trying this out to share with family!


We did a several thousand mile road trip a couple years ago. We planned it out using various online tools and pen and paper. Will have to look into doing something like this the next time.

The kiddos got to see a LOT of really cool things. They had a blast.


Fantastic post!

But keeping this "limited iPads/electronics" policy for the kids: is the idea to print out these maps and put them into a journal for them to annotate on?


Awesome thanks for sharing. I've worked with OSM data extensively but didn't know about the routing possibilities shown here. Will have to try soon!


Cool! Curious — has anyone done something similar in Python?


Thank you! Love R.


Cool, like a DIY AAA TripTik (anyone else used to pick those up for trips?)


Thank you for sharing this was really nice and interesting.


A little underwhelming for so much work, but I guess if you already have R installed, then it's just plug and play.

Thanks for sharing.


Very Nice! I will try it




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: