kiwitobes.com

kiwitobes.com

Author, Software Developer, and Data Magnate

kiwitobes.com RSS Feed
 

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.
San Francisco Map
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.

  1. You’ll need an API key from Google
  2. Download this Base map template
  3. 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).
  4. 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.
  5. If you don’t have the Freebase API installed, you’ll need to run “easy_install simplejson” and “easy_install freebase” to get it
  6. 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.

36 Responses to “A San Francisco Restaurant Health-map (with code)”

  1. Gravatar
    1
    Steve Dekorte:

    For the 10% of the public that is red-green color blind, could you change the colors to blue and red?

  2. Gravatar
    2
    Andy Baio:

    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.

  3. Gravatar
    3
    Fredrik:

    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?

  4. Gravatar
    4
    Spirulina:

    Fajna stronka, bede tu wpadal czesciej, pozdro

  5. Gravatar
    5
    Björn:

    Your headline says “health map”, not “heat map”. The heat map is neat, but a health map would be even more interesting ;-)

  6. Gravatar
    6
    Björn:

    Oops sorry, it actually is a health map ;-) I missed the health department scores.

  7. Gravatar
    7
    Alan:

    I third the request. I would love to use this, but the red/green makes this useless to me. :( They all look the same.

  8. Gravatar
    8
    Omar D. Mignone:

    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. :)

  9. Gravatar
    9
    Cold sore freedom:

    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.

  10. Gravatar
    10
    Botox New York:

    $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.

  11. Gravatar
    11
    Liposuction:

    kiwitobes.com » A San Francisco Restaurant Health-map (with code) great article thank you.

  12. Gravatar
    12
    özel güvenlik:

    kiwitobes.com » A San Francisco Restaurant Health-map (with code) great article thank you.

  13. Gravatar
    13
    M Lockner:

    Wow! great idea!

  14. Gravatar
    14
    Sam Keen:

    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

  15. Gravatar
    15
    Tourist:

    Thanks for interesting article, very informative.

  16. Gravatar
    16
    health medicine:

    excellent article, very nice

  17. Gravatar
    17
    Michael Warren:

    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.

  18. Gravatar
    18
    Lemon Detox Diet Recipe:

    What a great idea!

  19. Gravatar
    19
    Restaurant Cluj:

    There are some huge red spots on this health map. BTW, great way to know a good area for a good restaurant

  20. Gravatar
    20
    Private Label Rights:

    I love your posts! Please write more often if you can

  21. Gravatar
    21
    Tenders:

    Отличное наполнение блога, есть что почитать интересного, спс

  22. Gravatar
    22
    NejikFans:

    Поздравляю, это просто отличная мысль

  23. Gravatar
    23
    internous:

    very interesting article…,nice post
    can you send other articles by email
    thanks

  24. Gravatar
    24
    john janial:

    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

  25. Gravatar
    25
    Tamada:

    Посоветовали мне этот блог, и видно что незря, есть все что я хотел найти.

  26. Gravatar
    26
    Trader:

    Посоветовали друзья этот блог и были правы, все то что я и хотел найти. Понравилось очень

  27. Gravatar
    27
    Gamanets:

    Не совсем то, что ожидал конечно, средненький блог. Еще работать и работать над ним.

  28. Gravatar
    28
    Drew Ade:

    I pretty much totally agree with this. :P

  29. Gravatar
    29
    ihsan:

    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

  30. Gravatar
    30
    brian:

    nice job…

  31. Gravatar
    31
    Buycasodex:

    Very helpful content on your blog!

  32. Gravatar
    32
    geographos:

    A good resource for finding good map color schemes is http://colorbrewer2.org/

  33. Gravatar
    33
    Mike LeBro:

    Great post! I will definitely be reading more of your site more often! This is a great article on health!

  34. Gravatar
    34
    Robert:

    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

  35. Gravatar
    35
    Victoria:

    Its not the crash of realestate market but actually It is because of Current Economic Crises.

  36. Gravatar
    36
    cosmetic dental marketing:

    It was a great blog post mate…..

Leave a Reply