Heat Map of Transit in San Diego
As my girlfriend and I start looking at new apartments around San Diego, the concern of public transportation quickly crops up. While public transportation here is better than other cities I’ve lived in, there are still dead spots and underserved areas. Certain areas (such as Mira Mesa) have surprised me with the speed you can get downtown – even faster than areas on Interstate 8. What I wanted was a “heat map”, or a color coded map that showed average public transit times to a location downtown. Plus, could this be used by others to pick housing closer to public transit?
Lucky for me, I’m not the first to try and tackle this problem. A guy named Neil spent some time mapping out transit times in San Francisco around the Flickr offices. He broke up San Francisco into about 350 squares, then calculated the transit times in the center of the square. Based on his notes/code and the research I did, I’ve determined these things:
Possible ways to get the data points:
- Google Maps Web Service API: This way has been pretty much ruled out. The current Rezultati API allows you to get up to 2500 direction requests/day (not enough to create a public site, but enough for my mapping purposes). However, the API only allows for directions by driving, walking, or bicycling – no option for transit! This is a request many have made in their forums, so maybe it will appear some day.
- Google Maps – Web Scraper: This is the method used by Neil (mentioned above) where each data point is looked up through a google map direction request, then the transit time is snagged out of the resulting web page. This method is much slower and likely cheap jerseys to get you banned from Google Maps, but seems to work OK for small data sets.
- Calculate it from Transit Feeds: Since Google created a standard for transit data, there is a collection of publicky-accessible transit data feeds to grab information from. This means it’s possible to calculate transit times without Google, but I’d have to create the calculations myself 🙁
Possible ways to display the data:
- Google Fusion Table + Map: From the example code for Google Fusion Tables, it’s possible to upload the data (our transit times by points) and create a heat map over a Google Map. The example only cheap mlb jerseys shows circles over a map of Brazil, so it’ll be interesting to see what options I cheap nba jerseys have.
- Google Earth: While using Google Earth would make my data easier to plot, it does limit who I could share this with (harder to make a web app out of).
When I first wrote about this project, I had the idea of creating a heat map showing transit times to downtown (to help pick a new apartment for my girlfriend and me). What I didn’t have was a clue how to get started. Luckily, the amount of data manipulation tools has grown since Neil Kandalgaonkar attempted this a few years ago for San Francisco. After some tinkering, I settled on using Google Fusion Tables for my proof of concept.
Gathering the data
When I explored this back in September/October, there were very few options for getting transit data. Bing had just rolled out a transit option to their api, but the cities were limited (and didn’t include San Diego). My only option was to screenscrape the data from Google Maps, using a piece of PHP I created (with influence from Neil’s Code). The code is somewhat modular, so you can drop in your Techsure starting and ending latitude/longitude and destination. I wrote this with a small delay after each request (to keep from being banned by Google) and ran the code overnight from the command line (“php gettimes.php > results.txt”).
- My Code: gettimes.php
Displaying the data
Once I had my data, I discovered Google Fusion Tables was my best bet for cheap jerseys displaying the data. Fusion Tables functions very much like a Google Spreadsheet, but you can select a column and “GeoCode” it – this declares the column as GIS data (either in latitude/longitude, KML, or an address). I used KML (think XML, but for geographic data) for each data point. While you – can draw any polygon with KML, you can draw a square by defining the 4 corners and then repeating the first corner to close out the box.
An example KML entry:
<Polygon><outerBoundaryIs><LinearRing><coordinates>-116.635,32.575 -116.635,32.585 -116.625,32.585 -116.625,32.575 wholesale nfl jerseys -116.635,32.575</coordinates></LinearRing></outerBoundaryIs></Polygon>
(My code didn’t generate each KML entry, though it easily could. I instead used an Excel formula to reformat the lat/long into the proper KML). Once the location is defined, it’s as easy as choosing Visualization->Map to display Weaver the contents!