Since Google released its Maps API last year, the mapping mashup has emerged as the new trend in online media. Journalists, amateurs and Web developers have all hopped on board. And, for better  or  for  worse,  many  of  them  have spent  countless  hours  reinventing  the wheel.

Plotting shapes: Census tracts. School districts. Bike routes. If you’ve ever done it  by  hand  in  Google  Maps,  you  know how long it takes. As any geographic information  system  (GIS)  program  user can tell you, most of this information is already available in the form of shape-files, the spatial data source of choice in programs such as ESRI’s ArcView. The trick  is  transferring  the  data  from  one form to another – a task that has, until recently, been obnoxiously difficult.

Enter Shp2XML. Developed by Proximity,  the  easy-to-use  Windows  interface converts shapefiles into Google Maps-ready XML in about three clicks of the
mouse. Using Shp2XML, it took me 10 minutes  to  post  a  shapefile  of  Boone County, Mo., Census tracts online – Javascript  and  all  –  and  that was  just scratching the surface.

You  can  download  the  program  at  no cost at www.proximityone.com/shp2xml.htm.

The beauty of Shp2XML is that it doesn’t require  much  know-how  beyond  the Maps API itself. Of course, there are alternatives, but most of them are confusing  or  require  some  programming  expertise.  One  in  particular  –  a  program called  Shp2text  –  essentially  does  the same  thing  from  the  command  line, without a user-friendly interface.

Converting  a  file  in  Shp2XML  is  very straightforward. Open the program, then open a shapefile or U.S. Census Bureau TIGER map. Name your output file, select coloring and name/id field options, then click the Shp2Xml convert button. Presto.

The resulting XML file is nested  into  shapes  and  markers.  The shapes,  as  you  might  imagine,  are your polygon boundaries, in this case Census  tracts.  The  markers  are  the points that form those boundaries. Interpreted  by  the  Google  Maps  API, they form lines. Your color, id and name attributes will also be present and can be passed into Javascript variables for use in your application.

Optionally, you can limit the shapes or lines selected into the exported XML by using the Criteria/Query Statement box. Similar to an ArcView SQL query, this  allows  you  to  exclude  features based  on  criteria  in  their  underlying tables. If you only want to see Census tracts with more than 5,000 residents, for example, this is where you do it.

An  apparent  shortcoming  is  that Shp2XML can only export two fields of attribute  information  for  each  shape. That means it will code two pieces of
information  into  XML  as  shape  attributes – say tract name and population – but not more than that.

Adding further attributes – population, demographics, etc. – takes a little massaging,  either  by  hand  or  using  your utility of choice. Options include modifying the XML via a scripting language and  pulling  data  from  an  underlying mySQL  table.  It’s  not  difficult,  just  a hassle.

Something  else  to  keep  in  mind: Google  projects  its  maps  using  the Mercator projection, and, it is conventionally accepted, the WGS84 datum. Reprojecting your maps to these specifications  using  your  GIS  before  you turn  them  into  XML  is  strongly  advised.

Once you have a valid XML file, your biggest  challenge  will  be  translating your result into language the API can understand. That means dusting off a little  Javascript  and  delving  into  the API  documentation,  at  www.google.com/apis/maps.

If you don’t already have an API key, sign up for one. You’ll need it to use the service.  The  code  used  to  plot  your newly created polylines is beyond the scope of this article, but you can see a sample  at  www.nicar.org/downloads/shp2xml.html.

In  short,  my  Javascript  draws  in  the XML file and parses it using nested for loops – one for the shape tags and the other  for  the  enclosed  marker  tags. Google has done an excellent job abstracting  some  of  the  cumbersome XML  handling  into  API-specific  functions,  and  drawing  the  lines  themselves falls to only one line of code.

It  is  also  worth  keeping  in  mind  that Google  Maps  has  limits.  As  they  do when  you  plot  thousands  of points,  browsers  choke  on maps  awash  in  polylines. Census  tracts,  school  districts, municipal boundaries – things like that work fine. Map block groups at your own peril. Usually, the cutoff is several thousand  lines.  Larger  numbers are possible but require complex workarounds.

Accuracy  is  also  an  issue. With the proliferation of online mapping  services,  it  is  easy to forget how hard it is to find an accurate map. With Google
Maps  in  particular,  the  API community  has  been  abuzz with  talk  that  Google’s  maps do not match up well with other maps, often plotting points several hundred feet  away  from  accurate  baseline data.

As  a  rule,  I  would  rely  on  Google Maps  only  for  basic  approximations, and  I  would  only  use  them  in  situations where precision is expendable. None of these issues fault Shp2XML. The program itself is solid, if not a little  limited. The  founder  of  Proximity, Warren Glimpse, is a Ph.D. econometrician and the former Census Bureau official  who  developed  the  prototype to what are now Census TIGER files.

Based  on  his  experience,  he  knows what he’s doing. Proximity offers several other pieces  of  software,  including a geocoding application and a shapefile viewer/manipulator.Bottom line: Shp2XML is useful.  It  allows  Google  Maps hackers access to the expan-sive  stores  of  available  GIS data and quickly convert it into a useful format.

Contact Chase Davis by email at chase.davis@gmail.com.