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

I'm trying to figure out how to generate nice maps on the fly. The specific problem I have is that I need to have a map of a state, display the localities within it, and color each locality. Eventually I'm going to need to have maps of the localities, break them down by either zip code or our own pre-defined districts and color code them.

The problem is that I don't really have a clue how to generate any map. Where do I get the geography of the area? How to I convert that to an image? Once I figure that out, I would assume it would be easy to implement the color coding.

Thanks

Replies are listed 'Best First'.
Re: Geographical Map
by tall_man (Parson) on Nov 10, 2004 at 19:43 UTC
    To get really advanced, you may find you need a real geographic information system like ArcView. However, you might try some simple things to get started. Many common geographical shapes (such as state and county boundaries) are publicly available as shapefiles. The module Geo::ShapeFile will enable you to read them and extract the polygon information, which you could plot with Perl/Tk, for example.
      The new release ArcGIS 9 now supports scripting as well - finally.
      This looks like it might be helpful. Thanks!
Re: Geographical Map
by fglock (Vicar) on Nov 10, 2004 at 19:49 UTC

    Take a look at MapScript

    The MapServer system includes MapScript which allows popular scripting languages such as PHP, Perl, Python, and soon even Java to access the MapServer C API.

      This looks really cool. Thanks!
Re: Geographical Map
by howie (Sexton) on Nov 10, 2004 at 23:23 UTC
    If you will always be colouring in the same map predefined areas (like counties, or electoral disctricts, for a topical one) rather than arbirary ones, then you might want to consider something simple to deal with like SVG. You prepare the map in a graphics package like Illustrator, save it as SVG. SVG is a XML-based format, so it's text.

    If you spend a little time upfront giving the county-outlines a meaniful name or ID ('TX', 'CA') then your colouring-in phase becomes a simple search/replace on a text file, which perl has Several Ways to do.

    I believe PDF can be dealt with similarly. If you need a PNG or something eventualy, for a web app, then there are tools around to render SVG to a bitmap format.

    Several graphics packages come with pretty decent maps in their clipart, too. CorelDRAW! certainly used to have good outline maps packaged with it.

Re: Geographical Map
by dragonchild (Archbishop) on Nov 10, 2004 at 19:50 UTC
    A few further things to think about:
    • How are you defining localities? What happens if, like where I live, there are two 'Marysville's in Ohio, each in a different county?
    • What's wrong with pointing people at MapQuest or YahooMaps?
    • What's wrong with going to your state government site and using what they've got? This sounds like something voting software would have a solution for ...

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Responces to the bullet points in order:
      • Right now we're defining localities as counties and cities. Two Marysville hopefully would have different zip codes or some other way to tell them apart.

      • We're not really looking for street maps. We want to display membership changes of our local groups. On the local level we want to be able to display membership by zip. I hope this application will have other uses beyond this.

      • I haven't come across voting software that seems useful yet. We wouldn't mind using the voting precint as the basic unit. Even if there was something, I'd rather 'roll my own' since this seems like an interesting project to me.
        A word of caution - ZIP codes are not meant for mapping - they are meant for delivering mail. You're better off geocoding with FIPS codes. You can check out Census Bureau mapping resources at http://www.census.gov/geo/www
Re: Geographical Map
by diotalevi (Canon) on Nov 10, 2004 at 21:17 UTC
    I've used TIGER/Line data and GD to plot ward boundaries. Right now the hosting server is down so I can't link to it but the general idea is easy - you just get a bunch of lat/long lines and you plot it out on a graph. Its pretty easy. What are you doing this for? Care to share any code or ideas?
Re: Geographical Map
by hackdaddy (Hermit) on Nov 11, 2004 at 11:36 UTC
      SVG is certainly a fantastic standard for dynamic map display. However, it suffers from very poor browser support. Also, it is a very little used standard so you may have difficulty finding experts that have knowledge of using it. If you want a shape file to svg converter there is one written in Perl at http://www.carto.net/papers/svg/utils/shp2svg/. A solution that I am developing at the moment for a similar problem is to color shockwave flash maps at runtime. Flash is difficult to use for cartography, but the results are fast loading and have much better browser compatibility. Do you have any examples of the data you wish to map?
Re: Geographical Map
by theorbtwo (Prior) on Nov 13, 2004 at 00:10 UTC

    A lot of people have weighed in on how to display the data, but the question of what data you're mapping is pretty open. It sounds like you need to find some high-quality description of the localities in question. Mostly, this information seems to be, in the US, mostly not orginized past a fairly local level. If you want information on counties of a state, try searching for Pennsylvania GIS, for example. If you want information on districts within a county, try Lancaster Pennsylvania GIS.


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).