geokit-nominatim 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +40 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/geokit-nominatim.gemspec +66 -0
- data/lib/geokit/geocoders/nominatim_geocoder.rb +69 -0
- data/lib/geokit-nominatim.rb +6 -0
- data/spec/nominatim_geocoder_spec.rb +57 -0
- data/spec/spec_helper.rb +17 -0
- metadata +130 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'json_pure'
|
7
|
+
gem 'geokit'
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rspec" #, "~> 2.3.0"
|
13
|
+
gem "bundler" #, "~> 1.0.0"
|
14
|
+
gem "jeweler" #, "~> 1.6.2"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Andrew Williams
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
= geokit-nominatim
|
2
|
+
|
3
|
+
Nominatim geocoding provider for geokit.
|
4
|
+
|
5
|
+
- GeoKit: http://geokit.rubyforge.org/
|
6
|
+
- Nominatim: http://wiki.openstreetmap.org/wiki/Nominatim
|
7
|
+
- MapQuest service: http://developer.mapquest.com/web/products/open/nominatim
|
8
|
+
|
9
|
+
== Synopsis
|
10
|
+
|
11
|
+
Set up nominatim as a geocoder provider
|
12
|
+
|
13
|
+
Geokit::Geocoders::provider_order = [:nominatim]
|
14
|
+
|
15
|
+
Set the address of the Nominatim server to use.
|
16
|
+
see http://developer.mapquest.com/web/products/open/nominatim for usage policy.
|
17
|
+
|
18
|
+
Geokit::Geocoders::NominatimGeocoder.server = "open.mapquestapi.com/nominatim/v1/search"
|
19
|
+
|
20
|
+
geocode an address
|
21
|
+
|
22
|
+
include Geokit::Geocoders
|
23
|
+
res = MultiGeocoder.geocode('100 Spear st, San Francisco, CA')
|
24
|
+
puts res.ll # ll=latitude,longitude
|
25
|
+
|
26
|
+
== Contributing to geokit-nominatim
|
27
|
+
|
28
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
29
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
30
|
+
* Fork the project
|
31
|
+
* Start a feature/bugfix branch
|
32
|
+
* Commit and push until you are happy with your contribution
|
33
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
34
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
35
|
+
|
36
|
+
== Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2011 Andrew Williams.
|
39
|
+
See LICENSE.txt for further details.
|
40
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "geokit-nominatim"
|
18
|
+
gem.homepage = "http://github.com/sobakasu/geokit-nominatim"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Nominatim geocoding provider for geokit}
|
21
|
+
gem.description = %Q{Nominatim geocoding provider for geokit}
|
22
|
+
gem.email = "sobakasu@gmail.com"
|
23
|
+
gem.authors = ["Andrew Williams"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "geokit-nominatim #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{geokit-nominatim}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Andrew Williams"]
|
12
|
+
s.date = %q{2011-06-25}
|
13
|
+
s.description = %q{Nominatim geocoding provider for geokit}
|
14
|
+
s.email = %q{sobakasu@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"geokit-nominatim.gemspec",
|
28
|
+
"lib/geokit-nominatim.rb",
|
29
|
+
"lib/geokit/geocoders/nominatim_geocoder.rb",
|
30
|
+
"spec/nominatim_geocoder_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/sobakasu/geokit-nominatim}
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.6.2}
|
37
|
+
s.summary = %q{Nominatim geocoding provider for geokit}
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<json_pure>, [">= 0"])
|
44
|
+
s.add_runtime_dependency(%q<geokit>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<json_pure>, [">= 0"])
|
51
|
+
s.add_dependency(%q<geokit>, [">= 0"])
|
52
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
53
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
54
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<json_pure>, [">= 0"])
|
59
|
+
s.add_dependency(%q<geokit>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
61
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
62
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class Geokit::Geocoders::NominatimGeocoder < Geokit::Geocoders::Geocoder
|
2
|
+
|
3
|
+
PLACE_KEYS = %W{city state postcode country country_code house_number house
|
4
|
+
hamlet}
|
5
|
+
PROVIDER = 'nominatim'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :server
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.do_geocode(address, options = {})
|
12
|
+
# get server address
|
13
|
+
server = options[:server] || self.server
|
14
|
+
raise "server required" unless server
|
15
|
+
server = "http://#{server}" unless server.match(/^http:/)
|
16
|
+
|
17
|
+
# construct response
|
18
|
+
res = Geokit::GeoLoc.new
|
19
|
+
res.provider = PROVIDER
|
20
|
+
|
21
|
+
# create query string
|
22
|
+
address_str = address.is_a?(Geokit::GeoLoc) ? address.to_geocodeable_s : address
|
23
|
+
opts = options.merge(:q => address_str, :limit => 1,
|
24
|
+
:format => :xml, :addressdetails => 1)
|
25
|
+
opts.delete(:server)
|
26
|
+
params = opts.collect { |k,v| "#{k}=#{escape(v)}" }.join("&")
|
27
|
+
|
28
|
+
# send query
|
29
|
+
url = "#{server}?#{params}"
|
30
|
+
server_res = self.call_geocoder_service(url)
|
31
|
+
return res if !server_res.is_a?(Net::HTTPSuccess)
|
32
|
+
|
33
|
+
# parse response
|
34
|
+
xml = server_res.body
|
35
|
+
logger.debug "nominatim geocoding. Address: #{address}. Result: #{xml}"
|
36
|
+
self.parse_response(xml, res)
|
37
|
+
res
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def self.parse_response(xml, res)
|
43
|
+
doc = REXML::Document.new(xml)
|
44
|
+
|
45
|
+
place = doc.elements['//searchresults/place']
|
46
|
+
attrs = place.attributes
|
47
|
+
res.lat = attrs['lat']
|
48
|
+
res.lng = attrs['lon']
|
49
|
+
|
50
|
+
elements = {}
|
51
|
+
PLACE_KEYS.each do |key|
|
52
|
+
elements[key] = place.elements[key] ? place.elements[key].text : nil
|
53
|
+
end
|
54
|
+
|
55
|
+
res.full_address = attrs['display_name']
|
56
|
+
res.street_address = elements['road']
|
57
|
+
res.zip = elements['postcode']
|
58
|
+
res.country = elements['country']
|
59
|
+
res.city = elements['city'] || elements['hamlet']
|
60
|
+
res.state = elements['state']
|
61
|
+
res.street_number = elements['house_number'] || elements['house']
|
62
|
+
res.success = true
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.escape(string)
|
66
|
+
Geokit::Inflector::url_escape(string.to_s)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
class NominatimTests
|
4
|
+
|
5
|
+
def self.geocode_tests
|
6
|
+
[ ["Adelaide", {
|
7
|
+
:lat => -34.927, :lng => 138.600,
|
8
|
+
:zip => "5000", :country => "Australia", :city => "Adelaide",
|
9
|
+
:state => "South Australia"
|
10
|
+
}],
|
11
|
+
["359 Columbus Avenue, New York", {
|
12
|
+
:lat => 40.717, :lng => -73.338,
|
13
|
+
:zip => '11704', :street_number => '359',
|
14
|
+
:country => "United States of America", :city => "West Babylon",
|
15
|
+
:state => "New York"
|
16
|
+
}]
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe Geokit::Geocoders::NominatimGeocoder do
|
23
|
+
|
24
|
+
before(:all) do
|
25
|
+
@klass = Geokit::Geocoders::NominatimGeocoder
|
26
|
+
@server = ENV['NOMINATIM_SERVER']
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should respond to do_geocode()" do
|
30
|
+
@klass.should respond_to(:do_geocode)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be usable from MultiGeocoder" do
|
34
|
+
@klass.should_receive(:geocode).and_return(Geokit::GeoLoc.new)
|
35
|
+
|
36
|
+
Geokit::Geocoders::provider_order = [:nominatim]
|
37
|
+
Geokit::Geocoders::MultiGeocoder.geocode('test address')
|
38
|
+
end
|
39
|
+
|
40
|
+
NominatimTests.geocode_tests.each do |addr, expected|
|
41
|
+
it "should geocode #{addr}" do
|
42
|
+
@klass.server = @server
|
43
|
+
res = @klass.geocode(addr)
|
44
|
+
res.should_not be_nil
|
45
|
+
res.success.should be_true
|
46
|
+
res.lat.should be_within(0.1).of(expected[:lat])
|
47
|
+
res.lng.should be_within(0.1).of(expected[:lng])
|
48
|
+
|
49
|
+
expected.each do |k,v|
|
50
|
+
next if [:lat, :lng].include?(k)
|
51
|
+
res.send(k).should == v
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'geokit-nominatim'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
unless ENV['NOMINATIM_SERVER']
|
15
|
+
puts "NOMINATIM_SERVER environment setting required"
|
16
|
+
exit 1
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geokit-nominatim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Williams
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-06-25 00:00:00.000000000 +09:30
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json_pure
|
17
|
+
requirement: &2152833080 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2152833080
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: geokit
|
28
|
+
requirement: &2152832100 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2152832100
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &2152831220 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2152831220
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &2152830320 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2152830320
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: jeweler
|
61
|
+
requirement: &2152829580 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2152829580
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rcov
|
72
|
+
requirement: &2152828720 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *2152828720
|
81
|
+
description: Nominatim geocoding provider for geokit
|
82
|
+
email: sobakasu@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files:
|
86
|
+
- LICENSE.txt
|
87
|
+
- README.rdoc
|
88
|
+
files:
|
89
|
+
- .document
|
90
|
+
- .rspec
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.rdoc
|
94
|
+
- Rakefile
|
95
|
+
- VERSION
|
96
|
+
- geokit-nominatim.gemspec
|
97
|
+
- lib/geokit-nominatim.rb
|
98
|
+
- lib/geokit/geocoders/nominatim_geocoder.rb
|
99
|
+
- spec/nominatim_geocoder_spec.rb
|
100
|
+
- spec/spec_helper.rb
|
101
|
+
has_rdoc: true
|
102
|
+
homepage: http://github.com/sobakasu/geokit-nominatim
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
hash: 2076618883302095355
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.6.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Nominatim geocoding provider for geokit
|
130
|
+
test_files: []
|