A San Francisco Restaurant Health-map (with code)
If you’re just interested in a heat-map of restaurant sketchiness in San Francisco, here it is! If you want to learn about how it was done, keep reading below.

Click to see the interactive map
(In addition to showing the “sketchy areas”, it also is great just for seeing where the clusters restaurants are, which is really what defines the neighborhood centers)
Thanks to the ever resourceful Adrian Holovaty, I figured out that one could actually get license-free restaurant listings by scanning city-government records (those of you not looking to republish the data could just use the Yelp API or something). I got about 3000 restaurants into Freebase, along with their health department scores.
Addresses in Freebase are geocoded automatically by the geobot, so it was pretty easy for me to make this map of San Francisco, along with all the restaurants colored by their score.
If you’d like to do something similar yourself, I’ve created a few templates and scripts that you can work through. The Google Maps API and Freebase API are well-documented, but sometimes it’s nice to have a really basic tutorial to get you started.
- You’ll need an API key from Google
- Download this Base map template
- If you want custom icons, you’ll need to draw or generate them. In this case, I wrote a python script to make a set of colored dots going from red to green. You can (right-click) download the script make_icons.py (requires PIL).
- I uploaded the icons to a directory called “icons”, and the created the icons in the page with this script
// Create your icons
r=[];
for (i=2;i<11;i++) {
r[i] = new GIcon();
r[i].image = "icons/rated"+i+".png";
r[i].shadow=null;
r[i].iconSize=new GSize(8,8);
r[i].shadowSize=new GSize(0,0);
r[i].iconAnchor=new GPoint(3,3);
}
Understanding how to do custom icons was a little tricky, a lot of attributes need to be set before they work properly. - If you don’t have the Freebase API installed, you’ll need to run “easy_install simplejson” and “easy_install freebase” to get it
- Finally, you can generate all the overlays and paste them into your code with a script like make_overlays.txt. This script just prints a bunch of javascript, which you can capture and paste into your map HTML file.
Easy, wasn’t it? I suggest you take a look at make_overlays.py and see what it’s doing. Essentially, there’s a query at the top to pull out the scores and addresses of all the topics that have my personal type “health_department_rated_business”. The addresses have geolocations attached by the geobot.
If you wanted to use this recipe to make a map of something else, you can change the query. For example, I could just pull out businesses that start with the letter ‘M’.
query={'type':'/business/business_location/address',
'name~=':'^M',
'name':None,
'/business/business_location/address':{'citytown':'San Francisco',
'/location/location/geolocation':{'latitude':None,'longitude':None}}
}
(If you try this, remember to get rid of the references to “score” in the loop below)
If you make a map using this recipe, let me know and I’ll link to it!
Update: Fixed the python code links. Sorry about the red-green problem, I’ll fix it as soon as I get a chance.
August 18th, 2008 at 3:55 pm
For the 10% of the public that is red-green color blind, could you change the colors to blue and red?
August 19th, 2008 at 4:56 am
First off, this looks wonderful.
I’ll second the request for different colors… I thought I was going crazy, staring at these dots, trying to make out the differences between them.
August 19th, 2008 at 4:58 am
I get “Internal Server Error” when I try to look at the Python files. Could your server be set up to treat any PY-file as a CGI script?
August 19th, 2008 at 5:14 pm
Fajna stronka, bede tu wpadal czesciej, pozdro
October 15th, 2008 at 5:02 am
Your headline says “health map”, not “heat map”. The heat map is neat, but a health map would be even more interesting
October 15th, 2008 at 5:03 am
Oops sorry, it actually is a health map
I missed the health department scores.
January 21st, 2009 at 3:18 am
I third the request. I would love to use this, but the red/green makes this useless to me.
They all look the same.
March 6th, 2009 at 3:44 am
Hi nice post, i have come across your site once before when searching for something so i was just wondering something. I love your theme, would it happen to be a free one i can download, or is it a custom one you had made? In a few months i may get my own domain, but i don’t know how to setup themes so i don’t mind paying someone to make me a nice one and set it all up. Do you know any good Wordpress designer companies, thanks for your help.
April 3rd, 2009 at 2:53 am
As i can see colors pretty well, this map was really useful to me, but it will be a good idea to change the red n blue dots for a better traffic to your site. Thanks a lot.
April 17th, 2009 at 12:44 am
$250/per area special. Board Certified MD Botox(r) treatments
for wrinkles, gummy smile, hyperhidrosis, jaw line reduction, eyebrow lift.
We are located in NYC.
May 4th, 2009 at 12:55 pm
kiwitobes.com » A San Francisco Restaurant Health-map (with code) great article thank you.
May 5th, 2009 at 5:31 pm
kiwitobes.com » A San Francisco Restaurant Health-map (with code) great article thank you.
June 7th, 2009 at 5:48 pm
Wow! great idea!
June 9th, 2009 at 11:17 am
Hey Toby,
I finally got some time to build a similar map for Portland, Oregon. Thanks for the idea!
http://dabbling.in/geo/portland-restaurant-health-map
June 25th, 2009 at 3:05 am
Thanks for interesting article, very informative.
June 30th, 2009 at 3:00 pm
excellent article, very nice
July 3rd, 2009 at 5:24 am
Hi Well Written Post,
I dont normally comment on blogs but your post was a real call to action. Thank you for a great read, I will be sure to bookmark your site and check in now and again.
mical.
July 11th, 2009 at 4:07 am
What a great idea!
September 1st, 2009 at 12:55 am
There are some huge red spots on this health map. BTW, great way to know a good area for a good restaurant
September 1st, 2009 at 8:10 pm
I love your posts! Please write more often if you can
September 5th, 2009 at 8:15 am
Отличное наполнение блога, есть что почитать интересного, спс
September 5th, 2009 at 12:33 pm
Поздравляю, это просто отличная мысль
September 7th, 2009 at 10:58 am
very interesting article…,nice post
can you send other articles by email
thanks
September 12th, 2009 at 6:02 am
Hi,
Just found your blog on Technorati & Digg upcomming news feeds and read a few of your other posts.
ISeems good contents,Keep up the good work. Look forward to reading more from you in the future.
Thanks,
Michael
September 15th, 2009 at 1:10 pm
Посоветовали мне этот блог, и видно что незря, есть все что я хотел найти.
September 16th, 2009 at 5:55 pm
Посоветовали друзья этот блог и были правы, все то что я и хотел найти. Понравилось очень
September 17th, 2009 at 3:26 am
Не совсем то, что ожидал конечно, средненький блог. Еще работать и работать над ним.
September 28th, 2009 at 12:28 pm
I pretty much totally agree with this.
October 5th, 2009 at 6:19 am
hi
healt and sliming is important at the life
this very populer and safe products for healt
garlica is plant products
here is somne link you can get information
garlica
garlica
garlica
garlica
October 9th, 2009 at 8:51 am
nice job…
October 23rd, 2009 at 2:34 pm
Very helpful content on your blog!
December 11th, 2009 at 4:41 am
A good resource for finding good map color schemes is http://colorbrewer2.org/
December 22nd, 2009 at 7:31 pm
Great post! I will definitely be reading more of your site more often! This is a great article on health!
December 22nd, 2009 at 10:58 pm
Hi,
I came across your site because I enjoy the wonderful Google maps. I have listed that wonderful city in http://currate.com/map.php web site - world’s first Google World Currencies Map with Currency Images.
Cheers,
Robert
Currate.com Developer/Publisher
December 30th, 2009 at 1:48 am
Its not the crash of realestate market but actually It is because of Current Economic Crises.
January 23rd, 2010 at 1:06 pm
It was a great blog post mate…..