
150
|
Chapter 3, Mapping Your World
#31 Plot Dymaxion Maps in Perl
HACK
$map->write( file => "world_cities.png" )
or die $map->errstr;
The script starts by opening a text file called cities.txt and then discards the
header line. Next, it reads the next 50 lines, one by one, splitting each line
up into tab-separated fields, extracting the latitude and longitude from the
second-to-last and last fields on each line, respectively. One important thing
to note is that
Geo::Dymaxion expects latitudes south of the equator and lon-
gitudes west of the prime meridian to be expressed with negative values; this
is taken care of by the two regular expression matches in the main loop. The
latitude and longitude are fed to
Geo::Dymaxion, and the x- and y-coordi-
nates are used to draw a three-pixel-wide red dot on the map in the appro-
priate location. Finally, the updated map is written to a PNG image called
world_cities.png.
Running the Code
In order to run this code, we’ll first need a list of cities. We’ve compiled just
such a list for you, using data from world-gazetteer.com, which you can fetch
from http://mappinghacks.com/data/cities.txt. The file is tab-separated and
contains a bunch of other information, about which we won’t go into detail
here, but that you might find useful for other mapping projects. Next, we’ll
need a Dymaxion map of the world. Dymaxion maps are astonishingly hard
to find on the Internet, ...