Skip to content

Instantly share code, notes, and snippets.

@michellemho
Last active December 29, 2016 19:59
Show Gist options
  • Save michellemho/5be0f061705600933c6f119e0f2877b8 to your computer and use it in GitHub Desktop.
Save michellemho/5be0f061705600933c6f119e0f2877b8 to your computer and use it in GitHub Desktop.

#POIs within 400m of CARTO using Overpass API

The best way to retrieve POIs in OSM Overpass API is to query for nodes and ways that have a NAME. In the case of WAYS, return only BUILDINGS (as opposed to streets).

http://overpass-turbo.eu/s/kUM

(
  node
    ["name"]
    (around:400,40.704301,-73.936658);
  way
    ["name"]
    ["building"]
    (around:400,40.704301,-73.936658);
);
(
  ._;
  >;
);
out body;

This query will return 22 POIs and 8 Polygons within 400m of CARTO.

Overpass API converted query to use in CARTO: http://overpass-api.de/api/interpreter?data=%28node%5B%22name%22%5D%28around%3A400%2C40%2E704301%2C%2D73%2E936658%29%3Bway%5B%22name%22%5D%5B%22building%22%5D%28around%3A400%2C40%2E704301%2C%2D73%2E936658%29%3B%29%3B%28%2E%5F%3B%3E%3B%29%3Bout%20body%3B%0A

The data format that is exported and uploaded to CARTO will change the results. This CARTO map demonstrates the different formats (GPX, KML, geoJSON, and OSM Compact Query Language).

https://team.carto.com/u/michellemho-carto/builder/9cfebfbc-cd55-11e6-a4bf-0e3ff518bd15/embed

GPX and OSM QL will return multiple datasets for a single import. KML and geoJSON returns one dataset. There’s some strange behavior with KML, in which CARTO might favor polygons and not show points, or show both (see the two KML layers). The data and map can be found in the .Carto file here: Overpass Exports (on 2016-12-29 at 01.07.47).carto.zip

##Details on Keys ###AMENITY http://wiki.openstreetmap.org/wiki/Key:amenity The key “amenity” covers an assortment of community facilities including toilets, telephones, banks, pharmacies and schools. The key “amenity” only applies to nodes and closed ways. Amenities can be part of larger places (for example, ATMs within banks), or used in combination with other keys to create more specific descriptions (for example amenity=recycling can be combined with recycling_type=container for containers or recycling_type=centre for recycling centres), or describe large areas (amenity=school for a school grounds perimeter).

Query for all amenities within 400m radius around CARTO in Brooklyn:

(node
  [amenity]
  (around:400,
40.704301, -73.936658);
way
  [amenity]
  (around:400,
40.704301, -73.936658));
(._;>;);
out;

http://overpass-turbo.eu/s/kUJ

The following list contains amenities that could be considered “businesses” as opposed to public amenities such as parking, garbage bins, benches, etc. Not all are necessarily businesses.

Pub;bar;restaurant;fast_food;cafe;food_court;ice_cream;college;kindergarten;library;school;music_school;driving_school;language_school;university;bicycle_rental;boat_sharing;car_rental;car_sharing;car_wash;ferry_terminal;fuel;bank;bureau_de_change;clinic;dentist;doctors;hospital;nursing_home;pharmacy;social_facility;veterinary;blood_donation;arts_centre;brothel;casino;community_centre;cinema;gambling;nightclub;planetarium;social_centre;stripclub;swingerclub;studio;theatre;animal_boarding;animal_shelter;courthouse;coworking_space;crematorium;dive_centre;dojo;embassy;fire_station;internet_cafe;marketplace;place_of_worship;police;post_office;prison;townhall;waste_transfer_station

Query for “business” amenities within 4000m of CARTO: http://overpass-turbo.eu/s/kUG pois: 869, lines: 0, polygons: 369

For comparison, the query for all amenities within 4000m of CARTO: http://overpass-turbo.eu/s/kUH pois: 1568, lines: 16, polygons: 486

###SHOP http://wiki.openstreetmap.org/wiki/Key:shop The key “shop” describes locations that sell products (as opposed to services). All shops are businesses. Usually used in conjunction with building=commercial.

Query for all shops within 400m radius around CARTO in Brooklyn:

(node
  [shop]
  (around:400,40.704301, -73.936658);
way
  [shop]
  (around:400, 40.704301, -73.936658);
relation
  [shop]
  (around:400,40.704301, -73.936658));
(._;>;);
out;

http://overpass-turbo.eu/s/kUI

###OFFICE The key “office” describes locations that offer professional services (as opposed to products, ie. shops). ###BUILDING http://wiki.openstreetmap.org/wiki/Key:building

The key “building” is used to mark building footprints. Often, it is used to indicate the location of a building within a larger area (for example, a hotel building on hotel grounds including recreation areas and parking). Not all buildings are businesses.

@talos
Copy link

talos commented Dec 29, 2016

Looks great! Looks like the amenity/shop approach might actually be best, as buildings are inconsistently tagged (saying this having compared the three maps against what is styled as a POI in OSM's own map.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment