When Spatial Search Goes Wrong
2019-02-13
I want to find some great pizza near my city of Salisbury, Maryland. I do a search and put in 60 miles as my radius. I get a bunch of results:Salisbury is on a peninsula, separated from western Maryland by the Chespeake Bay, with only one way to cross. Take a look at the pizzas on the left. They are across the Bay, and take hours to drive to.
Instead of a simple buffer, we can create an isochrone. An isochrone is a polygon of everywhere one can travel to within a certain time. An isochrone of 60 minutes for my city looks like this:
Now, I can do a query to get all the pizza joints that are contained within that isochrone polygon:
Good! These are more meaningful results.
There are multiple ways to generate isochrones. The free and open source way is to use PostGIS with pgrouting. For this example, I used the Mapbox isochrone API which is fast and easy.
When your product requires these kind of search queries, think about the application before doing a simple buffer.
Often users don't want results that are geographically close, they want results that are chronologically close.