From 1d286c3f505f481c929eba2cb6220acb2d13693d Mon Sep 17 00:00:00 2001 From: "Kasper D. Fischer" Date: Thu, 1 Oct 2015 11:43:37 +0000 Subject: [PATCH 1/4] Adding Komoot tile service. --- www/map.js | 12 ++++++++++++ www/map.js.en | 10 ++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/www/map.js b/www/map.js index 5f563ab..157345f 100644 --- a/www/map.js +++ b/www/map.js @@ -61,6 +61,12 @@ function addEventMarker(id, lat, lng, mag, type) { case 'earthquake': marker = L.starMarker(L.latLng(lat, lng), markerOptions); break; + case 'explosion': + markerOptions['numberOfSides'] = 6; + markerOptions['radius'] = 2.0*markerOptions['radius']; + markerOptions['innerRadius'] = 0.3*markerOptions['radius']; + marker = L.regularPolygonMarker(L.latLng(lat, lng), markerOptions); + break; case 'quarry blast': markerOptions['numberOfPoints'] = 7; markerOptions['innerRadius'] = 0.3*markerOptions['radius']; @@ -152,6 +158,12 @@ $(document).ready(function() { attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community' }).addTo(map); break; + case 'komoot': // add OpenStreetMap.DE tile layer + L.tileLayer('//www.komoot.de/tiles/{s}/{z}/{x}/{y}.png', + { + attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA | Tiles Courtesy of Komoot', + }).addTo(map); + break; case 'mapquestgray': // add MapQuestOSM tile layer L.tileLayer.grayscale('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg', { diff --git a/www/map.js.en b/www/map.js.en index 44c6fde..867aef8 100644 --- a/www/map.js.en +++ b/www/map.js.en @@ -158,6 +158,12 @@ $(document).ready(function() { attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community' }).addTo(map); break; + case 'komoot': // add OpenStreetMap.DE tile layer + L.tileLayer('//www.komoot.de/tiles/{s}/{z}/{x}/{y}.png', + { + attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA | Tiles Courtesy of Komoot', + }).addTo(map); + break; case 'mapquestgray': // add MapQuestOSM tile layer L.tileLayer.grayscale('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg', { @@ -214,8 +220,4 @@ $(document).ready(function() { }; }); }); - - // print icon - // L.easyPrint().addTo(map); - }); From 31fb40a22075802b7916401846b01b7d3be4a9ac Mon Sep 17 00:00:00 2001 From: "Kasper D. Fischer" Date: Thu, 1 Oct 2015 11:53:10 +0000 Subject: [PATCH 2/4] Changed Nominatim (Reverse Geocoding) service to Komoot Photon. --- www/events.js | 17 ++++++----------- www/events.js.en | 13 +++++-------- www/misc.js | 5 ++--- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/www/events.js b/www/events.js index 379520d..cd44da9 100644 --- a/www/events.js +++ b/www/events.js @@ -41,15 +41,12 @@ function addTableRow(row, table) { /* do reverse geolocation lookup */ function getGeolocation(id, lat, lng) { if ( !geolocationTable[id] ) { - $.getJSON( config['ajax']['nominatimURL'], { lat: lat, lon: lng, zoom: 10, format: "json" } ) + $.getJSON( config['ajax']['nominatimURL'], { lat: lat, lon: lng } ) .done(function( json ) { - var city = json.address["city"]; - if ( ~city ) { city = json.address["town"]; }; - if ( ~city ) { city = json.address["village"]; }; - var country = json.address["country"]; - var countryCode = json.address["country_code"].toUpperCase(); + var city = json.features[0].properties.city; + var countryCode = json.features[0].properties.country; geolocationTable[id] = city; - ( countryCode != "DE" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null; + ( countryCode != "Germany" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null; if ( city ) { $("#eventstable a.toggle[eventid="+id+"]").text(geolocationTable[id]); var sort = [[0,1],[1,1],[2,1]]; @@ -120,12 +117,10 @@ function ajaxLoadEvents(stime, etime, eventid, url, target) { var evaluationStatus = $(this).find('origin > evaluationStatus').text(); var type = $(this).find('type').last().text(); var location - // get location, try this in order: - // regional map name, given value, cached value, or nominatim lookup - geolocationTable[id] ? null : getGeolocation(id, lat, lng); // do AJAX lookup if not cached, location will be updated later - location = ( geolocationTable[id] || getLocation(lat, lng)[0] || $(this).find('description > text').text() ); // create table row: Date, Time, Mag, Location if ( !eventTable[id] && $.inArray(type, config['event']['typeWhitelist'] )+1 && $.inArray(evaluationStatus, config['event']['evaluationBlacklist'])<0 && Number(mag)+0.05 >= config['event']['minMag'] ) { + geolocationTable[id] ? null : getGeolocation(id, lat, lng); // do AJAX lookup if not cached, location will be updated later + location = ( geolocationTable[id] || getLocation(lat, lng)[0] || $(this).find('description > text').text() ); // general event info (1st line) var row = '' + ''+otime.split('.')[0]+'Z' diff --git a/www/events.js.en b/www/events.js.en index 0bf8c60..aa2c0b1 100644 --- a/www/events.js.en +++ b/www/events.js.en @@ -41,15 +41,12 @@ function addTableRow(row, table) { /* do reverse geolocation lookup */ function getGeolocation(id, lat, lng) { if ( !geolocationTable[id] ) { - $.getJSON( config['ajax']['nominatimURL'], { lat: lat, lon: lng, zoom: 10, format: "json" } ) + $.getJSON( config['ajax']['nominatimURL'], { lat: lat, lon: lng } ) .done(function( json ) { - var city = json.address["city"]; - if ( ~city ) { city = json.address["town"]; }; - if ( ~city ) { city = json.address["village"]; }; - var country = json.address["country"]; - var countryCode = json.address["country_code"].toUpperCase(); + var city = json.features[0].properties.city; + var countryCode = json.features[0].properties.country; geolocationTable[id] = city; - ( countryCode != "DE" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null; + ( countryCode != "Germany" ) ? geolocationTable[id] = geolocationTable[id] + " ("+countryCode+")" : null; if ( city ) { $("#eventstable a.toggle[eventid="+id+"]").text(geolocationTable[id]); var sort = [[0,1],[1,1],[2,1]]; @@ -90,7 +87,7 @@ function ajaxLoadEvents(stime, etime, eventid, url, target) { } else { request_data = { starttime: sprintf("%d-%02d-%02d", rtime.getFullYear(), rtime.getMonth()+1, rtime.getDate()), - orderby: 'time', + orderby: 'time-asc', minlat: sprintf('%.2f', mapBounds.getSouth()-config['map']['latlngDelta']), maxlat: sprintf('%.2f', mapBounds.getNorth()+config['map']['latlngDelta']), minlon: sprintf('%.2f', mapBounds.getWest()-config['map']['latlngDelta']), diff --git a/www/misc.js b/www/misc.js index 809136e..df925d1 100644 --- a/www/misc.js +++ b/www/misc.js @@ -95,9 +95,8 @@ var config = { dlsvURL: 'dlsv', mseedURL: '/fdsnws/dataselect/1/query', stationURL: '/fdsnws/station/1/query', - nominatimURL: '//open.mapquestapi.com/nominatim/v1/reverse.php', - // nominatimURL: '//nominatim.openstreetmap.org/reverse', - timespan: 60, + nominatimURL: 'http://photon.komoot.de/reverse', + timespan: 180, }, event: { evaluationBlacklist: ['automatic', 'preliminary', 'rejected'], From dff6994a2bd8ac66206c891011ae9b2058e5f956 Mon Sep 17 00:00:00 2001 From: "Kasper D. Fischer" Date: Thu, 1 Oct 2015 14:37:41 +0000 Subject: [PATCH 3/4] Switched to Komoot/Photon reverse geolocation service. --- scripts/mkEvents.csh | 2 +- scripts/mkGeolocationTable.py | 30 +++++++++++++++++++++++++++++- www/index.html.de | 4 ++-- www/index.html.en | 2 +- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/scripts/mkEvents.csh b/scripts/mkEvents.csh index a4cb770..4b6d670 100755 --- a/scripts/mkEvents.csh +++ b/scripts/mkEvents.csh @@ -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" diff --git a/scripts/mkGeolocationTable.py b/scripts/mkGeolocationTable.py index fd2a891..64082c5 100755 --- a/scripts/mkGeolocationTable.py +++ b/scripts/mkGeolocationTable.py @@ -39,6 +39,8 @@ def mkGeolocationTable(file=''): import xml.etree.ElementTree as ET from sys import stdin import warnings + from time import sleep + from geopy.geocoders import Photon import urllib2 as URL import json as JSON @@ -51,6 +53,7 @@ def mkGeolocationTable(file=''): warnings.formatwarning = simple_warning # try loading the file + geolocationTable = {} if file : try: jsonfile = open(file) @@ -62,6 +65,7 @@ def mkGeolocationTable(file=''): # parse event.xml DOM = ET.parse(stdin).getroot() + geolocator = Photon() # iterate over all events for event in DOM.iterfind('qml:eventParameters/qml:event', namespaces): @@ -75,9 +79,32 @@ def mkGeolocationTable(file=''): elif evaluationMode == 'automatic': warnings.warn('Skipping automatic event %s' %(publicID)) 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) # 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) if ( response.msg == 'OK' ): 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)) else: warnings.warn('Request {0} failed'.format(url)) + ''' # dump json print 'var geolocationTable = '+JSON.dumps(geolocationTable, sort_keys=True)+';' diff --git a/www/index.html.de b/www/index.html.de index 2ed0153..5cb2541 100755 --- a/www/index.html.de +++ b/www/index.html.de @@ -112,7 +112,7 @@ Symbole:

- Nominatim Search Courtesy of MapQuest Mapquest Logo + Reverse Geolocation courtesy of Photon by Komoot

@@ -173,7 +173,7 @@ - +
diff --git a/www/index.html.en b/www/index.html.en index 0474a92..619ca49 100755 --- a/www/index.html.en +++ b/www/index.html.en @@ -116,7 +116,7 @@ Symbols:

- Nominatim Search Courtesy of MapQuest Mapquest Logo + Reverse Geolocation courtesy of Photon by Komoot

From 23ccbb8d9baf98ebdde65f30c38a9d4b73bb104f Mon Sep 17 00:00:00 2001 From: "Kasper D. Fischer" Date: Thu, 1 Oct 2015 15:13:56 +0000 Subject: [PATCH 4/4] Switched Komoot Geolocation url to https --- www/misc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/misc.js b/www/misc.js index df925d1..69c0a8a 100644 --- a/www/misc.js +++ b/www/misc.js @@ -95,7 +95,7 @@ var config = { dlsvURL: 'dlsv', mseedURL: '/fdsnws/dataselect/1/query', stationURL: '/fdsnws/station/1/query', - nominatimURL: 'http://photon.komoot.de/reverse', + nominatimURL: 'https://photon.komoot.de/reverse', timespan: 180, }, event: {