Switched to Komoot/Photon reverse geolocation service.
This commit is contained in:
parent
31fb40a220
commit
dff6994a2b
Notes:
subgit
2018-03-07 17:59:11 +01:00
r837 www/branches/life
@ -1 +1 @@
|
|||||||
curl -o events.xml "https://ariadne.geophysik.ruhr-uni-bochum.de/fdsnws/event/1/query?starttime=2014-08-01&orderby=time&minlat=50.92&maxlat=52.76&minlon=4.26&maxlon=9.74&minmag=1.1"
|
curl -o events.xml "https://ariadne.geophysik.ruhr-uni-bochum.de/fdsnws/event/1/query?starttime=2015-04-01&orderby=time&minlat=50.92&maxlat=52.76&minlon=4.26&maxlon=9.74&minmag=1.1"
|
||||||
|
@ -39,6 +39,8 @@ def mkGeolocationTable(file=''):
|
|||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from sys import stdin
|
from sys import stdin
|
||||||
import warnings
|
import warnings
|
||||||
|
from time import sleep
|
||||||
|
from geopy.geocoders import Photon
|
||||||
import urllib2 as URL
|
import urllib2 as URL
|
||||||
import json as JSON
|
import json as JSON
|
||||||
|
|
||||||
@ -51,6 +53,7 @@ def mkGeolocationTable(file=''):
|
|||||||
warnings.formatwarning = simple_warning
|
warnings.formatwarning = simple_warning
|
||||||
|
|
||||||
# try loading the file
|
# try loading the file
|
||||||
|
geolocationTable = {}
|
||||||
if file :
|
if file :
|
||||||
try:
|
try:
|
||||||
jsonfile = open(file)
|
jsonfile = open(file)
|
||||||
@ -62,6 +65,7 @@ def mkGeolocationTable(file=''):
|
|||||||
|
|
||||||
# parse event.xml
|
# parse event.xml
|
||||||
DOM = ET.parse(stdin).getroot()
|
DOM = ET.parse(stdin).getroot()
|
||||||
|
geolocator = Photon()
|
||||||
|
|
||||||
# iterate over all events
|
# iterate over all events
|
||||||
for event in DOM.iterfind('qml:eventParameters/qml:event', namespaces):
|
for event in DOM.iterfind('qml:eventParameters/qml:event', namespaces):
|
||||||
@ -75,9 +79,32 @@ def mkGeolocationTable(file=''):
|
|||||||
elif evaluationMode == 'automatic':
|
elif evaluationMode == 'automatic':
|
||||||
warnings.warn('Skipping automatic event %s' %(publicID))
|
warnings.warn('Skipping automatic event %s' %(publicID))
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
location = geolocator.reverse("{lat}, {lng}".format(lat=lat, lng=lng))
|
||||||
|
except:
|
||||||
|
warnings.warn('Reverse Geolocation failed. Skipping event.')
|
||||||
|
continue
|
||||||
|
place = []
|
||||||
|
try:
|
||||||
|
place = location.raw['properties']['city']
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
place = location.raw['properties']['town']
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
place = location.raw['properties']['village']
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
place = location.raw['properties']['county']
|
||||||
|
except KeyError:
|
||||||
|
warnings.warn('Could not extract city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url))
|
||||||
|
geolocationTable[publicID] = place
|
||||||
|
sleep(1.1)
|
||||||
|
|
||||||
|
'''
|
||||||
#warnings.warn('Processing event %s' %publicID)
|
#warnings.warn('Processing event %s' %publicID)
|
||||||
# send and evaluate nominatim request
|
# send and evaluate nominatim request
|
||||||
url = 'https://open.mapquestapi.com/nominatim/v1/reverse.php?lat={0}&lon={1}&zoom=10&format=json'.format(lat, lng)
|
url = 'https://open.mapquestapi.com/nominatim/v1/reverse.php?key=oE512xGQxeH1n2cueacJ6xzRv7qFlCib&lat={0}&lon={1}&zoom=10&format=json'.format(lat, lng)
|
||||||
response = URL.urlopen(url)
|
response = URL.urlopen(url)
|
||||||
if ( response.msg == 'OK' ):
|
if ( response.msg == 'OK' ):
|
||||||
data = JSON.loads(response.read())
|
data = JSON.loads(response.read())
|
||||||
@ -106,6 +133,7 @@ def mkGeolocationTable(file=''):
|
|||||||
warnings.warn('Could not extract city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url))
|
warnings.warn('Could not extract city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url))
|
||||||
else:
|
else:
|
||||||
warnings.warn('Request {0} failed'.format(url))
|
warnings.warn('Request {0} failed'.format(url))
|
||||||
|
'''
|
||||||
# dump json
|
# dump json
|
||||||
print 'var geolocationTable = '+JSON.dumps(geolocationTable, sort_keys=True)+';'
|
print 'var geolocationTable = '+JSON.dumps(geolocationTable, sort_keys=True)+';'
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@
|
|||||||
<span id="events-type">Symbole:</span>
|
<span id="events-type">Symbole:</span>
|
||||||
</p>
|
</p>
|
||||||
<p class="table-caption">
|
<p class="table-caption">
|
||||||
Nominatim Search Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img alt="Mapquest Logo" src="//developer.mapquest.com/content/osm/mq_logo.png" />
|
Reverse Geolocation courtesy of <a href="http://photon.komoot.de/" target="_blank">Photon by Komoot</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<!-- Stations -->
|
<!-- Stations -->
|
||||||
@ -173,7 +173,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- Logo -->
|
<!-- Logo -->
|
||||||
<div class="rublogo"><a href="http://www.gmg.ruhr-uni-bochum.de/geophysik/seisobs"><img class="rublogo" src="logo_RUB_155x30.png" alt="Ruhr-Universität Bochum" title="Ruhr-Universität Bochum" border="0"/></a></div>
|
<div class="rublogo"><a href="http://www.gmg.ruhr-uni-bochum.de/geophysik/seisobs"><img class="rublogo" src="logo_RUB_155x30.png" alt="Ruhr-Universität Bochum" title="Ruhr-Universität Bochum" border="0"/></a></div>
|
||||||
<!-- Map -->
|
<!-- Map -->
|
||||||
<div id="map" class="map"></div>
|
<div id="map" class="map"></div>
|
||||||
<div id="spinner" class="spinner" style="display:none;"><img id="img-spinner" src="spinner.gif" alt="Loading"/><br />Loading ...</div>
|
<div id="spinner" class="spinner" style="display:none;"><img id="img-spinner" src="spinner.gif" alt="Loading"/><br />Loading ...</div>
|
||||||
</body>
|
</body>
|
||||||
|
@ -116,7 +116,7 @@
|
|||||||
<span id="events-type">Symbols:</span>
|
<span id="events-type">Symbols:</span>
|
||||||
</p>
|
</p>
|
||||||
<p class="table-caption">
|
<p class="table-caption">
|
||||||
Nominatim Search Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img alt="Mapquest Logo" src="//developer.mapquest.com/content/osm/mq_logo.png" />
|
Reverse Geolocation courtesy of <a href="http://photon.komoot.de/" target="_blank">Photon by Komoot</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<!-- Stations -->
|
<!-- Stations -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user