Another stupid Graphviz trick - geographic graphs

For fun, I experimented with positioning nodes based on geography (latitude & longitude). GPS systems are ubiquitous so finding coordinates of cities was pretty easy. Converting latitude & longitude into X-Y coordinates was more work, but I found the proj program and it will apply any of ~140 map projections. Unfortunately, I know almost nothing about mapping, but I muddled through. I piped latitude, longitude and city name into this command:
proj -r +proj=laea +lon_0=125w +lat_0=30n -m 1:5000
then into a small awk program to turn that into a dot input file, then into this:
neato -n2 -Tpng >cities.png

The dot looks like this (boring):
graph geo {
node [shape=point color=red label=""]
city1 [pos=“691.37,403.50” xlabel=“Cleveland”]
city2 [pos=“515.79,276.31” xlabel=“Kansas City”]
…
The output:

All in all, it works and is pretty script-able, but I expect that there are better ways to position nodes geographically. Though I haven’t used them for something like this, R and Qgis come to mind.

1 Like

Interesting idea. Will you overlay on map tiles?

BTW, is this a rotated plot? It jumps out that Detroit was plotted lower than Philly. And the west coast was low too. Then found that rotating the tablet computer seemed to bring things into alignment

Anyone interested in map projections, there is a nice demo here: Projection Transitions / D3 / Observable (observablehq.com)

2 Likes

This work was just done for fun, to see how easy (or hard) it would be. I’ve done nothing with it since.
I did not explicitly rotate the map. I assume any location oddities are a function of the projection algorithm I used (Lambert Azimuthal Equal Area) and the parameters I chose ( +lon_0=125w +lat_0=30n).

I tried something like this ~27 years ago (before Graphviz, Google, Web, …) It was harder.