From 1d2581d8b9bbb8ccd43fa7e4b202b5e39b0a459f Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Sat, 10 Nov 2012 12:17:34 -0700 Subject: [PATCH 01/32] Fixing two typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4579b9b80b..c59f9f0efb 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ helpful as a reference. ## Coding style When writing code it is generally a good idea to try and match your -formatting to hat of any existing code in the same file, or to other +formatting to that of any existing code in the same file, or to other similar files if you are writing new code. Consistency of layout is far more important that the layout itself as it makes reading code much easier. @@ -107,7 +107,7 @@ and why it should be the way it is. When you submit patches, the project maintainer has to read them and understand them. This is difficult enough at the best of times, and misunderstanding patches can lead to them being more difficult to -merge. To help wit this, when submitting you should: +merge. To help with this, when submitting you should: * Split up large patches into smaller units of functionality. * Keep your commit messages relevant to the changes in each individual From 39835363482fff6b8873d9f042f6b7590958bbfc Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Sat, 10 Nov 2012 21:59:12 -0700 Subject: [PATCH 02/32] Fixing typo and outdated information. Changing 'posstible' to 'possible' in example.application.yml. Updating wiki link and PostgreSQL version recommendation in example.database.yml (8.3 will be EOLed in Feb 2013). --- config/example.application.yml | 2 +- config/example.database.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/example.application.yml b/config/example.application.yml index d3af9705d4..249e447735 100644 --- a/config/example.application.yml +++ b/config/example.application.yml @@ -11,7 +11,7 @@ defaults: &defaults email_return_path: "bounces@openstreetmap.org" # API version api_version: "0.6" - # Application status - posstible values are: + # Application status - possible values are: # :online - online and operating normally # :api_readonly - site online but API in read-only mode # :api_offline - site online but API offline diff --git a/config/example.database.yml b/config/example.database.yml index 3908e51e53..e075d7f8df 100644 --- a/config/example.database.yml +++ b/config/example.database.yml @@ -1,5 +1,5 @@ -# Postgresql version 8.3 recommended. -# See http://wiki.openstreetmap.org/wiki/OSM_Protocol_Version_0.6/postgres for detailed setup instructions. +# Using a recent release (8.3 or higher) of PostgreSQL (http://postgresql.org/) is recommended. +# See http://wiki.openstreetmap.org/wiki/The_Rails_Port#PostgreSQL_setup for detailed setup instructions. # development: adapter: postgresql From 1a87fae6e4e15764677cc20ab0a18474dcd54f16 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Sat, 10 Nov 2012 22:29:28 -0700 Subject: [PATCH 03/32] Adding simple yml file for Travis Continuous Integration --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..884fc6a2a0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: ruby +rvm: + - "1.8.7" + - "1.9.2" + - "1.9.3" From 8fb8dc204ff2a8c65e9a86b734db7b8f091322ad Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 09:26:02 -0700 Subject: [PATCH 04/32] First draft of Travis CI YAML file --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 884fc6a2a0..ffd9282069 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,5 @@ rvm: - "1.8.7" - "1.9.2" - "1.9.3" +before_script: + - psql -c 'create database rails_port_test;' -U postgres \ No newline at end of file From 5a8bb4c7f40eaafd008c395372351b83e43a811c Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 10:18:17 -0700 Subject: [PATCH 05/32] Adding steps to before_script --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ffd9282069..65e42c9f62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,7 @@ rvm: - "1.9.2" - "1.9.3" before_script: - - psql -c 'create database rails_port_test;' -U postgres \ No newline at end of file + - psql -c 'create database rails_port_test;' -U postgres + - psql -c 'createuser osm_test -s;' -U postgres + - cp config/example.application.yml config/application.yml + - cp config/example.database.yml config/database.yml \ No newline at end of file From 444711428f1fea112272df0d962bd5ed69954d33 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 10:26:45 -0700 Subject: [PATCH 06/32] Create user correctly --- .travis.yml | 8 ++++---- config/example.database.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 65e42c9f62..dbe6412ffe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: ruby rvm: - - "1.8.7" - - "1.9.2" +# - "1.8.7" +# - "1.9.2" - "1.9.3" before_script: - psql -c 'create database rails_port_test;' -U postgres - - psql -c 'createuser osm_test -s;' -U postgres + - psql -c 'create role osm_test with superuser password osm_test;' -U postgres - cp config/example.application.yml config/application.yml - - cp config/example.database.yml config/database.yml \ No newline at end of file + - cp config/example.database.yml config/database.yml diff --git a/config/example.database.yml b/config/example.database.yml index e075d7f8df..2e38511a53 100644 --- a/config/example.database.yml +++ b/config/example.database.yml @@ -15,8 +15,8 @@ development: test: adapter: postgresql database: osm_test -# username: osm_test -# password: osm_test + username: osm_test + password: osm_test host: localhost encoding: utf8 From 7c0c9706e7320cea93331a4252d0a5acad5d4bc4 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 10:32:02 -0700 Subject: [PATCH 07/32] Create user correctly, continued --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dbe6412ffe..64e1f31155 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,6 @@ rvm: - "1.9.3" before_script: - psql -c 'create database rails_port_test;' -U postgres - - psql -c 'create role osm_test with superuser password osm_test;' -U postgres + - psql -c "create role osm_test with superuser password 'osm_test';" -U postgres - cp config/example.application.yml config/application.yml - cp config/example.database.yml config/database.yml From 15800679d3c4dad2da8f27ac86e85387cf8f23c1 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 10:37:29 -0700 Subject: [PATCH 08/32] Create user correctly, continued --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 64e1f31155..e1604a5e17 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,6 @@ rvm: - "1.9.3" before_script: - psql -c 'create database rails_port_test;' -U postgres - - psql -c "create role osm_test with superuser password 'osm_test';" -U postgres + - psql -c "create user osm_test with superuser password 'osm_test';" -U postgres - cp config/example.application.yml config/application.yml - cp config/example.database.yml config/database.yml From ca40f8eee6a7df124521b01304e330f60bf3b010 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 10:41:17 -0700 Subject: [PATCH 09/32] Create user correctly, continued --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e1604a5e17..ebfc518d7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,6 @@ rvm: before_script: - psql -c 'create database rails_port_test;' -U postgres - psql -c "create user osm_test with superuser password 'osm_test';" -U postgres + - psql -d osm_test -c 'CREATE EXTENSION btree_gist;' -U osm_test - cp config/example.application.yml config/application.yml - cp config/example.database.yml config/database.yml From 82bea989984911ee3f0607d4d887fdb09e6c6ed9 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 10:45:30 -0700 Subject: [PATCH 10/32] Create user correctly, continued --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ebfc518d7d..90c6265c27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ rvm: # - "1.9.2" - "1.9.3" before_script: - - psql -c 'create database rails_port_test;' -U postgres + - psql -c 'create database osm_test;' -U postgres - psql -c "create user osm_test with superuser password 'osm_test';" -U postgres - psql -d osm_test -c 'CREATE EXTENSION btree_gist;' -U osm_test - cp config/example.application.yml config/application.yml From cdff6435b03b0c529c568a44deed00df3ce285af Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 10:54:49 -0700 Subject: [PATCH 11/32] Run the db migration --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 90c6265c27..0c4b3d4bb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,3 +9,4 @@ before_script: - psql -d osm_test -c 'CREATE EXTENSION btree_gist;' -U osm_test - cp config/example.application.yml config/application.yml - cp config/example.database.yml config/database.yml + - rake db:migrate From 33f366b577c4e76caac644a86da00cf198b69286 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 11:57:30 -0700 Subject: [PATCH 12/32] Seems to work; adding rubies and status badge --- .travis.yml | 6 +++--- README.md | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c4b3d4bb4..0dbfbd9c79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: ruby rvm: -# - "1.8.7" -# - "1.9.2" - - "1.9.3" + - '1.8.7' + - '1.9.2' + - '1.9.3' before_script: - psql -c 'create database osm_test;' -U postgres - psql -c "create user osm_test with superuser password 'osm_test';" -U postgres diff --git a/README.md b/README.md index c59f9f0efb..bc8b025365 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/erictheise/openstreetmap-website.png)](https://travis-ci.org/erictheise/openstreetmap-website) + # Description This is the Rails port, the [Ruby on Rails](http://rubyonrails.org/) From aa74165e18136566dc82fc32f705c8e32eac65d0 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 12:52:46 -0700 Subject: [PATCH 13/32] Trying to install the quadtile functions --- .travis.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0dbfbd9c79..241982e515 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,17 @@ language: ruby rvm: - - '1.8.7' - - '1.9.2' +# - '1.9.2' - '1.9.3' +before_install: + - cd db/functions; make libpgosm.so ; cd ../..; before_script: - psql -c 'create database osm_test;' -U postgres - psql -c "create user osm_test with superuser password 'osm_test';" -U postgres - psql -d osm_test -c 'CREATE EXTENSION btree_gist;' -U osm_test +# - psql -d osm_test -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '//openstreetmap-website/db/functions/libpgosm', 'maptile_for_point' LANGUAGE C STRICT;" +# - psql -d osm_test -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '//openstreetmap-website/db/functions/libpgosm', 'maptile_for_point' LANGUAGE C STRICT;" +# - psql -d osm_test -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '//openstreetmap-website/rails-port/db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT;" +# - psql -d osm_test -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '//openstreetmap-website/db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT;" - cp config/example.application.yml config/application.yml - cp config/example.database.yml config/database.yml - rake db:migrate From dc9f22e48721ff7c03c7909f83ba6790eaa56ec2 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 14:11:18 -0700 Subject: [PATCH 14/32] Trying to install the quadtile functions, continued --- .travis.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 241982e515..14e50ca8f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,15 +3,13 @@ rvm: # - '1.9.2' - '1.9.3' before_install: - - cd db/functions; make libpgosm.so ; cd ../..; + - cd db/functions; make libpgosm.so; cd ../..; before_script: - psql -c 'create database osm_test;' -U postgres - psql -c "create user osm_test with superuser password 'osm_test';" -U postgres - psql -d osm_test -c 'CREATE EXTENSION btree_gist;' -U osm_test -# - psql -d osm_test -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '//openstreetmap-website/db/functions/libpgosm', 'maptile_for_point' LANGUAGE C STRICT;" -# - psql -d osm_test -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '//openstreetmap-website/db/functions/libpgosm', 'maptile_for_point' LANGUAGE C STRICT;" -# - psql -d osm_test -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '//openstreetmap-website/rails-port/db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT;" -# - psql -d osm_test -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '//openstreetmap-website/db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT;" + - psql -d osm_test -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS 'db/functions/libpgosm', 'maptile_for_point' LANGUAGE C STRICT;" + - psql -d osm_test -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS 'db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT;" - cp config/example.application.yml config/application.yml - cp config/example.database.yml config/database.yml - rake db:migrate From fd39a0e4b034ac1a257b0f770cb5c30fb77719a2 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 14:21:46 -0700 Subject: [PATCH 15/32] Trying to install the quadtile functions, continued --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 14e50ca8f5..8b19f586b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,8 @@ before_script: - psql -c 'create database osm_test;' -U postgres - psql -c "create user osm_test with superuser password 'osm_test';" -U postgres - psql -d osm_test -c 'CREATE EXTENSION btree_gist;' -U osm_test - - psql -d osm_test -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS 'db/functions/libpgosm', 'maptile_for_point' LANGUAGE C STRICT;" - - psql -d osm_test -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS 'db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT;" + - psql -d osm_test -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '`pwd`/db/functions/libpgosm', 'maptile_for_point' LANGUAGE C STRICT;" -U osm_test + - psql -d osm_test -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '`pwd`/db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT;" -U osm_test - cp config/example.application.yml config/application.yml - cp config/example.database.yml config/database.yml - rake db:migrate From b47846c588dda96ec2c25d9350d83c7b1d883de6 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 12 Nov 2012 20:15:56 -0700 Subject: [PATCH 16/32] Re-enabling builds for 1.8.7 & 1.9.2 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8b19f586b1..d8ea08c3aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: ruby rvm: -# - '1.9.2' + - '1.8.7' + - '1.9.2' - '1.9.3' before_install: - cd db/functions; make libpgosm.so; cd ../..; From bd90a51b12b96e9de8785a023daaeaf9980c5047 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 25 Feb 2013 13:20:54 -0800 Subject: [PATCH 17/32] adding tests for existing behavior of geocoder search --- test/functional/geocoder_controller_test.rb | 87 +++++++++++++++------ 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index b678125d2e..21988d7015 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -6,53 +6,92 @@ class GeocoderControllerTest < ActionController::TestCase # test all routes which lead to this controller def test_routes assert_routing( - { :path => "/geocoder/search", :method => :post }, - { :controller => "geocoder", :action => "search" } + { :path => '/geocoder/search', :method => :post }, + { :controller => 'geocoder', :action => 'search' } ) assert_routing( - { :path => "/geocoder/search_latlon", :method => :get }, - { :controller => "geocoder", :action => "search_latlon" } + { :path => '/geocoder/search_latlon', :method => :get }, + { :controller => 'geocoder', :action => 'search_latlon' } ) assert_routing( - { :path => "/geocoder/search_us_postcode", :method => :get }, - { :controller => "geocoder", :action => "search_us_postcode" } + { :path => '/geocoder/search_us_postcode', :method => :get }, + { :controller => 'geocoder', :action => 'search_us_postcode' } ) assert_routing( - { :path => "/geocoder/search_uk_postcode", :method => :get }, - { :controller => "geocoder", :action => "search_uk_postcode" } + { :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" } + { :path => '/geocoder/search_ca_postcode', :method => :get }, + { :controller => 'geocoder', :action => 'search_ca_postcode' } ) assert_routing( - { :path => "/geocoder/search_osm_namefinder", :method => :get }, - { :controller => "geocoder", :action => "search_osm_namefinder" } + { :path => '/geocoder/search_osm_namefinder', :method => :get }, + { :controller => 'geocoder', :action => 'search_osm_namefinder' } ) assert_routing( - { :path => "/geocoder/search_osm_nominatim", :method => :get }, - { :controller => "geocoder", :action => "search_osm_nominatim" } + { :path => '/geocoder/search_osm_nominatim', :method => :get }, + { :controller => 'geocoder', :action => 'search_osm_nominatim' } ) assert_routing( - { :path => "/geocoder/search_geonames", :method => :get }, - { :controller => "geocoder", :action => "search_geonames" } + { :path => '/geocoder/search_geonames', :method => :get }, + { :controller => 'geocoder', :action => 'search_geonames' } ) assert_routing( - { :path => "/geocoder/description", :method => :post }, - { :controller => "geocoder", :action => "description" } + { :path => '/geocoder/description', :method => :post }, + { :controller => 'geocoder', :action => 'description' } ) assert_routing( - { :path => "/geocoder/description_osm_namefinder", :method => :get }, - { :controller => "geocoder", :action => "description_osm_namefinder" } + { :path => '/geocoder/description_osm_namefinder', :method => :get }, + { :controller => 'geocoder', :action => 'description_osm_namefinder' } ) assert_routing( - { :path => "/geocoder/description_osm_nominatim", :method => :get }, - { :controller => "geocoder", :action => "description_osm_nominatim" } + { :path => '/geocoder/description_osm_nominatim', :method => :get }, + { :controller => 'geocoder', :action => 'description_osm_nominatim' } ) assert_routing( - { :path => "/geocoder/description_geonames", :method => :get }, - { :controller => "geocoder", :action => "description_geonames" } + { :path => '/geocoder/description_geonames', :method => :get }, + { :controller => 'geocoder', :action => 'description_geonames' } ) end + + ## + # test the regular expressions that split search queries into 'latlon', 'us_postcode', and the like + def test_identify_latlon_degdec + post :search, :query => '10.354, 010.374' + assert_response :success + assert_not_nil assigns(:sources) + assert_equal ['latlon'], assigns(:sources) + end + + def test_identify_us_postcode + ['12345', '12345-6789'].each do |code| + post :search, query: code + assert_response :success + assert_equal ['us_postcode', 'osm_nominatim'], assigns(:sources) + end + end + + def test_identify_uk_postcode + # examples from http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom + ['EC1A 1BB', 'W1A 1HQ', 'M1 1AA', 'B33 8TH', 'CR2 6XH', 'DN55 1PT'].each do |code| + post :search, query: code + assert_response :success + assert_equal ['uk_postcode', 'osm_nominatim'], assigns(:sources) + end + end + + def test_identify_ca_postcode + post :search, query: 'A1B 2C3' + assert_response :success + assert_equal ['ca_postcode', 'osm_nominatim'], assigns(:sources) + end + + def test_identify_fall_through_no_geonames + post :search, query: 'foo bar baz' + assert_response :success + assert_equal ['osm_nominatim'], assigns(:sources) + end + end From ae503fce733f8d55563eb9c84054bb295da8dd84 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 25 Feb 2013 14:29:02 -0800 Subject: [PATCH 18/32] tests and controller work to identify two general cases of degree/minute/second latlons; no calcs --- app/controllers/geocoder_controller.rb | 5 +++ test/functional/geocoder_controller_test.rb | 36 ++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index ced95dce63..9995440803 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -1,3 +1,4 @@ +# coding: utf-8 class GeocoderController < ApplicationController require 'uri' require 'net/http' @@ -15,6 +16,10 @@ def search if @query.match(/^[+-]?\d+(\.\d*)?\s*[\s,]\s*[+-]?\d+(\.\d*)?$/) @sources.push "latlon" + elsif @query.match(/^[NS]\s?(\d{1,3})°?\s?(\d{1,2})'?\s?(\d{1,3}\.\d*)?"?\W*[EW]\s?(\d{1,3})°?\s?(\d{1,2})'?\s?(\d{1,3}\.\d*)?"?$/) # [NSEW] degrees minutes seconds + @sources.push "latlon" + elsif @query.match(/^(\d{1,3})°?\s?(\d{1,2})'?\s?(\d{1,3}\.\d*)?"\s?[NS]\W*(\d{1,3})°?\s?(\d{1,2})'?\s?(\d{1,3}\.\d*)?"?\s?[EW]$/) # degrees minutes seconds [NSEW] + @sources.push "latlon" elsif @query.match(/^\d{5}(-\d{4})?$/) @sources.push "us_postcode" @sources.push "osm_nominatim" diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index 21988d7015..57525868c3 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -1,3 +1,4 @@ +# coding: utf-8 require File.dirname(__FILE__) + '/../test_helper' require 'geocoder_controller' @@ -58,11 +59,38 @@ def test_routes ## # test the regular expressions that split search queries into 'latlon', 'us_postcode', and the like + + # latlon examples/motivation from https://trac.openstreetmap.org/ticket/4730 & https://trac.openstreetmap.org/ticket/4748 def test_identify_latlon_degdec - post :search, :query => '10.354, 010.374' - assert_response :success - assert_not_nil assigns(:sources) - assert_equal ['latlon'], assigns(:sources) + ['50.06773 14.37742', '50.06773, 14.37742', '+50.06773 +14.37742', '+50.06773, +14.37742'].each do |code| + post :search, :query => code + assert_response :success + assert_equal ['latlon'], assigns(:sources) + end + end + +=begin + def test_identify_latlon_mindec + ['N 50° 04.064 E 014° 22.645', "N 50° 04.064' E 014° 22.645", "N 50° 04.064', E 014° 22.645'", 'N50° 04.064 E14° 22.645', 'N 50 04.064 E 014 22.645', 'N50 4.064 E14 22.645'].each do |code| + post :search, :query => code + assert_response :success + assert_equal ['latlon'], assigns(:sources) + end + end +=end + + def test_identify_latlon_dms + [ + "N 50° 4' 03.828\" E 14° 22' 38.712\"", + "N 50° 4' 03.828\", E 14° 22' 38.712\"", + 'N50 4 03.828 E14 22 38.712', + 'N50 4 03.828, E14 22 38.712', + "50°4'3.828\"N 14°22'38.712\"E" + ].each do |code| + post :search, :query => code + assert_response :success + assert_equal ['latlon'], assigns(:sources) + end end def test_identify_us_postcode From 82574df72bf87223c0f27c0a67f869aa42e2db4b Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 25 Feb 2013 14:38:21 -0800 Subject: [PATCH 19/32] use * instead of ? for whitespace tests --- app/controllers/geocoder_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 9995440803..bbeaac8aaf 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -16,9 +16,9 @@ def search if @query.match(/^[+-]?\d+(\.\d*)?\s*[\s,]\s*[+-]?\d+(\.\d*)?$/) @sources.push "latlon" - elsif @query.match(/^[NS]\s?(\d{1,3})°?\s?(\d{1,2})'?\s?(\d{1,3}\.\d*)?"?\W*[EW]\s?(\d{1,3})°?\s?(\d{1,2})'?\s?(\d{1,3}\.\d*)?"?$/) # [NSEW] degrees minutes seconds + elsif @query.match(/^[NS]\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\W*[EW]\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?$/) # [NSEW] degrees minutes seconds @sources.push "latlon" - elsif @query.match(/^(\d{1,3})°?\s?(\d{1,2})'?\s?(\d{1,3}\.\d*)?"\s?[NS]\W*(\d{1,3})°?\s?(\d{1,2})'?\s?(\d{1,3}\.\d*)?"?\s?[EW]$/) # degrees minutes seconds [NSEW] + elsif @query.match(/^(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"\s*[NS]\W*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\s*[EW]$/) # degrees minutes seconds [NSEW] @sources.push "latlon" elsif @query.match(/^\d{5}(-\d{4})?$/) @sources.push "us_postcode" From 624ce8adb8a8c0b83080f0052335b28c21070df5 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Mon, 25 Feb 2013 23:59:52 -0800 Subject: [PATCH 20/32] day's work; still need to test +/- NSEW --- app/controllers/geocoder_controller.rb | 9 +++++++-- app/helpers/geocoder_helper.rb | 19 +++++++++++++++++++ test/functional/geocoder_controller_test.rb | 18 ++++++++++++++---- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index bbeaac8aaf..6d68105107 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -16,9 +16,14 @@ def search if @query.match(/^[+-]?\d+(\.\d*)?\s*[\s,]\s*[+-]?\d+(\.\d*)?$/) @sources.push "latlon" - elsif @query.match(/^[NS]\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\W*[EW]\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?$/) # [NSEW] degrees minutes seconds + elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.\d*)?'?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.\d*)?'?$/).try(:captures) # [NSEW] degrees, decimal minutes + @query = view_context.ddm_to_decdeg(latlon) @sources.push "latlon" - elsif @query.match(/^(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"\s*[NS]\W*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\s*[EW]$/) # degrees minutes seconds [NSEW] + elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds + @query = view_context.dms_to_decdeg(latlon) + @sources.push "latlon" + elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] + @query = view_context.dms_to_decdeg(latlon) @sources.push "latlon" elsif @query.match(/^\d{5}(-\d{4})?$/) @sources.push "us_postcode" diff --git a/app/helpers/geocoder_helper.rb b/app/helpers/geocoder_helper.rb index f5519ddc3f..fa5b7e6858 100644 --- a/app/helpers/geocoder_helper.rb +++ b/app/helpers/geocoder_helper.rb @@ -40,4 +40,23 @@ def describe_location(lat, lon, zoom = nil, language = nil) "#{number_with_precision(lat, :precision => 3)}, #{number_with_precision(lon, :precision => 3)}" end end + + def ddm_to_decdeg(captures) + captures[0].downcase != 's' ? lat = captures[1].to_f + captures[2].to_f/60 : lat = -(captures[1].to_f + captures[2].to_f/60) + captures[3].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f/60 : lat = -(captures[4].to_f + captures[5].to_f/60) + return "#{number_with_precision(lat, :precision => 5)}, #{number_with_precision(lon, :precision => 5)}" + end + + def dms_to_decdeg(captures) + begin + Float(captures[0]) + captures[3].downcase != 's' ? lat = captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60 : lat = -(captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60) + captures[7].downcase != 'w' ? lon = captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60 : lat = -(captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60) + rescue + captures[0].downcase != 's' ? lat = captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60 : lat = -(captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60) + captures[4].downcase != 'w' ? lon = captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60 : lat = -(captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60) + end + return "#{number_with_precision(lat, :precision => 5)}, #{number_with_precision(lon, :precision => 5)}" + end + end diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index 57525868c3..e69ee046b2 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -66,20 +66,29 @@ def test_identify_latlon_degdec post :search, :query => code assert_response :success assert_equal ['latlon'], assigns(:sources) + assert_equal code, assigns(:query) end end -=begin - def test_identify_latlon_mindec - ['N 50° 04.064 E 014° 22.645', "N 50° 04.064' E 014° 22.645", "N 50° 04.064', E 014° 22.645'", 'N50° 04.064 E14° 22.645', 'N 50 04.064 E 014 22.645', 'N50 4.064 E14 22.645'].each do |code| + def test_identify_latlon_ddm + target = '50.06773, 14.37742' + [ + 'N 50° 04.064 E 014° 22.645', + "N 50° 04.064' E 014° 22.645", + "N 50° 04.064', E 014° 22.645'", + 'N50° 04.064 E14° 22.645', + 'N 50 04.064 E 014 22.645', + 'N50 4.064 E14 22.645' + ].each do |code| post :search, :query => code assert_response :success assert_equal ['latlon'], assigns(:sources) + assert_equal target, assigns(:query) end end -=end def test_identify_latlon_dms + target = '50.06773, 14.37742' [ "N 50° 4' 03.828\" E 14° 22' 38.712\"", "N 50° 4' 03.828\", E 14° 22' 38.712\"", @@ -90,6 +99,7 @@ def test_identify_latlon_dms post :search, :query => code assert_response :success assert_equal ['latlon'], assigns(:sources) + assert_equal target, assigns(:query) end end From 382ebb71dc7f5067434d50dbf098707e7e702f27 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Tue, 26 Feb 2013 12:17:03 -0800 Subject: [PATCH 21/32] found some bugs, more tests, moved tests to before_filter, verified conversions --- app/controllers/geocoder_controller.rb | 23 +++++---- app/helpers/geocoder_helper.rb | 6 +-- test/functional/geocoder_controller_test.rb | 56 +++++++++++++++++++++ 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 6d68105107..acfc3a1320 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -6,6 +6,7 @@ class GeocoderController < ApplicationController before_filter :authorize_web before_filter :set_locale + before_filter :convert_latlon def search @query = params[:query] @@ -16,15 +17,6 @@ def search if @query.match(/^[+-]?\d+(\.\d*)?\s*[\s,]\s*[+-]?\d+(\.\d*)?$/) @sources.push "latlon" - elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.\d*)?'?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.\d*)?'?$/).try(:captures) # [NSEW] degrees, decimal minutes - @query = view_context.ddm_to_decdeg(latlon) - @sources.push "latlon" - elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds - @query = view_context.dms_to_decdeg(latlon) - @sources.push "latlon" - elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] - @query = view_context.dms_to_decdeg(latlon) - @sources.push "latlon" elsif @query.match(/^\d{5}(-\d{4})?$/) @sources.push "us_postcode" @sources.push "osm_nominatim" @@ -322,4 +314,17 @@ def count_results(results) def escape_query(query) return URI.escape(query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]", false, 'N')) end + + def convert_latlon + @query = params[:query] + if latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.\d*)?'?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.\d*)?'?$/).try(:captures) # [NSEW] degrees, decimal minutes + params[:query] = view_context.ddm_to_decdeg(latlon) + elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds + params[:query] = view_context.dms_to_decdeg(latlon) + elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] + params[:query] = view_context.dms_to_decdeg(latlon) + else + end + end + end diff --git a/app/helpers/geocoder_helper.rb b/app/helpers/geocoder_helper.rb index fa5b7e6858..78d8513ff8 100644 --- a/app/helpers/geocoder_helper.rb +++ b/app/helpers/geocoder_helper.rb @@ -43,7 +43,7 @@ def describe_location(lat, lon, zoom = nil, language = nil) def ddm_to_decdeg(captures) captures[0].downcase != 's' ? lat = captures[1].to_f + captures[2].to_f/60 : lat = -(captures[1].to_f + captures[2].to_f/60) - captures[3].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f/60 : lat = -(captures[4].to_f + captures[5].to_f/60) + captures[3].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f/60 : lon = -(captures[4].to_f + captures[5].to_f/60) return "#{number_with_precision(lat, :precision => 5)}, #{number_with_precision(lon, :precision => 5)}" end @@ -51,10 +51,10 @@ def dms_to_decdeg(captures) begin Float(captures[0]) captures[3].downcase != 's' ? lat = captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60 : lat = -(captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60) - captures[7].downcase != 'w' ? lon = captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60 : lat = -(captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60) + captures[7].downcase != 'w' ? lon = captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60 : lon = -(captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60) rescue captures[0].downcase != 's' ? lat = captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60 : lat = -(captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60) - captures[4].downcase != 'w' ? lon = captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60 : lat = -(captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60) + captures[4].downcase != 'w' ? lon = captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60 : lon = -(captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60) end return "#{number_with_precision(lat, :precision => 5)}, #{number_with_precision(lon, :precision => 5)}" end diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index e69ee046b2..3d8375650a 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -132,4 +132,60 @@ def test_identify_fall_through_no_geonames assert_equal ['osm_nominatim'], assigns(:sources) end + def test_ne + target = '50.06773, 14.37742' + [ + "N 50° 04.064', E 014° 22.645'", + "N 50° 4' 03.828\", E 14° 22' 38.712\"", + "50°4'3.828\"N 14°22'38.712\"E" + ].each do |code| + post :search, :query => code + assert_response :success + assert_equal ['latlon'], assigns(:sources) + assert_equal target, assigns(:query) + end + end + + def test_nw + target = '50.06773, -14.37742' + [ + "N 50° 04.064', W 014° 22.645'", + "N 50° 4' 03.828\", W 14° 22' 38.712\"", + "50°4'3.828\"N 14°22'38.712\"W" + ].each do |code| + post :search, :query => code + assert_response :success + assert_equal ['latlon'], assigns(:sources) + assert_equal target, assigns(:query) + end + end + + def test_se + target = '-50.06773, 14.37742' + [ + "S 50° 04.064', E 014° 22.645'", + "S 50° 4' 03.828\", E 14° 22' 38.712\"", + "50°4'3.828\"S 14°22'38.712\"E" + ].each do |code| + post :search, :query => code + assert_response :success + assert_equal ['latlon'], assigns(:sources) + assert_equal target, assigns(:query) + end + end + + def test_sw + target = '-50.06773, -14.37742' + [ + "S 50° 04.064', W 014° 22.645'", + "S 50° 4' 03.828\", W 14° 22' 38.712\"", + "50°4'3.828\"S 14°22'38.712\"W" + ].each do |code| + post :search, :query => code + assert_response :success + assert_equal ['latlon'], assigns(:sources) + assert_equal target, assigns(:query) + end + end + end From d5bfc93c388c57e433f017695a3aee5ebe88e7a2 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Tue, 26 Feb 2013 13:06:20 -0800 Subject: [PATCH 22/32] should be able to cut and paste out of wikipedia; adding single prime alongside apostrophe, testing --- app/controllers/geocoder_controller.rb | 15 +++++++++------ app/helpers/geocoder_helper.rb | 10 ++++++++-- test/functional/geocoder_controller_test.rb | 15 ++++++++++----- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index acfc3a1320..35a0e4db75 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -317,13 +317,16 @@ def escape_query(query) def convert_latlon @query = params[:query] - if latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.\d*)?'?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.\d*)?'?$/).try(:captures) # [NSEW] degrees, decimal minutes - params[:query] = view_context.ddm_to_decdeg(latlon) - elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds - params[:query] = view_context.dms_to_decdeg(latlon) - elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})'?\s*(\d{1,3}\.\d*)?"?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] - params[:query] = view_context.dms_to_decdeg(latlon) + if latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes + params[:query] = view_context.ddm_to_decdeg(latlon) + elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] + params[:query] = view_context.ddm_to_decdeg(latlon) + elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?"?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?"?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds + params[:query] = view_context.dms_to_decdeg(latlon) + elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?"\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?"?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] + params[:query] = view_context.dms_to_decdeg(latlon) else + return end end diff --git a/app/helpers/geocoder_helper.rb b/app/helpers/geocoder_helper.rb index 78d8513ff8..1b40895d47 100644 --- a/app/helpers/geocoder_helper.rb +++ b/app/helpers/geocoder_helper.rb @@ -42,8 +42,14 @@ def describe_location(lat, lon, zoom = nil, language = nil) end def ddm_to_decdeg(captures) - captures[0].downcase != 's' ? lat = captures[1].to_f + captures[2].to_f/60 : lat = -(captures[1].to_f + captures[2].to_f/60) - captures[3].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f/60 : lon = -(captures[4].to_f + captures[5].to_f/60) + begin + Float(captures[0]) + captures[2].downcase != 's' ? lat = captures[0].to_f + captures[1].to_f/60 : lat = -(captures[0].to_f + captures[1].to_f/60) + captures[5].downcase != 'w' ? lon = captures[3].to_f + captures[4].to_f/60 : lon = -(captures[3].to_f + captures[4].to_f/60) + rescue + captures[0].downcase != 's' ? lat = captures[1].to_f + captures[2].to_f/60 : lat = -(captures[1].to_f + captures[2].to_f/60) + captures[3].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f/60 : lon = -(captures[4].to_f + captures[5].to_f/60) + end return "#{number_with_precision(lat, :precision => 5)}, #{number_with_precision(lon, :precision => 5)}" end diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index 3d8375650a..90ea05e6e0 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -78,7 +78,8 @@ def test_identify_latlon_ddm "N 50° 04.064', E 014° 22.645'", 'N50° 04.064 E14° 22.645', 'N 50 04.064 E 014 22.645', - 'N50 4.064 E14 22.645' + 'N50 4.064 E14 22.645', + "50° 04.064' N, 014° 22.645' E" ].each do |code| post :search, :query => code assert_response :success @@ -137,7 +138,8 @@ def test_ne [ "N 50° 04.064', E 014° 22.645'", "N 50° 4' 03.828\", E 14° 22' 38.712\"", - "50°4'3.828\"N 14°22'38.712\"E" + "50°4'3.828\"N 14°22'38.712\"E", + "50° 04.064' N, 014° 22.645' E" ].each do |code| post :search, :query => code assert_response :success @@ -151,7 +153,8 @@ def test_nw [ "N 50° 04.064', W 014° 22.645'", "N 50° 4' 03.828\", W 14° 22' 38.712\"", - "50°4'3.828\"N 14°22'38.712\"W" + "50°4'3.828\"N 14°22'38.712\"W", + "50° 04.064' N, 014° 22.645' W" ].each do |code| post :search, :query => code assert_response :success @@ -165,7 +168,8 @@ def test_se [ "S 50° 04.064', E 014° 22.645'", "S 50° 4' 03.828\", E 14° 22' 38.712\"", - "50°4'3.828\"S 14°22'38.712\"E" + "50°4'3.828\"S 14°22'38.712\"E", + "50° 04.064' S, 014° 22.645' E" ].each do |code| post :search, :query => code assert_response :success @@ -179,7 +183,8 @@ def test_sw [ "S 50° 04.064', W 014° 22.645'", "S 50° 4' 03.828\", W 14° 22' 38.712\"", - "50°4'3.828\"S 14°22'38.712\"W" + "50°4'3.828\"S 14°22'38.712\"W", + "50° 04.064' S, 014° 22.645' W" ].each do |code| post :search, :query => code assert_response :success From 8af648312252d9784d1e44c942828747e1e3b53f Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Tue, 26 Feb 2013 13:18:34 -0800 Subject: [PATCH 23/32] adding double prime alongside quotation --- app/controllers/geocoder_controller.rb | 4 ++-- test/functional/geocoder_controller_test.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 35a0e4db75..80bebbc15b 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -321,9 +321,9 @@ def convert_latlon params[:query] = view_context.ddm_to_decdeg(latlon) elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] params[:query] = view_context.ddm_to_decdeg(latlon) - elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?"?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?"?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds + elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds params[:query] = view_context.dms_to_decdeg(latlon) - elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?"\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?"?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] + elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] params[:query] = view_context.dms_to_decdeg(latlon) else return diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index 90ea05e6e0..680b0807e1 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -193,4 +193,16 @@ def test_sw end end + def test_primes_and_double_primes + target = '50.06773, -14.37742' + [ + "N 50° 4′ 03.828″, W 14° 22′ 38.712″" + ].each do |code| + post :search, :query => code + assert_response :success + assert_equal ['latlon'], assigns(:sources) + assert_equal target, assigns(:query) + end + end + end From a4499b9042b01df0d00d2e9a7c32555f63ce6966 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Tue, 26 Feb 2013 23:58:02 -0800 Subject: [PATCH 24/32] conforming this branch to upstream/master ; getting rid of extraneous local changes --- .travis.yml | 16 ---------------- README.md | 2 -- 2 files changed, 18 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d8ea08c3aa..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: ruby -rvm: - - '1.8.7' - - '1.9.2' - - '1.9.3' -before_install: - - cd db/functions; make libpgosm.so; cd ../..; -before_script: - - psql -c 'create database osm_test;' -U postgres - - psql -c "create user osm_test with superuser password 'osm_test';" -U postgres - - psql -d osm_test -c 'CREATE EXTENSION btree_gist;' -U osm_test - - psql -d osm_test -c "CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 AS '`pwd`/db/functions/libpgosm', 'maptile_for_point' LANGUAGE C STRICT;" -U osm_test - - psql -d osm_test -c "CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 AS '`pwd`/db/functions/libpgosm', 'tile_for_point' LANGUAGE C STRICT;" -U osm_test - - cp config/example.application.yml config/application.yml - - cp config/example.database.yml config/database.yml - - rake db:migrate diff --git a/README.md b/README.md index bc8b025365..c59f9f0efb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -[![Build Status](https://travis-ci.org/erictheise/openstreetmap-website.png)](https://travis-ci.org/erictheise/openstreetmap-website) - # Description This is the Rails port, the [Ruby on Rails](http://rubyonrails.org/) From 79e1f3fe04eedbdc7363f5ca34b732ef5204c72c Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Wed, 27 Feb 2013 00:02:52 -0800 Subject: [PATCH 25/32] conforming this branch to upstream/master ; getting rid of extraneous local changes --- config/example.database.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/example.database.yml b/config/example.database.yml index 2e38511a53..3908e51e53 100644 --- a/config/example.database.yml +++ b/config/example.database.yml @@ -1,5 +1,5 @@ -# Using a recent release (8.3 or higher) of PostgreSQL (http://postgresql.org/) is recommended. -# See http://wiki.openstreetmap.org/wiki/The_Rails_Port#PostgreSQL_setup for detailed setup instructions. +# Postgresql version 8.3 recommended. +# See http://wiki.openstreetmap.org/wiki/OSM_Protocol_Version_0.6/postgres for detailed setup instructions. # development: adapter: postgresql @@ -15,8 +15,8 @@ development: test: adapter: postgresql database: osm_test - username: osm_test - password: osm_test +# username: osm_test +# password: osm_test host: localhost encoding: utf8 From 99f7298f8d9efbc75d4e1d5d3180e911f347dd43 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Wed, 27 Feb 2013 00:14:12 -0800 Subject: [PATCH 26/32] conforming this branch to upstream/master ; getting rid of extraneous local changes --- config/example.database.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/example.database.yml b/config/example.database.yml index 3908e51e53..e075d7f8df 100644 --- a/config/example.database.yml +++ b/config/example.database.yml @@ -1,5 +1,5 @@ -# Postgresql version 8.3 recommended. -# See http://wiki.openstreetmap.org/wiki/OSM_Protocol_Version_0.6/postgres for detailed setup instructions. +# Using a recent release (8.3 or higher) of PostgreSQL (http://postgresql.org/) is recommended. +# See http://wiki.openstreetmap.org/wiki/The_Rails_Port#PostgreSQL_setup for detailed setup instructions. # development: adapter: postgresql From 7e318723f147f5076171cec04f41d1878cbb02d0 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Wed, 27 Feb 2013 15:53:40 -0800 Subject: [PATCH 27/32] circling back for block 2 (NSEW decimal degrees) in #4748 --- app/controllers/geocoder_controller.rb | 8 +++++++- app/helpers/geocoder_helper.rb | 12 ++++++++++++ test/functional/geocoder_controller_test.rb | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 80bebbc15b..a859781e31 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -317,7 +317,13 @@ def escape_query(query) def convert_latlon @query = params[:query] - if latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes + + if latlon = @query.match(/^([NS])\s*(\d{1,3}\.?\d*)\W*([EW])\s*(\d{1,3}\.?\d*)$/).try(:captures) # [NSEW] decimal degrees + params[:query] = view_context.nsew_to_decdeg(latlon) + elsif latlon = @query.match(/^(\d{1,3}\.?\d*)\s*([NS])\W*(\d{1,3}\.?\d*)\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] + params[:query] = view_context.nsew_to_decdeg(latlon) + + elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes params[:query] = view_context.ddm_to_decdeg(latlon) elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] params[:query] = view_context.ddm_to_decdeg(latlon) diff --git a/app/helpers/geocoder_helper.rb b/app/helpers/geocoder_helper.rb index 1b40895d47..cc3dcf1b53 100644 --- a/app/helpers/geocoder_helper.rb +++ b/app/helpers/geocoder_helper.rb @@ -41,6 +41,18 @@ def describe_location(lat, lon, zoom = nil, language = nil) end end + def nsew_to_decdeg(captures) + begin + Float(captures[0]) + captures[1].downcase != 's' ? lat = captures[0].to_f : lat = -(captures[0].to_f) + captures[3].downcase != 'w' ? lon = captures[2].to_f : lon = -(captures[2].to_f) + rescue + captures[0].downcase != 's' ? lat = captures[1].to_f : lat = -(captures[1].to_f) + captures[2].downcase != 'w' ? lon = captures[3].to_f : lon = -(captures[3].to_f) + end + return "#{number_with_precision(lat, :precision => 5)}, #{number_with_precision(lon, :precision => 5)}" + end + def ddm_to_decdeg(captures) begin Float(captures[0]) diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index 680b0807e1..016ee69fc6 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -70,6 +70,21 @@ def test_identify_latlon_degdec end end + def test_identify_latlon_degdec_nsew + target = '50.06773, 14.37742' + [ + 'N50.06773 E14.37742', + 'N50.06773, E14.37742', + '50.06773N 14.37742E', + '50.06773N, 14.37742E' + ].each do |code| + post :search, :query => code + assert_response :success + assert_equal ['latlon'], assigns(:sources) + assert_equal target, assigns(:query) + end + end + def test_identify_latlon_ddm target = '50.06773, 14.37742' [ From 7767825e2b0123eea6d367839df9e8c1da96d22a Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Thu, 28 Feb 2013 22:00:16 -0800 Subject: [PATCH 28/32] reverting whitespace change --- test/functional/geocoder_controller_test.rb | 48 ++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index 680b0807e1..ba9e304204 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -7,53 +7,53 @@ class GeocoderControllerTest < ActionController::TestCase # test all routes which lead to this controller def test_routes assert_routing( - { :path => '/geocoder/search', :method => :post }, - { :controller => 'geocoder', :action => 'search' } + { :path => '/geocoder/search', :method => :post }, + { :controller => 'geocoder', :action => 'search' } ) assert_routing( - { :path => '/geocoder/search_latlon', :method => :get }, - { :controller => 'geocoder', :action => 'search_latlon' } + { :path => '/geocoder/search_latlon', :method => :get }, + { :controller => 'geocoder', :action => 'search_latlon' } ) assert_routing( - { :path => '/geocoder/search_us_postcode', :method => :get }, - { :controller => 'geocoder', :action => 'search_us_postcode' } + { :path => '/geocoder/search_us_postcode', :method => :get }, + { :controller => 'geocoder', :action => 'search_us_postcode' } ) assert_routing( - { :path => '/geocoder/search_uk_postcode', :method => :get }, - { :controller => 'geocoder', :action => 'search_uk_postcode' } + { :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' } + { :path => '/geocoder/search_ca_postcode', :method => :get }, + { :controller => 'geocoder', :action => 'search_ca_postcode' } ) assert_routing( - { :path => '/geocoder/search_osm_namefinder', :method => :get }, - { :controller => 'geocoder', :action => 'search_osm_namefinder' } + { :path => '/geocoder/search_osm_namefinder', :method => :get }, + { :controller => 'geocoder', :action => 'search_osm_namefinder' } ) assert_routing( - { :path => '/geocoder/search_osm_nominatim', :method => :get }, - { :controller => 'geocoder', :action => 'search_osm_nominatim' } + { :path => '/geocoder/search_osm_nominatim', :method => :get }, + { :controller => 'geocoder', :action => 'search_osm_nominatim' } ) assert_routing( - { :path => '/geocoder/search_geonames', :method => :get }, - { :controller => 'geocoder', :action => 'search_geonames' } + { :path => '/geocoder/search_geonames', :method => :get }, + { :controller => 'geocoder', :action => 'search_geonames' } ) assert_routing( - { :path => '/geocoder/description', :method => :post }, - { :controller => 'geocoder', :action => 'description' } + { :path => '/geocoder/description', :method => :post }, + { :controller => 'geocoder', :action => 'description' } ) assert_routing( - { :path => '/geocoder/description_osm_namefinder', :method => :get }, - { :controller => 'geocoder', :action => 'description_osm_namefinder' } + { :path => '/geocoder/description_osm_namefinder', :method => :get }, + { :controller => 'geocoder', :action => 'description_osm_namefinder' } ) assert_routing( - { :path => '/geocoder/description_osm_nominatim', :method => :get }, - { :controller => 'geocoder', :action => 'description_osm_nominatim' } + { :path => '/geocoder/description_osm_nominatim', :method => :get }, + { :controller => 'geocoder', :action => 'description_osm_nominatim' } ) assert_routing( - { :path => '/geocoder/description_geonames', :method => :get }, - { :controller => 'geocoder', :action => 'description_geonames' } + { :path => '/geocoder/description_geonames', :method => :get }, + { :controller => 'geocoder', :action => 'description_geonames' } ) end From af4d9a4f66ebd7feca62d04dadcd6ced180b9031 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Thu, 28 Feb 2013 22:25:01 -0800 Subject: [PATCH 29/32] reverting changes to geocoder_helper; putting converters in geocoder_controller --- app/helpers/geocoder_helper.rb | 37 ---------------------------------- 1 file changed, 37 deletions(-) diff --git a/app/helpers/geocoder_helper.rb b/app/helpers/geocoder_helper.rb index cc3dcf1b53..f5519ddc3f 100644 --- a/app/helpers/geocoder_helper.rb +++ b/app/helpers/geocoder_helper.rb @@ -40,41 +40,4 @@ def describe_location(lat, lon, zoom = nil, language = nil) "#{number_with_precision(lat, :precision => 3)}, #{number_with_precision(lon, :precision => 3)}" end end - - def nsew_to_decdeg(captures) - begin - Float(captures[0]) - captures[1].downcase != 's' ? lat = captures[0].to_f : lat = -(captures[0].to_f) - captures[3].downcase != 'w' ? lon = captures[2].to_f : lon = -(captures[2].to_f) - rescue - captures[0].downcase != 's' ? lat = captures[1].to_f : lat = -(captures[1].to_f) - captures[2].downcase != 'w' ? lon = captures[3].to_f : lon = -(captures[3].to_f) - end - return "#{number_with_precision(lat, :precision => 5)}, #{number_with_precision(lon, :precision => 5)}" - end - - def ddm_to_decdeg(captures) - begin - Float(captures[0]) - captures[2].downcase != 's' ? lat = captures[0].to_f + captures[1].to_f/60 : lat = -(captures[0].to_f + captures[1].to_f/60) - captures[5].downcase != 'w' ? lon = captures[3].to_f + captures[4].to_f/60 : lon = -(captures[3].to_f + captures[4].to_f/60) - rescue - captures[0].downcase != 's' ? lat = captures[1].to_f + captures[2].to_f/60 : lat = -(captures[1].to_f + captures[2].to_f/60) - captures[3].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f/60 : lon = -(captures[4].to_f + captures[5].to_f/60) - end - return "#{number_with_precision(lat, :precision => 5)}, #{number_with_precision(lon, :precision => 5)}" - end - - def dms_to_decdeg(captures) - begin - Float(captures[0]) - captures[3].downcase != 's' ? lat = captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60 : lat = -(captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60) - captures[7].downcase != 'w' ? lon = captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60 : lon = -(captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60) - rescue - captures[0].downcase != 's' ? lat = captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60 : lat = -(captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60) - captures[4].downcase != 'w' ? lon = captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60 : lon = -(captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60) - end - return "#{number_with_precision(lat, :precision => 5)}, #{number_with_precision(lon, :precision => 5)}" - end - end From 450312bca53b70fc332ec1a75e18993473f72b9e Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Thu, 28 Feb 2013 23:24:46 -0800 Subject: [PATCH 30/32] putting converters in geocoder_controller. adding test helper to round latlon to specified precision --- app/controllers/geocoder_controller.rb | 49 ++++++++++++++++++--- test/functional/geocoder_controller_test.rb | 17 ++++--- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index a859781e31..e1b13fc7d0 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -319,21 +319,56 @@ def convert_latlon @query = params[:query] if latlon = @query.match(/^([NS])\s*(\d{1,3}\.?\d*)\W*([EW])\s*(\d{1,3}\.?\d*)$/).try(:captures) # [NSEW] decimal degrees - params[:query] = view_context.nsew_to_decdeg(latlon) + params[:query] = nsew_to_decdeg(latlon) elsif latlon = @query.match(/^(\d{1,3}\.?\d*)\s*([NS])\W*(\d{1,3}\.?\d*)\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] - params[:query] = view_context.nsew_to_decdeg(latlon) - + params[:query] = nsew_to_decdeg(latlon) elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes - params[:query] = view_context.ddm_to_decdeg(latlon) + params[:query] = ddm_to_decdeg(latlon) elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] - params[:query] = view_context.ddm_to_decdeg(latlon) + params[:query] = ddm_to_decdeg(latlon) elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds - params[:query] = view_context.dms_to_decdeg(latlon) + params[:query] = dms_to_decdeg(latlon) elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] - params[:query] = view_context.dms_to_decdeg(latlon) + params[:query] = dms_to_decdeg(latlon) else return end end + def nsew_to_decdeg(captures) + begin + Float(captures[0]) + captures[1].downcase != 's' ? lat = captures[0].to_f : lat = -(captures[0].to_f) + captures[3].downcase != 'w' ? lon = captures[2].to_f : lon = -(captures[2].to_f) + rescue + captures[0].downcase != 's' ? lat = captures[1].to_f : lat = -(captures[1].to_f) + captures[2].downcase != 'w' ? lon = captures[3].to_f : lon = -(captures[3].to_f) + end + return "#{lat}, #{lon}" + end + + def ddm_to_decdeg(captures) + begin + Float(captures[0]) + captures[2].downcase != 's' ? lat = captures[0].to_f + captures[1].to_f/60 : lat = -(captures[0].to_f + captures[1].to_f/60) + captures[5].downcase != 'w' ? lon = captures[3].to_f + captures[4].to_f/60 : lon = -(captures[3].to_f + captures[4].to_f/60) + rescue + captures[0].downcase != 's' ? lat = captures[1].to_f + captures[2].to_f/60 : lat = -(captures[1].to_f + captures[2].to_f/60) + captures[3].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f/60 : lon = -(captures[4].to_f + captures[5].to_f/60) + end + return "#{lat}, #{lon}" + end + + def dms_to_decdeg(captures) + begin + Float(captures[0]) + captures[3].downcase != 's' ? lat = captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60 : lat = -(captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60) + captures[7].downcase != 'w' ? lon = captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60 : lon = -(captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60) + rescue + captures[0].downcase != 's' ? lat = captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60 : lat = -(captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60) + captures[4].downcase != 'w' ? lon = captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60 : lon = -(captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60) + end + return "#{lat}, #{lon}" + end + end diff --git a/test/functional/geocoder_controller_test.rb b/test/functional/geocoder_controller_test.rb index 69f51f0f97..889d53e897 100644 --- a/test/functional/geocoder_controller_test.rb +++ b/test/functional/geocoder_controller_test.rb @@ -70,6 +70,13 @@ def test_identify_latlon_degdec end end + ## + # this is a test helper for rounding latlon strings to a specified precision, e.g., at a precision + # of 5, "50.06773333333334, -14.377416666666667" will become "50.06773, -14.37742" + def assert_latlon_equal_round(expected, actual, precision) + assert_equal expected.split(',').map {|i| i.to_f.round(precision)}.join(', '), actual.split(',').map {|i| i.to_f.round(precision)}.join(', ') + end + def test_identify_latlon_degdec_nsew target = '50.06773, 14.37742' [ @@ -99,7 +106,7 @@ def test_identify_latlon_ddm post :search, :query => code assert_response :success assert_equal ['latlon'], assigns(:sources) - assert_equal target, assigns(:query) + assert_latlon_equal_round(target, assigns(:query), 5) end end @@ -159,7 +166,7 @@ def test_ne post :search, :query => code assert_response :success assert_equal ['latlon'], assigns(:sources) - assert_equal target, assigns(:query) + assert_latlon_equal_round(target, assigns(:query), 5) end end @@ -174,7 +181,7 @@ def test_nw post :search, :query => code assert_response :success assert_equal ['latlon'], assigns(:sources) - assert_equal target, assigns(:query) + assert_latlon_equal_round(target, assigns(:query), 5) end end @@ -189,7 +196,7 @@ def test_se post :search, :query => code assert_response :success assert_equal ['latlon'], assigns(:sources) - assert_equal target, assigns(:query) + assert_latlon_equal_round(target, assigns(:query), 5) end end @@ -204,7 +211,7 @@ def test_sw post :search, :query => code assert_response :success assert_equal ['latlon'], assigns(:sources) - assert_equal target, assigns(:query) + assert_latlon_equal_round(target, assigns(:query), 5) end end From dc1a5be1fff2ce0d3c2468513b193fea169021d3 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Thu, 28 Feb 2013 23:32:38 -0800 Subject: [PATCH 31/32] correcting case comment --- app/controllers/geocoder_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index e1b13fc7d0..7ccf8eb28f 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -320,7 +320,7 @@ def convert_latlon if latlon = @query.match(/^([NS])\s*(\d{1,3}\.?\d*)\W*([EW])\s*(\d{1,3}\.?\d*)$/).try(:captures) # [NSEW] decimal degrees params[:query] = nsew_to_decdeg(latlon) - elsif latlon = @query.match(/^(\d{1,3}\.?\d*)\s*([NS])\W*(\d{1,3}\.?\d*)\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] + elsif latlon = @query.match(/^(\d{1,3}\.?\d*)\s*([NS])\W*(\d{1,3}\.?\d*)\s*([EW])$/).try(:captures) # decimal degrees [NSEW] params[:query] = nsew_to_decdeg(latlon) elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes params[:query] = ddm_to_decdeg(latlon) From 8bd386775b66e1321100e2039ba72eba1161cc26 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Sat, 2 Mar 2013 12:42:00 -0800 Subject: [PATCH 32/32] improved regexps for floating point values --- app/controllers/geocoder_controller.rb | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 7ccf8eb28f..17951853e5 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -318,17 +318,19 @@ def escape_query(query) def convert_latlon @query = params[:query] - if latlon = @query.match(/^([NS])\s*(\d{1,3}\.?\d*)\W*([EW])\s*(\d{1,3}\.?\d*)$/).try(:captures) # [NSEW] decimal degrees + if latlon = @query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) # [NSEW] decimal degrees params[:query] = nsew_to_decdeg(latlon) - elsif latlon = @query.match(/^(\d{1,3}\.?\d*)\s*([NS])\W*(\d{1,3}\.?\d*)\s*([EW])$/).try(:captures) # decimal degrees [NSEW] + elsif latlon = @query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures) # decimal degrees [NSEW] params[:query] = nsew_to_decdeg(latlon) - elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes + + elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?$/).try(:captures) # [NSEW] degrees, decimal minutes params[:query] = ddm_to_decdeg(latlon) - elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}\.?\d*)?['′]?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] + elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,3}(\.\d*)?)?['′]?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] params[:query] = ddm_to_decdeg(latlon) - elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds + + elsif latlon = @query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds params[:query] = dms_to_decdeg(latlon) - elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}\.?\d*)?["″]?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] + elsif latlon = @query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?\s*(\d{1,3}(\.\d*)?)?["″]?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] params[:query] = dms_to_decdeg(latlon) else return @@ -339,10 +341,10 @@ def nsew_to_decdeg(captures) begin Float(captures[0]) captures[1].downcase != 's' ? lat = captures[0].to_f : lat = -(captures[0].to_f) - captures[3].downcase != 'w' ? lon = captures[2].to_f : lon = -(captures[2].to_f) + captures[4].downcase != 'w' ? lon = captures[3].to_f : lon = -(captures[3].to_f) rescue captures[0].downcase != 's' ? lat = captures[1].to_f : lat = -(captures[1].to_f) - captures[2].downcase != 'w' ? lon = captures[3].to_f : lon = -(captures[3].to_f) + captures[3].downcase != 'w' ? lon = captures[4].to_f : lon = -(captures[4].to_f) end return "#{lat}, #{lon}" end @@ -350,11 +352,11 @@ def nsew_to_decdeg(captures) def ddm_to_decdeg(captures) begin Float(captures[0]) - captures[2].downcase != 's' ? lat = captures[0].to_f + captures[1].to_f/60 : lat = -(captures[0].to_f + captures[1].to_f/60) - captures[5].downcase != 'w' ? lon = captures[3].to_f + captures[4].to_f/60 : lon = -(captures[3].to_f + captures[4].to_f/60) + captures[3].downcase != 's' ? lat = captures[0].to_f + captures[1].to_f/60 : lat = -(captures[0].to_f + captures[1].to_f/60) + captures[7].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f/60 : lon = -(captures[4].to_f + captures[5].to_f/60) rescue captures[0].downcase != 's' ? lat = captures[1].to_f + captures[2].to_f/60 : lat = -(captures[1].to_f + captures[2].to_f/60) - captures[3].downcase != 'w' ? lon = captures[4].to_f + captures[5].to_f/60 : lon = -(captures[4].to_f + captures[5].to_f/60) + captures[4].downcase != 'w' ? lon = captures[5].to_f + captures[6].to_f/60 : lon = -(captures[5].to_f + captures[6].to_f/60) end return "#{lat}, #{lon}" end @@ -362,11 +364,11 @@ def ddm_to_decdeg(captures) def dms_to_decdeg(captures) begin Float(captures[0]) - captures[3].downcase != 's' ? lat = captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60 : lat = -(captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60) - captures[7].downcase != 'w' ? lon = captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60 : lon = -(captures[4].to_f + (captures[5].to_f + captures[6].to_f/60)/60) + captures[4].downcase != 's' ? lat = captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60 : lat = -(captures[0].to_f + (captures[1].to_f + captures[2].to_f/60)/60) + captures[9].downcase != 'w' ? lon = captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60 : lon = -(captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60) rescue captures[0].downcase != 's' ? lat = captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60 : lat = -(captures[1].to_f + (captures[2].to_f + captures[3].to_f/60)/60) - captures[4].downcase != 'w' ? lon = captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60 : lon = -(captures[5].to_f + (captures[6].to_f + captures[7].to_f/60)/60) + captures[5].downcase != 'w' ? lon = captures[6].to_f + (captures[7].to_f + captures[8].to_f/60)/60 : lon = -(captures[6].to_f + (captures[7].to_f + captures[8].to_f/60)/60) end return "#{lat}, #{lon}" end