Skip to content

Instantly share code, notes, and snippets.

@ToucheSir
Created April 23, 2023 01:19
Show Gist options
  • Save ToucheSir/afded417533d67be6bd47d5687024c64 to your computer and use it in GitHub Desktop.
Save ToucheSir/afded417533d67be6bd47d5687024c64 to your computer and use it in GitHub Desktop.
Querying amenities in Greater Victoria using OSM
import osmnx as ox
import matplotlib.pyplot as plt
from pathlib import Path
AMENITY_QUERIES = [
("bank", {"amenity": "bank"}),
("bar", {"amenity": ["bar", "pub"]}),
("coffee shop", {"amenity": "cafe", "cuisine": "coffee_shop"}),
(
"greater victoria public library",
{"operator": "Greater Victoria Public Library"},
),
("medical clinic", {"amenity": "clinic"}),
("school", {"amenity": "school"}),
(
"store",
{
"shop": ["supermarket", "greengrocer", "convenience"],
"name": ["Walmart", "Wholesale Club"],
},
),
]
COL_REGEX = r"^(name|brand|geometry|(addr:\w+))$"
if __name__ == "__main__":
data_dir = Path("amenity_data_gva")
data_dir.mkdir(exist_ok=True)
for amenity, query in AMENITY_QUERIES:
places = ox.geometries_from_place("Greater Victoria", query)
places = places.filter(regex=COL_REGEX)
places.to_file(data_dir / f"{amenity}.geojson", driver="GeoJSON")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment