]> git.openstreetmap.org Git - rails.git/commitdiff
look for extra place tags in Nominatim search results
authorSarah Hoffmann <lonvia@denofr.de>
Mon, 26 Sep 2016 10:08:42 +0000 (12:08 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Mon, 26 Sep 2016 11:00:10 +0000 (13:00 +0200)
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.

app/controllers/geocoder_controller.rb
test/controllers/geocoder_controller_test.rb
test/http/nominatim.yml

index 8afa80d7fbe593820b0f87ef7f6b92cf780f3e2b..8ad51b234d2a7343baa60e68d4e628d7b182a2f0 100644 (file)
@@ -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"]
index 7899bd982421caad81401ad8bbe4f537786ef602..57d5a10f179b1d01f3e6ce36b5f614a2521b89c5 100644 (file)
@@ -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,
index 2fd25d184d99219ce7363443813ccf907c6ce9fa..41467721f414d17b0d231445b0b7a87c816ddcc5 100644 (file)
@@ -6,14 +6,14 @@
       <place place_id='110741' osm_type='node' osm_id='18007599' place_rank='18' boundingbox="51.7216709,51.8016709,-0.0512898,0.0287102" lat='51.7616709' lon='-0.0112898' display_name='Hoddesdon, Hertfordshire, East of England, England, United Kingdom' class='place' type='town' importance='0.50547792382382' icon='http://nominatim.openstreetmap.org/images/mapicons/poi_place_town.p.20.png'/>
     </searchresults>
   
-/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: |
     <?xml version="1.0" encoding="UTF-8" ?>
     <searchresults timestamp='Sun, 01 Mar 15 20:42:25 +0000' attribution='Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright' querystring='Broxbourne' viewbox='-0.559,51.766,0.836,51.217' polygon='false' exclude_place_ids='150696,127984131,109724' more_url='http://nominatim.openstreetmap.org/search?format=xml&amp;exclude_place_ids=150696,127984131,109724&amp;viewbox=-0.559%2C51.766%2C0.836%2C51.217&amp;q=Broxbourne'>
-      <place place_id='150696' osm_type='node' osm_id='28825933' place_rank='20' boundingbox="51.7265723,51.7665723,-0.0390782,0.0009218" lat='51.7465723' lon='-0.0190782' display_name='Broxbourne, Hertfordshire, East of England, England, United Kingdom' class='place' type='suburb' importance='0.52141385408531' icon='http://nominatim.openstreetmap.org/images/mapicons/poi_place_village.p.20.png'/>
-      <place place_id='127984131' osm_type='relation' osm_id='2677978' place_rank='16' boundingbox="51.6808751,51.7806237,-0.114204,0.0145267" lat='51.73083995' lon='-0.0579457295222991' display_name='Broxbourne, Hertfordshire, East of England, England, United Kingdom' class='boundary' type='administrative' importance='0.46' icon='http://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png'/>
-      <place place_id='109724' osm_type='node' osm_id='17044599' place_rank='30' boundingbox="51.7418469,51.7518469,-0.0156773,-0.0056773" lat='51.7468469' lon='-0.0106773' display_name='Broxbourne, Stafford Drive, Broxbourne, Hertfordshire, East of England, England, United Kingdom' class='railway' type='station' importance='0.111' icon='http://nominatim.openstreetmap.org/images/mapicons/transport_train_station2.p.20.png'/>
+      <place place_id='150696' osm_type='node' osm_id='28825933' place_rank='20' boundingbox="51.7265723,51.7665723,-0.0390782,0.0009218" lat='51.7465723' lon='-0.0190782' display_name='Broxbourne, Hertfordshire, East of England, England, United Kingdom' class='place' type='suburb' importance='0.52141385408531' icon='http://nominatim.openstreetmap.org/images/mapicons/poi_place_village.p.20.png'><extratags><tag key="wikipedia" value="en:Broxbourne"/></extratags></place>
+      <place place_id='127984131' osm_type='relation' osm_id='2677978' place_rank='16' boundingbox="51.6808751,51.7806237,-0.114204,0.0145267" lat='51.73083995' lon='-0.0579457295222991' display_name='Broxbourne, Hertfordshire, East of England, England, United Kingdom' class='boundary' type='administrative' importance='0.46' icon='http://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png'><extratags><tag key="place" value="village"/></extratags></place>
+      <place place_id='109724' osm_type='node' osm_id='17044599' place_rank='30' boundingbox="51.7418469,51.7518469,-0.0156773,-0.0056773" lat='51.7468469' lon='-0.0106773' display_name='Broxbourne, Stafford Drive, Broxbourne, Hertfordshire, East of England, England, United Kingdom' class='railway' type='station' importance='0.111' icon='http://nominatim.openstreetmap.org/images/mapicons/transport_train_station2.p.20.png'><extratags></extratags></place>
     </searchresults>
   
 /reverse?accept-language=&lat=51.7632&lon=-0.0076&zoom=15: