Map of ISIS Zoo Animals

I had an acute desire to see a wolverine, but couldn't find an easy way online to locate the nearest in captivity. Twelve hours later, I had created a map of mammals in zoos, which might be useful for people looking for samples. Or wolverines.

The map can be found here. The information was scraped from the website of the International Species Information System (ISIS), an organization of animal management professionals. Technical notes can be found below.

Wolverines

In case you're curious, the ISIS wolverines nearest to New York City can be found at the NY State Zoo at Thompson Park in Watertown, NY:

Technical Notes

I downloaded the webpages from the ISIS website using a custom Perl script and the Unix utility wget. I scraped the info from the webpages using the Perl module HTML::Parser. This guide was super helpful in created modules like this one to grab the link data:

use strict;

require HTML::Parser;
package GrabLinks;

use vars qw(@ISA);
@ISA = qw(HTML::Parser);
sub start {
	my ($self,$tag,$attr,$attrseq,$orig) = @_;

	if ($tag eq 'a') {
		if ($self->{cur_url} == $attr->{href}) {
			$self->{got_href}++;
		}
	}
}

sub end {
	my ($self,$tag) = @_;
	if ($tag eq 'a' && $self->{got_href}) {
		$self->{got_href}--;
	}
}

sub text {
	my ($self,$text ) = @_;

	if ($self->{got_href}) {
		$self->{URLS}{$self->{cur_url}} .= $text; 
	}
}

For each species at each zoo, I grabbed the number of males, number of females, number of unknown sexes, and number of births in past year. I also grabbed the zoo's address. Since I wanted to map the institutions, I needed to turn the addresses into latitude/longitude coordinates. I did so using Google's geocoding service. You pass the service an address and it returns a JSON file. The URL for the NY State Zoo, for example, is:

http://maps.googleapis.com/maps/api/geocode/json
   ?address=One+Thompson+Park+Watertown+NY+13601+USA&sensor=false

which returns a JSON file that contains the following (some parts removed):

"formatted_address" : "1 Thompson Park, Watertown, NY 13601, USA",
"geometry" : {
    "location" : {
        "lat" : 43.96397980,
        "lng" : -75.8966490
    },
}

I used the JSON Perl package to grab the latitude and longitude for each zoo. Then for each genus I write a KML file with entires for each zoo. The placemark entries look like this:

<Placemark>
	<name>NY State Zoo at Thompson Park</name>
	<description>
		<![CDATA[
			<p><b>
			 One Thompson Park Watertown NY 13601 USA
			</b></p>
			<hr><br>
			<p><em><b>Gulo gulo</b></em><br>
			1 Male(s) 
			1 Female(s)<br>
			0 Unknown(s)<br>
			0 Birth(s) in last 12 mos.<br></p>
			<hr><br>
		]]>
	</description>
	<Point>
		<coordinates>-75.896649,43.9639798</coordinates>
	</Point>
</Placemark>

Finally, now that I have one KML file for each genus, the Perl script is finished. On to PHP to display the Google map with the placemarks. In general, this follows Google's example, with the following modification. The genus to be displayed is passed via POST from a form that contains a drop down box. The KML file of placemarks is added to the map with the following:

var ctaLayer = new google.maps.KmlLayer('kml/.kml',
	{preserveViewport: true});
ctaLayer.setMap(map);