Merge pull request #1732 from tomhughes/npemap

Remove npemap as a source for UK postcodes
This commit is contained in:
Andy Allan 2018-02-23 10:23:22 +08:00 committed by GitHub
commit 549acfa918
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 62 deletions

View file

@ -19,7 +19,6 @@ class GeocoderController < ApplicationController
if @params[:query] =~ /^\d{5}(-\d{4})?$/ if @params[:query] =~ /^\d{5}(-\d{4})?$/
@sources.push "osm_nominatim" @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 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" @sources.push "osm_nominatim"
elsif @params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i elsif @params[:query] =~ /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
@sources.push "ca_postcode" @sources.push "ca_postcode"
@ -55,32 +54,6 @@ class GeocoderController < ApplicationController
end end
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 def search_ca_postcode
# get query parameters # get query parameters
query = params[:query] query = params[:query]

View file

@ -368,7 +368,6 @@ en:
search: search:
title: title:
latlon: 'Results from <a href="https://openstreetmap.org/">Internal</a>' latlon: 'Results from <a href="https://openstreetmap.org/">Internal</a>'
uk_postcode: 'Results from <a href="http://www.npemap.org.uk/">NPEMap / FreeThe Postcode</a>'
ca_postcode: 'Results from <a href="https://geocoder.ca/">Geocoder.CA</a>' ca_postcode: 'Results from <a href="https://geocoder.ca/">Geocoder.CA</a>'
osm_nominatim: 'Results from <a href="https://nominatim.openstreetmap.org/">OpenStreetMap Nominatim</a>' osm_nominatim: 'Results from <a href="https://nominatim.openstreetmap.org/">OpenStreetMap Nominatim</a>'
geonames: 'Results from <a href="http://www.geonames.org/">GeoNames</a>' geonames: 'Results from <a href="http://www.geonames.org/">GeoNames</a>'

View file

@ -246,7 +246,6 @@ OpenStreetMap::Application.routes.draw do
# geocoder # geocoder
match "/search" => "geocoder#search", :via => :get, :as => :search match "/search" => "geocoder#search", :via => :get, :as => :search
match "/geocoder/search_latlon" => "geocoder#search_latlon", :via => :get 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_ca_postcode" => "geocoder#search_ca_postcode", :via => :get
match "/geocoder/search_osm_nominatim" => "geocoder#search_osm_nominatim", :via => :get match "/geocoder/search_osm_nominatim" => "geocoder#search_osm_nominatim", :via => :get
match "/geocoder/search_geonames" => "geocoder#search_geonames", :via => :get match "/geocoder/search_geonames" => "geocoder#search_geonames", :via => :get

View file

@ -13,10 +13,6 @@ class GeocoderControllerTest < ActionController::TestCase
{ :path => "/geocoder/search_latlon", :method => :get }, { :path => "/geocoder/search_latlon", :method => :get },
{ :controller => "geocoder", :action => "search_latlon" } { :controller => "geocoder", :action => "search_latlon" }
) )
assert_routing(
{ :path => "/geocoder/search_uk_postcode", :method => :get },
{ :controller => "geocoder", :action => "search_uk_postcode" }
)
assert_routing( assert_routing(
{ :path => "/geocoder/search_ca_postcode", :method => :get }, { :path => "/geocoder/search_ca_postcode", :method => :get },
{ :controller => "geocoder", :action => "search_ca_postcode" } { :controller => "geocoder", :action => "search_ca_postcode" }
@ -263,7 +259,7 @@ class GeocoderControllerTest < ActionController::TestCase
"CR2 6XH", "CR2 6XH",
"DN55 1PT" "DN55 1PT"
].each do |code| ].each do |code|
search_check code, %w[uk_postcode osm_nominatim] search_check code, %w[osm_nominatim]
end end
end end
@ -298,24 +294,6 @@ class GeocoderControllerTest < ActionController::TestCase
results_check_error "Longitude 180.23 out of range" results_check_error "Longitude 180.23 out of range"
end 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 # Test the Canadian postcode search
def test_search_ca_postcode def test_search_ca_postcode

View file

@ -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