misc-fred/grandlyon/wcs-scripts/has_close_demands.py

26 lines
974 B
Python

import json
import os
from quixote import get_publisher
from wcs.wf.geolocate import GeolocateWorkflowStatusItem
result = False
coords = vars().get('form_var_carte')
if not coords and 'form_var_numero' in vars():
geolocate = GeolocateWorkflowStatusItem()
geolocate.method = 'address_string'
geolocate.address_string = '[form_var_numero] [form_var_voie], [form_var_commune], France'
coords = geolocate.geolocate_address_string(None)
coords = '%(lat)s;%(lon)s' % coords
if coords:
lat, lon = coords.split(';')
lat, lon = float(lat), float(lon)
lat1, lat2 = lat - 0.008, lat + 0.008
lon1, lon2 = lon - 0.006, lon + 0.006
geojson_file = os.path.join(get_publisher().app_dir, 'geojsons', form_slug + '.json')
for feature in json.load(open(geojson_file))['features']:
lon, lat = feature['geometry']['coordinates']
if lon > lon1 and lon < lon2 and lat > lat1 and lat < lat2:
result = True
break