Skip to Content
Mapping Hacks
book

Mapping Hacks

by Schuyler Erle, Rich Gibson, Jo Walsh
June 2005
Intermediate to advanced
568 pages
24h 7m
English
O'Reilly Media, Inc.
Content preview from Mapping Hacks
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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

The Three Traps That Stymie Reinvention

The Three Traps That Stymie Reinvention

Ryan Raffaelli
Computing for Numerical Methods Using Visual C++

Computing for Numerical Methods Using Visual C++

Shaharuddin Salleh, Albert Y. Zomaya, Sakhinah A. Bakar

Publisher Resources

ISBN: 0596007035Purchase LinkErrata PageOther