From: Sarah Hoffmann Date: Mon, 26 Sep 2016 10:08:42 +0000 (+0200) Subject: look for extra place tags in Nominatim search results X-Git-Tag: live~4356 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/5efbc8a8b7094588fb4745c25778d7746ec0b64b look for extra place tags in Nominatim search results Administrative boundaries at municipality level are generally better described by the place node (as town, village etc.). Nominatim exports the place type in extratags if it was able to merge place nodes with admin boundaries. Use this preferably to create the descriptive term. --- diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 8afa80d7f..8ad51b234 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -149,7 +149,7 @@ class GeocoderController < ApplicationController exclude = "&exclude_place_ids=#{params[:exclude]}" if params[:exclude] # ask nominatim - response = fetch_xml("http:#{NOMINATIM_URL}search?format=xml&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}") + response = fetch_xml("http:#{NOMINATIM_URL}search?format=xml&extratags=1&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}") # extract the results from the response results = response.elements["searchresults"] @@ -179,6 +179,11 @@ class GeocoderController < ApplicationController if klass == "boundary" && type == "administrative" rank = (place.attributes["place_rank"].to_i + 1) / 2 prefix_name = t "geocoder.search_osm_nominatim.admin_levels.level#{rank}", :default => prefix_name + place.elements["extratags"].elements.each("tag") do |extratag| + if extratag.attributes["key"] == "place" + prefix_name = t "geocoder.search_osm_nominatim.prefix.place.#{extratag.attributes["value"]}", :default => prefix_name + end + end end prefix = t "geocoder.search_osm_nominatim.prefix_format", :name => prefix_name object_type = place.attributes["osm_type"] diff --git a/test/controllers/geocoder_controller_test.rb b/test/controllers/geocoder_controller_test.rb index 7899bd982..57d5a10f1 100644 --- a/test/controllers/geocoder_controller_test.rb +++ b/test/controllers/geocoder_controller_test.rb @@ -387,7 +387,7 @@ class GeocoderControllerTest < ActionController::TestCase "min-lat" => 51.7265723, "max-lat" => 51.7665723, "min-lon" => -0.0390782, "max-lon" => 0.0009218, "type" => "node", "id" => 28825933 }, - { "prefix" => "City Boundary", + { "prefix" => "Village", "name" => "Broxbourne, Hertfordshire, East of England, England, United Kingdom", "min-lat" => 51.6808751, "max-lat" => 51.7806237, "min-lon" => -0.114204, "max-lon" => 0.0145267, diff --git a/test/http/nominatim.yml b/test/http/nominatim.yml index 2fd25d184..41467721f 100644 --- a/test/http/nominatim.yml +++ b/test/http/nominatim.yml @@ -6,14 +6,14 @@ -/search?accept-language=&format=xml&q=Broxbourne&viewbox=-0.559%2C51.766%2C0.836%2C51.217: +/search?accept-language=&format=xml&extratags=1&q=Broxbourne&viewbox=-0.559%2C51.766%2C0.836%2C51.217: code: 200 body: | - - - + + + /reverse?accept-language=&lat=51.7632&lon=-0.0076&zoom=15: