“You're in a gun shop. How far away is the nearst bank?”
This script processes OpenStreetMap data to answer questions like that.
You give it an OSM data file, and for everything tagged one way (e.g. shop=weapons
for gun shops), it finds the closest thing with the other tag(s) (amenity=bank
for banks, amenity=atm
for ATMs).
osm-distance-to-nearest -i DATA.osm.pbf -a shop=weapons -b amenity=atm,bank -o guns_banks_
Creates guns_banks_distances.csv
(and guns_banks_distances.geojson
)
-i FILENAME.osm.pbf
: Input filename to process. Takes anythingosmium
can read.-a OSMIUM_FILTER
: Theosmium tags-filter
filter expression to select the A objects-b OSMIUM_FILTER
: tags filter to select B-o OUTPUT_PREFIX
: (optional) text to prefix for files
There is one row for every OSM element tagged with the -a
filter, and it has
been matched up to the row with -b
which is the closest.
a_tags
: OSM tags for object A. Encoded in JSON, and escaped for CSVa_osm_type
: Text showing OSM Type for A: eithernode
,way
orrelation
a_osm_id
: Integer of the OSM ID for Ab_tags
: OSM tags for object B. Encoded in JSON, and escaped for CSVb_osm_type
: Text showing OSM Type for B: eithernode
,way
orrelation
b_osm_id
: Integer of the OSM ID for Bdistance_m
: Distance in metres between A & B. Uses great circle calculation. “As the crow flies distance”a_point_wkt
: Centroid of object A, encoded as a Well Known Text pointa_point_geojson
: Centroid of A, as a GeoJSON geometrya_point_lat
: Latitide of the centroid of A. Floating point numbera_point_lng
: Longitude of the centroid of A. Floating point numberb_point_wkt
: Centroid of object B, encoded as a Well Known Text pointb_point_geojson
: Centroid of B, as a GeoJSON geometryb_point_lat
: Latitide of the centroid of B. Floating point numberb_point_lng
: Longitude of the centroid of B. Floating point numberline_wkt
: Line from A to B, encoded as WKTline_geojson
: Line from A to B, encoded as GeoJSON geometry
The CSV could be converted to GeoJSON with this command:
ogr2ogr -F GeoJSON OUTPUT.geojson FILENAME.csv -oo GEOM_POSSIBLE_NAMES=line_wkt -oo KEEP_GEOM_COLUMNS=no
osmium
: Tags are filtered with osmium tool.
Vincent Privat posted on twitter of a gun shop across the road from a bank (technially an ATM). WeeklyOSM reported in №634. So it got me thinking.
Copyright, GNU Affero General Public Licence v3 (or later) © 2022 Amanda McCann amanda@technomancy.org. See LICENCE
Data & Derived Work from the OpenStreetMap project is open data, licensed under the Open Data Commons Open Database License (ODbL), and © OpenStreetMap Contributors