21 min read

Open Coffee Map Part 4

Statement of Problem

I continue to require coffee at lunch time. If I was doing a Multi-Criteria Decision Analysis I’d throw in some requirements:

  • Be able to get to the coffee and back within a 30-60 minute lunch.
  • Be reasonably priced.
  • Taste good.
  • Preference for independent coffee shops. Cost/bucks &c. might be acting legally when they minimise their tax bill, but I can take a stand on the ethics of it by preferring local.
  • Getting a reasonable number of steps in is a nice-to-have. If it’s not raining.

Previous Solutions

I looked at this with bits of Python towards the start of this blog, and there’s been some developments in R packages for spatial work, interacting with the OpenStreetMap API, and network theory/graph theory.

Currently they’re not brilliant at talking to each other! But for these purposes it’s not terrible in computing time to load the data twice into different libraries to look at it from different angles - once as geography and once as a network connected by “can walk from A-B”.

Today’s Solution

Normally I put my library calls in the hidden bit at the top, but the serious work is being done by the libraries, so they’re going in the main post today:


First, I grabbed a sensible bounding box and all the cafes inside that box:

bbox <- c(-1.5853357315063479,53.78906626347749,-1.513667106628418,53.81142134499526)

cafe <- opq(bbox = bbox) %>%
  add_osm_feature(key = 'amenity', value="cafe") %>%

tm_shape(cafe$osm_points) + tm_dots()