Created
April 23, 2023 01:19
-
-
Save ToucheSir/afded417533d67be6bd47d5687024c64 to your computer and use it in GitHub Desktop.
Querying amenities in Greater Victoria using OSM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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