http://qs321.pair.com?node_id=178641

Stegalex has asked for the wisdom of the Perl Monks concerning the following question:

I would like to plot the zip codes from my orders database against a U.S. State map as a means of graphically depicting where our customers are (for management).

How would you tackle this problem?

Please refrain from commenting on whether this is a dumb thing to do as the point is moot - it's a requirement from on-high. Thanks in advance!

~~~~~~~~~~~~~~~
I like chicken.

Replies are listed 'Best First'.
Re: Plot zip codes on US Map
by dws (Chancellor) on Jul 01, 2002 at 19:15 UTC
    I would like to plot the zip codes from my orders database against a U.S. State map as a means of graphically depicting where our customers are (for management).

    This problem breaks nicely into a couple of pieces:

    1. You'll need a mapping of zip codes to geographics coordinates.
    2. You'll need a graphic image of a map.
    3. You'll need a way to translate/scale geographic coordinates to map image coordinates.
    4. You'll need a way to composite images.

    You can find (1) by doing a bit of google searching. Finding (2) is a matter of looking around until you find a map image that you like. The only complication with (3) is dealing with Alaska and Hawaii if they appear as sidebars on the map, instead of in their "true" locations. (4) is easily handled by GD.

Re: Plot zip codes on US Map
by DamnDirtyApe (Curate) on Jul 01, 2002 at 19:15 UTC
(jeffa) Re: Plot zip codes on US Map
by jeffa (Bishop) on Jul 01, 2002 at 19:16 UTC
    WWW::MapBlast sounds like a good starting point. This module will give you the latitude and longitude of a given zip code. Next step would be to use a module like GD to apply the zip codes. I would try some kind of World to Viewport algorithm to do so. It has been a long time since i did any graphics programming, last time was in Java. You can find my explanation on World to Viewport here (which is paraphrased from the book Computer Graphics).

    Remember also that jcwren has already done this something very similar at the Big Monk Map.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Plot zip codes on US Map
by maverick (Curate) on Jul 01, 2002 at 19:16 UTC
Re: Plot zip codes on US Map
by cacharbe (Curate) on Jul 01, 2002 at 19:21 UTC
    Personally, I would get a list of Zip / Long-Lat pairs and use the coordinates as a starting source to plot them on a map, and then maybe talk with jcwren about how he created the Big Monk Map functionality on his website.

    And if you want to find the distances between them, check here to see the differences in some of the algorithms.

    C-.

    ---
    Flex the Geek

Re: Plot zip codes on US Map
by greenFox (Vicar) on Jul 02, 2002 at 02:53 UTC

    Its been a while and I don't have the code at hand but I have done something similar using a Perl Tk canvas object. By using Northings & Eastings instead of Lat/Long I was able to plot as x-y points. I had data available in Northing Easting format and if I recall correctly it was all within the one zone.

    Geography::CoCo man page (not on CPAN that I could see) will convert Lat/Lon to Northing/Easting (or grid) format.

    --
    my $chainsaw = 'Perl';