Created
May 16, 2025 07:05
-
-
Save sven4all/2b69fc2dc08e624171235e21ce360aab to your computer and use it in GitHub Desktop.
An example python script for how you can get data https://api.datadeelmobiliteit.nl/vehicles and filter out all data outside of a GeoJSON file.
This file contains hidden or 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 requests | |
import json | |
from shapely.geometry import shape, Point | |
# Step 1: Load Zwolle boundary GeoJSON manually | |
with open("zwolle.geojson") as f: | |
geojson = json.load(f) | |
# Assuming the first feature contains the polygon | |
zwolle_polygon = shape(geojson['features'][0]['geometry']) | |
# Step 2: Fetch vehicle data from the API | |
url = "https://api.datadeelmobiliteit.nl/vehicles" # Replace with actual URL | |
response = requests.get(url) | |
data = response.json() | |
vehicles = data['data']['vehicles'] | |
# Step 3: Filter vehicles within Zwolle | |
vehicles_in_zwolle = [] | |
for v in vehicles: | |
point = Point(v['lon'], v['lat']) | |
if zwolle_polygon.contains(point): | |
vehicles_in_zwolle.append(v) | |
# Step 4: Print filtered vehicles | |
print(json.dumps(vehicles_in_zwolle, indent=2)) |
This file contains hidden or 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
requests==2.32.2 | |
shapely==2.1.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment