May 31, 2005, 2:25 AM ET
Drawing arbitrary GIS data on Google Maps
I just added ZIP-code browsing to chicagocrime.org. A novel thing about it, from a technical standpoint, is that the ZIP code maps (example) display a blue border around the relevant area, so you can tell where the ZIP code begins and ends.
I did this using free GIS data from the City of Chicago. That data defines each ZIP code in the city and its spatial boundaries.
The data comes in standard SHP (shapefile) format, which I imported into PostgreSQL using its excellent PostGIS spatial-database package. PostGIS handles the conversion of the shapefile data to longitude and latitude points in the projection that Google Maps uses.
Next, I fed that list of coordinates through a Python script that encodes latitude/longitude points into Google's proprietary line-generation format. That script is a port of Neil Kandalgaonkar's Perl version. Neil appears to be the guy who reverse-engineered the line-generation format -- an incredibly impressive feat.
With Google's line-generation format calculated, it was just a matter of inserting that chunk of characters in the appropriate place within the Google Maps XML file.
Interesting tidbit: I played with importing the City of Chicago's neighborhood-boundary data, too, but the neighborhood boundaries -- particularly those that touch Lake Michigan -- are made up of so many distinct longitude/latitude points that displaying them on a Google Map crashes the browser when viewed at a close zoom level. The lines generated in that case are simply too complex!

Post a comment:
Comments on this entry are closed.
Don't see any comments? That's because my Web hosting provider has made a server upgrade that broke the commenting feature on this site. I'm working to restore that; please check back later.