Release v2.0 - add Netherlands POI analysis
This commit is contained in:
+37
-35
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Adres Analyse - Rapport generator
|
||||
Gebruikt PDOK voor geocoding en ORS voor isochronen
|
||||
Gebruikt PDOK voor geocoding, ORS voor isochronen/routes en PostGIS OSM-data voor voorzieningen.
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -10,13 +10,14 @@ import urllib.request
|
||||
import urllib.parse
|
||||
from datetime import datetime
|
||||
|
||||
from voorzieningen import analyse_voorzieningen, format_voorzieningen_markdown
|
||||
|
||||
# Config
|
||||
ORS_BASE = "http://192.168.1.71:9080/ors/v2"
|
||||
PDOK_BASE = "https://api.pdok.nl/bzk/locatieserver/search/v3_1"
|
||||
|
||||
def geocode_adres(adres):
|
||||
"""Geocode adres naar coördinaten via PDOK Locatieserver"""
|
||||
# Gebruik suggest endpoint voor betere adres matching
|
||||
params = urllib.parse.urlencode({
|
||||
'q': adres,
|
||||
'rows': 5,
|
||||
@@ -30,7 +31,6 @@ def geocode_adres(adres):
|
||||
if not data['response']['docs']:
|
||||
raise ValueError(f"Adres niet gevonden: {adres}")
|
||||
|
||||
# Zoek naar exact adres match (type=adres)
|
||||
doc = None
|
||||
for d in data['response']['docs']:
|
||||
if d.get('type') == 'adres':
|
||||
@@ -38,9 +38,8 @@ def geocode_adres(adres):
|
||||
break
|
||||
|
||||
if not doc:
|
||||
doc = data['response']['docs'][0] # Fallback naar eerste resultaat
|
||||
doc = data['response']['docs'][0]
|
||||
|
||||
# Parse POINT(lon lat) format
|
||||
point = doc['centroide_ll']
|
||||
coords = point.replace('POINT(', '').replace(')', '').split()
|
||||
lon, lat = float(coords[0]), float(coords[1])
|
||||
@@ -58,7 +57,7 @@ def haal_isochroon(lon, lat, profiel='driving-car', minuten=20):
|
||||
url = f"{ORS_BASE}/isochrones/{profiel}"
|
||||
payload = {
|
||||
"locations": [[lon, lat]],
|
||||
"range": [minuten * 60], # seconden
|
||||
"range": [minuten * 60],
|
||||
"attributes": ["area", "reachfactor", "total_pop"]
|
||||
}
|
||||
|
||||
@@ -81,49 +80,52 @@ def format_oppervlakte(m2):
|
||||
else:
|
||||
return f"{m2:.0f} m²"
|
||||
|
||||
def print_isochroon_sectie(titel, icoon, iso_data):
|
||||
print(f"{icoon} **{titel}**")
|
||||
if 'features' in iso_data and iso_data['features']:
|
||||
props = iso_data['features'][0]['properties']
|
||||
area_m2 = props.get('area', 0)
|
||||
reach = props.get('reachfactor', 0)
|
||||
print(f"**Oppervlakte:** {format_oppervlakte(area_m2)}")
|
||||
print(f"**Reach factor:** {reach:.3f}")
|
||||
bbox = iso_data.get('bbox', [])
|
||||
if len(bbox) == 4:
|
||||
print(f"**Bereik:** {bbox[1]:.3f}°-{bbox[3]:.3f}°N, {bbox[0]:.3f}°-{bbox[2]:.3f}°E")
|
||||
else:
|
||||
print("❌ Geen isochroon data ontvangen")
|
||||
print()
|
||||
|
||||
def genereer_rapport(adres_input):
|
||||
"""Genereer volledig adres analyse rapport"""
|
||||
print(f"📍 **Adres Analyse Rapport**")
|
||||
print(f"Gegenereerd: {datetime.now().strftime('%d-%m-%Y %H:%M')}")
|
||||
print()
|
||||
|
||||
# Geocoding
|
||||
print("🔍 Geocoding...")
|
||||
locatie = geocode_adres(adres_input)
|
||||
print(f"**Adres:** {locatie['adres']}")
|
||||
print(f"**Coördinaten:** {locatie['lat']:.6f}, {locatie['lon']:.6f}")
|
||||
print()
|
||||
|
||||
# Isochroon
|
||||
print("🚗 **Bereikbaarheid (Auto 20 min)**")
|
||||
iso_data = haal_isochroon(locatie['lon'], locatie['lat'], 'driving-car', 20)
|
||||
|
||||
if 'features' in iso_data and iso_data['features']:
|
||||
props = iso_data['features'][0]['properties']
|
||||
area_m2 = props.get('area', 0)
|
||||
reach = props.get('reachfactor', 0)
|
||||
|
||||
print(f"**Oppervlakte:** {format_oppervlakte(area_m2)}")
|
||||
print(f"**Reach factor:** {reach:.3f}")
|
||||
print()
|
||||
|
||||
# Bereken bbox
|
||||
bbox = iso_data.get('bbox', [])
|
||||
if len(bbox) == 4:
|
||||
print(f"**Bereik:** {bbox[1]:.3f}°-{bbox[3]:.3f}°N, {bbox[0]:.3f}°-{bbox[2]:.3f}°E")
|
||||
print()
|
||||
|
||||
# Save GeoJSON voor kaart generatie
|
||||
output_file = f"/tmp/isochroon_{datetime.now().strftime('%Y%m%d_%H%M%S')}.geojson"
|
||||
with open(output_file, 'w') as f:
|
||||
json.dump(iso_data, f)
|
||||
print(f"💾 Data opgeslagen: `{output_file}`")
|
||||
else:
|
||||
print("❌ Geen isochroon data ontvangen")
|
||||
|
||||
auto_iso = haal_isochroon(locatie['lon'], locatie['lat'], 'driving-car', 20)
|
||||
fiets_iso = haal_isochroon(locatie['lon'], locatie['lat'], 'cycling-regular', 30)
|
||||
print_isochroon_sectie("Bereikbaarheid (Auto 20 min)", "🚗", auto_iso)
|
||||
print_isochroon_sectie("Bereikbaarheid (Fiets 30 min)", "🚲", fiets_iso)
|
||||
|
||||
print("🏙️ **Voorzieningen dichtbij**")
|
||||
voorzieningen = analyse_voorzieningen(locatie['lon'], locatie['lat'], limit=5)
|
||||
print(format_voorzieningen_markdown("🛒 **Supermarkten**", voorzieningen['supermarkten']))
|
||||
print()
|
||||
print(format_voorzieningen_markdown("🏫 **Scholen**", voorzieningen['scholen']))
|
||||
print()
|
||||
|
||||
output_file = f"/tmp/isochronen_{datetime.now().strftime('%Y%m%d_%H%M%S')}.geojson"
|
||||
with open(output_file, 'w') as f:
|
||||
json.dump({'auto_20_min': auto_iso, 'fiets_30_min': fiets_iso}, f)
|
||||
print(f"💾 Isochroondata opgeslagen: `{output_file}`")
|
||||
print()
|
||||
print("---")
|
||||
print("_Onderdeel 1/?: Isochroon bereikbaarheid_")
|
||||
print("_Onderdelen: geocoding, isochronen, voorzieningen_")
|
||||
|
||||
if __name__ == '__main__':
|
||||
adres = sys.argv[1] if len(sys.argv) > 1 else "Griendvelden 14 Best"
|
||||
|
||||
Reference in New Issue
Block a user