Hack 15. Zoom Right In on Your Neighborhood

And thereby give new meaning to the term "ICBM coordinates."

I like pretty pictures that move. Sadly, most maps are stable and don't move. Biologists have a special word for systems that are stable and no longer move, and that word is "dead." Let's get the defibrillation paddles out and put some life into our maps. [Hack #1] describes how to find a location using MapQuest, and it will get you a map. But where is the place described by that map? My daughter wanted to know where New Orleans is. She went to MapQuest and searched. And MapQuest presented exactly what she asked for. Try it! The city appears on the banks of Lake Ponchartrain. But where the heck is that? Molly zoomed out, and out, and out, until Texas appeared. "Ah, I see now where it is."

To save her from the effort of ever again clicking "zoom out" three times in rapid succession, I wrote a little script called boomzoom.cgi. I called it this, because the first person who saw it said that it looked like the earth as viewed from a rapidly approaching ICBM. Now, as it turns out, my friend wasn't all that far off: Cartographers actually have a term for this kind of instant zoom-in orientation, which they call ballistic navigation. But somehow "boomzoom" was the name that stuck for me.

You can run it at http://www.mappinghacks.com/cgi-bin/boomzoom.cgi. Enter the latitude, longitude, and text to mark your center point, and then select "Make zoomy thing," as shown in Figure 2-6.

Figure 2-6. Boomzoom's initial screen

The Boomzoom program proceeds to fetch about 10 images from the TIGER Map Server [Hack #14] , and then stitches them together to make an animated GIF. Each image is shown for just long enough to give an idea of what it is showing, before giving way to the next. Figure 2-7 shows the first image of a "boomzoom" on the O'Reilly campus in Sebastopol, CA.

Figure 2-7. Can you find O'Reilly?


2.3.1. The Code

You can run the same basic code on your desktop, as well. Since the TIGER data allows us to grab map images directly, we can automate the process with this bit of Perl, which we'll just call zoom.pl:

use LWP::Simple;
my $lat = 38.4034; # center on this latitude
my $long = -122.8185; # center on this longitude.
my $mlat = 0; # put a marker on this latitude
my $mlong = 0; # put a marker on this longitude.
my $mlabel = 'your_label'; # label for your marker. No whitespace!
my $wid = 20; # starting width in degrees
my $minwid = .001; # ending width in degrees
my $cnt = 0;
while ($wid >= $minwid) {
 $wid = $wid * .3;
 my $url = "http://tiger.census.gov/cgi-bin/mapper/map.gif?lat=$lat&
 $cnt = sprintf("%03.0f", $cnt);
 open OUT, ">zoom_$cnt.gif";
 print OUT get $url;
 close OUT;

Obviously, most of the hard work in this script is done by the enormous URL that we send to the TIGER Map Service to generate the link. For more information on how to tweak this URL to your satisfaction, check out [Hack #14] .

2.3.2. Running the Code

Enter your own U.S. location in place of the latitude and longitude lines, place the script in an empty directory, and run it with perl zoom.pl. The script fetches a series of maps centered on that location, narrowing the scale of the map by 10% each time. The maps will be stored as numbered image files, with the names file_000.gif through file_008.gif or so.

Next, we'll animate this collection of GIF images using the convert tool from ImageMagick. ImageMagick is available for Unix/Linux, Windows, and Mac OS X platforms. Unix/Linux binaries are available via your favorite package manager, or from http://www.imagemagick.org/.

Once you've got ImageMagick loaded, creating your animated ballistic navigation is a cinch:

convert -adjoin -delay 10 zoom_*.gif oreilly.gif

The delay is measured in hundredths of a second, so this creates an animation of 10 frames per second.

2.3.3. More Ballistic Tomfoolery

This hack uses standard animated GIFs, so there's nothing stopping you from interposing your own images, as you preserve the zoom_###.gif naming convention. You could, for example, replace the last image with a picture of your house or even a series of ever-closer views of the blueprints to your home. Another hack would be to change the center (lat, long) of the image request so that you could have an animated pan effect. You could even use Perl's Image::Magick module to automate the whole process. The possibilities, while not literally endless, are legion.

2.3.4. Install Boomzoom on Your Own Site (Please!)

Consider that the Boomzoom script on http://mappinghacks.com/ has to fetch around 10 images from the TIGER Map Service and then generate a fairly large animated GIF. This makes it a bit greedy for bandwidth! Fortunately, you can install it on your own system! If you have a web server that supports CGIs, you can probably install boomzoom.cgi on your own site. You can download the code from http://mappinghacks.com/code/. You will also need to install ImageMagick (http://www.imagemagick.org/) and the Image::Magick Perl module from the CPAN.

Under OS X, you can enable a local copy of the Apache web server by going to System PreferencesSharing and turning on "Personal Web Sharing." Copy the boomzoom.cgi source code to the folder /Library/WebServer/CGI-Executables.

Mapping Your Life

Mapping Your Neighborhood

Mapping Your World

Mapping (on) the Web

Mapping with Gadgets

Mapping on Your Desktop

Names and Places

Building the Geospatial Web

Mapping with Other People

Mapping Hacks
Mapping Hacks: Tips & Tools for Electronic Cartography
ISBN: 0596007035
EAN: 2147483647
Year: 2004
Pages: 172

Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net