From: Andy Allan Date: Fri, 23 Feb 2018 02:23:22 +0000 (+0800) Subject: Merge pull request #1732 from tomhughes/npemap X-Git-Tag: live~3661 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/549acfa918c04fa20b3386fece25ce69b3565519?hp=ff962a1e1b168dc52278a1a7fe9eb21aad3f727e Merge pull request #1732 from tomhughes/npemap Remove npemap as a source for UK postcodes --- diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index e9fa7f26a..384f2c24c 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -19,7 +19,6 @@ class GeocoderController < ApplicationController if @params[:query] =~ /^\d{5}(-\d{4})?$/ @sources.push "osm_nominatim" elsif @params[:query] =~ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i - @sources.push "uk_postcode" @sources.push "osm_nominatim" elsif @params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i @sources.push "ca_postcode" @@ -55,32 +54,6 @@ class GeocoderController < ApplicationController end end - def search_uk_postcode - # get query parameters - query = params[:query] - - # create result array - @results = [] - - # ask npemap.org.uk to do a combined npemap + freethepostcode search - response = fetch_text("http://www.npemap.org.uk/cgi/geocoder.fcgi?format=text&postcode=#{escape_query(query)}") - - # parse the response - unless response =~ /Error/ - dataline = response.split(/\n/)[1] - data = dataline.split(/,/) # easting,northing,postcode,lat,long - postcode = data[2].delete("'") - zoom = POSTCODE_ZOOM - postcode.count("#") - @results.push(:lat => data[3], :lon => data[4], :zoom => zoom, - :name => postcode) - end - - render :action => "results" - rescue StandardError => ex - @error = "Error contacting www.npemap.org.uk: #{ex}" - render :action => "error" - end - def search_ca_postcode # get query parameters query = params[:query] diff --git a/config/locales/en.yml b/config/locales/en.yml index 2412a2b9c..2550b5b96 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -368,7 +368,6 @@ en: search: title: latlon: 'Results from Internal' - uk_postcode: 'Results from NPEMap / FreeThe Postcode' ca_postcode: 'Results from Geocoder.CA' osm_nominatim: 'Results from OpenStreetMap Nominatim' geonames: 'Results from GeoNames' diff --git a/config/routes.rb b/config/routes.rb index 98bb332f2..66eda1916 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -246,7 +246,6 @@ OpenStreetMap::Application.routes.draw do # geocoder match "/search" => "geocoder#search", :via => :get, :as => :search match "/geocoder/search_latlon" => "geocoder#search_latlon", :via => :get - match "/geocoder/search_uk_postcode" => "geocoder#search_uk_postcode", :via => :get match "/geocoder/search_ca_postcode" => "geocoder#search_ca_postcode", :via => :get match "/geocoder/search_osm_nominatim" => "geocoder#search_osm_nominatim", :via => :get match "/geocoder/search_geonames" => "geocoder#search_geonames", :via => :get diff --git a/test/controllers/geocoder_controller_test.rb b/test/controllers/geocoder_controller_test.rb index 0d062cf42..e05c8d06a 100644 --- a/test/controllers/geocoder_controller_test.rb +++ b/test/controllers/geocoder_controller_test.rb @@ -13,10 +13,6 @@ class GeocoderControllerTest < ActionController::TestCase { :path => "/geocoder/search_latlon", :method => :get }, { :controller => "geocoder", :action => "search_latlon" } ) - assert_routing( - { :path => "/geocoder/search_uk_postcode", :method => :get }, - { :controller => "geocoder", :action => "search_uk_postcode" } - ) assert_routing( { :path => "/geocoder/search_ca_postcode", :method => :get }, { :controller => "geocoder", :action => "search_ca_postcode" } @@ -263,7 +259,7 @@ class GeocoderControllerTest < ActionController::TestCase "CR2 6XH", "DN55 1PT" ].each do |code| - search_check code, %w[uk_postcode osm_nominatim] + search_check code, %w[osm_nominatim] end end @@ -298,24 +294,6 @@ class GeocoderControllerTest < ActionController::TestCase results_check_error "Longitude 180.23 out of range" end - ## - # Test the UK postcode search - def test_search_uk_postcode - with_http_stubs "npemap" do - get :search_uk_postcode, :xhr => true, - :params => { :query => "CV4 7AL", :zoom => 10, - :minlon => -0.559, :minlat => 51.217, - :maxlon => 0.836, :maxlat => 51.766 } - results_check :name => "CV4 7AL", :lat => 52.381748701968, :lon => -1.56176420939232 - - get :search_uk_postcode, :xhr => true, - :params => { :query => "XX9 9XX", :zoom => 10, - :minlon => -0.559, :minlat => 51.217, - :maxlon => 0.836, :maxlat => 51.766 } - results_check - end - end - ## # Test the Canadian postcode search def test_search_ca_postcode diff --git a/test/http/npemap.yml b/test/http/npemap.yml deleted file mode 100644 index 28074d089..000000000 --- a/test/http/npemap.yml +++ /dev/null @@ -1,10 +0,0 @@ -/cgi/geocoder.fcgi?format=text&postcode=CV4%207AL: - code: 200 - body: | - # Easting,Northing,Matched Postcode,Latitude,Longitude - 429926,276058,'CV4 7AL',52.381748701968,-1.56176420939232 - -/cgi/geocoder.fcgi?format=text&postcode=XX9%209XX: - code: 200 - body: | - Error: Postcode area 'XX' not found, postcode probably invalid