# Another stupid Graphviz trick - geographic graphs

**URL:** <https://forum.graphviz.org/t/another-stupid-graphviz-trick-geographic-graphs/256>\
**Category:** Show and Tell\
**Created:** [July 15, 2020, 11:33pm UTC](https://forum.graphviz.org/t/another-stupid-graphviz-trick-geographic-graphs/256 "2020-07-15T23:33:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [July 15, 2020, 11:33pm UTC](https://forum.graphviz.org/t/another-stupid-graphviz-trick-geographic-graphs/256/1 "2020-07-15T23:33:33Z")

</div>

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:

 ![cities](https://global.discourse-cdn.com/graphviz/original/1X/cedab4bbf29506c749ca3f590bb48ad81bac8588.png)

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.

---

<div class="post-metadata">

**Author:** ![BAMaustin](https://avatars.discourse-cdn.com/v4/letter/b/cab0a1/32.png) [@BAMaustin](https://forum.graphviz.org/u/BAMaustin)\
**Post date:** [May 28, 2021, 11:33am UTC](https://forum.graphviz.org/t/another-stupid-graphviz-trick-geographic-graphs/256/2 "2021-05-28T11:33:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![schmoo2k](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/schmoo2k/32/29_2.png) [@schmoo2k](https://forum.graphviz.org/u/schmoo2k)\
**Post date:** [May 28, 2021, 1:31pm UTC](https://forum.graphviz.org/t/another-stupid-graphviz-trick-geographic-graphs/256/3 "2021-05-28T13:31:48Z")

</div>

Anyone interested in map projections, there is a nice demo here: [Projection Transitions / D3 / Observable (observablehq.com)](https://observablehq.com/@d3/projection-transitions)

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [May 28, 2021, 2:34pm UTC](https://forum.graphviz.org/t/another-stupid-graphviz-trick-geographic-graphs/256/4 "2021-05-28T14:34:38Z")

</div>

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.
