Bug Mapping

(the insect kind, not the computer kind)

I’ve always been interested in maps and I’ve had at least a couple on my walls since I was a kid. That interest has carried over to the computer world, as you can see by the many GPS track maps I publish with my trip reports.

I’ve been a regular participant on the BugGuide.Net website for the past year or so, and I always thought it would be cool to plot a map of the locations where people have photographed their bugs. I offered to give it a try, and Troy Bartlett, the site owner, graciously provided me with the location data to play with.

The first hurdle was the free form location data. A photographer could put any location they wanted in that field, and the contents varied significantly. Some would give full state names, others would use abbreviations. Add in several misspellings, some non-U.S./Canada locations and it was hard to work with. (Troy has since modified the website to require users to select from a pre-defined state/province list).

I ended up writing a PHP function to try to take a location name and pull the state or province out of it. I basically assigned each state/province an array of possible matches. So West Virginia, for example, was comprised of WV, W. Va., W. Virginia and West Virginia. This worked fairly well. Then it was a matter of arranging the location comparisons so that you get the right state, i.e. you have to check for West Virginia before Virginia because they share names. Through testing I found you also have to put Delaware and Louisiana toward the end of the checks because “de” and “la” appear in some Spanish-based place names. For similar reasons, you need to check Indiana and Ontario toward the end. I found later that it’s also a good idea to put Colorado down there since “Co.” is an abbreviation for “county.” (Click here to see the code).

Once I had the locations simplified, I needed a way to plot them on a map. I tossed around various ideas but settled on a good open-source mapping package called MapServer, which I had played around with over the years but never created any applications. I had some publicly available map data “shapefiles” to use, and all I had to do was feed my list of states and provinces to the map template. MapServer did the rest, generating North American maps with the relevant areas colored in. MapServer has lots of features for browsing maps interactively on websites, but for the time I just wanted to create static maps.

After lots of testing, I decided it was ready to use. I packaged it up and sent it to Troy, who quickly integrated it into BugGuide as the “Data” page. He adjusted the color scheme and added a neat breakdown of locations by month. While the maps generated aren’t comprehensive range-maps, they do show what’s been captured by the website’s users, and perhaps with time will approach the true ranges of many species.

It’s a fun way to use maps on the Internet. Here are a couple examples:

  • Arthropods — this map shows all the states and provinces they have photos from so far
  • Asian Lady Beetle — a species page with several states already highlighted

And you can browse the maps anywhere between the phylum and the species…check it out!