Skip to content

Commit

Permalink
look for extra place tags in Nominatim search results
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lonvia committed Sep 26, 2016
1 parent e104b53 commit 5efbc8a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion app/controllers/geocoder_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def search_osm_nominatim
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"]
Expand Down Expand Up @@ -179,6 +179,11 @@ def search_osm_nominatim
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"]
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/geocoder_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def test_search_osm_nominatim
"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,
Expand Down
8 changes: 4 additions & 4 deletions test/http/nominatim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 5efbc8a

Please sign in to comment.