geocoder 1.2.14 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of geocoder might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +16 -1
- data/lib/geocoder/calculations.rb +1 -1
- data/lib/geocoder/lookup.rb +5 -4
- data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/lib/geocoder/lookups/maxmind_local.rb +1 -1
- data/lib/geocoder/results/esri.rb +15 -6
- data/lib/geocoder/results/geoportail_lu.rb +69 -0
- data/lib/geocoder/results/google.rb +8 -0
- data/lib/geocoder/stores/mongo_base.rb +0 -44
- data/lib/geocoder/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7a2b3e33175d20be86a8eaf6c74d6178bc71991
|
4
|
+
data.tar.gz: d0dc03b689fbc43f16ae9395c7f743a3dd7876bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb9f5c459af278bd20438a714475dece555b72222c34eab8c8fb61f6ddfc695848d330e9b84f366c8d67e5f253bda7d5e61020ab46382f8fbb40c8b7a9a58e82
|
7
|
+
data.tar.gz: ca02902240f5287a570ee05b0bc3b0300708200108b09543763e761ad1f0a2371355ef651471cdf96ce5cdabf104a39aedb04ef684e4f02aa3023911c27d7c4a
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,13 @@ Changelog
|
|
3
3
|
|
4
4
|
Major changes to Geocoder for each release. Please see the Git log for complete list of changes.
|
5
5
|
|
6
|
+
1.3.0 (2016 Jan 31)
|
7
|
+
-------------------
|
8
|
+
* Lazy load lookups to reduce memory footprint (thanks github.com/TrangPham).
|
9
|
+
* Add :geoportail_lu lookup (Luxembourg only) (thanks github.com/mdebo).
|
10
|
+
* Maxmind local query performance improvement (thanks github.com/vojtad).
|
11
|
+
* Remove deprecated Mongo near query methods (please use Mongo-native methods instead).
|
12
|
+
|
6
13
|
1.2.14 (2015 Dec 27)
|
7
14
|
--------------------
|
8
15
|
* Fix bug in :geoip2 lookup (thanks github.com/mromulus).
|
data/README.md
CHANGED
@@ -637,6 +637,16 @@ Data Science Toolkit provides an API whose reponse format is like Google's but w
|
|
637
637
|
* **Terms of Service**: http://www.itella.fi/liitteet/palvelutjatuotteet/yhteystietopalvelut/Postinumeropalvelut-Palvelukuvausjakayttoehdot.pdf
|
638
638
|
* **Limitations**: ?
|
639
639
|
|
640
|
+
#### Geoportail.lu (`:geoportail_lu`)
|
641
|
+
|
642
|
+
* **API key**: none
|
643
|
+
* **Quota**: none
|
644
|
+
* **Region**: LU
|
645
|
+
* **SSL support**: yes
|
646
|
+
* **Languages**: en
|
647
|
+
* **Documentation**: http://wiki.geoportail.lu/doku.php?id=en:api
|
648
|
+
* **Terms of Service**: http://wiki.geoportail.lu/doku.php?id=en:mcg_1
|
649
|
+
* **Limitations**: ?
|
640
650
|
|
641
651
|
#### PostcodeAnywhere Uk (`:postcode_anywhere_uk`)
|
642
652
|
|
@@ -924,6 +934,9 @@ Now, any time Geocoder looks up "New York, NY" its results array will contain on
|
|
924
934
|
]
|
925
935
|
)
|
926
936
|
|
937
|
+
Note:
|
938
|
+
Keys must be strings not symbols when calling `add_stub` or `set_default_stub`. For example `'latitude' =>` not `:latitude =>`.
|
939
|
+
|
927
940
|
|
928
941
|
Command Line Interface
|
929
942
|
----------------------
|
@@ -1099,7 +1112,9 @@ If anyone has a more elegant solution to this problem I am very interested in se
|
|
1099
1112
|
Contributing
|
1100
1113
|
------------
|
1101
1114
|
|
1102
|
-
Contributions are welcome via pull requests
|
1115
|
+
Contributions are welcome via Github pull requests. If you are new to the project and looking for a way to get involved, try picking up an issue with a "beginner-task" label. Hints about what needs to be done are usually provided.
|
1116
|
+
|
1117
|
+
For all contributions, please respect the following guidelines:
|
1103
1118
|
|
1104
1119
|
* Each pull request should implement ONE feature or bugfix. If you want to add or fix more than one thing, submit more than one pull request.
|
1105
1120
|
* Do not commit changes to files that are irrelevant to your feature or bugfix (eg: `.gitignore`).
|
@@ -263,7 +263,7 @@ module Geocoder
|
|
263
263
|
end
|
264
264
|
|
265
265
|
##
|
266
|
-
# Given a start point,
|
266
|
+
# Given a start point, heading (in degrees), and distance, provides
|
267
267
|
# an endpoint.
|
268
268
|
# The starting point is given in the same way that points are given to all
|
269
269
|
# Geocoder methods that accept points as arguments. It can be:
|
data/lib/geocoder/lookup.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "geocoder/lookups/test"
|
2
|
+
|
1
3
|
module Geocoder
|
2
4
|
module Lookup
|
3
5
|
extend self
|
@@ -42,6 +44,7 @@ module Geocoder
|
|
42
44
|
:smarty_streets,
|
43
45
|
:okf,
|
44
46
|
:postcode_anywhere_uk,
|
47
|
+
:geoportail_lu,
|
45
48
|
:test
|
46
49
|
]
|
47
50
|
end
|
@@ -83,6 +86,8 @@ module Geocoder
|
|
83
86
|
#
|
84
87
|
def spawn(name)
|
85
88
|
if all_services.include?(name)
|
89
|
+
name = name.to_s
|
90
|
+
require "geocoder/lookups/#{name}"
|
86
91
|
Geocoder::Lookup.const_get(classify_name(name)).new
|
87
92
|
else
|
88
93
|
valids = all_services.map(&:inspect).join(", ")
|
@@ -99,7 +104,3 @@ module Geocoder
|
|
99
104
|
end
|
100
105
|
end
|
101
106
|
end
|
102
|
-
|
103
|
-
Geocoder::Lookup.all_services.each do |name|
|
104
|
-
require "geocoder/lookups/#{name}"
|
105
|
-
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require "geocoder/results/geoportail_lu"
|
3
|
+
|
4
|
+
module Geocoder
|
5
|
+
module Lookup
|
6
|
+
class GeoportailLu < Base
|
7
|
+
|
8
|
+
def name
|
9
|
+
"Geoportail.lu"
|
10
|
+
end
|
11
|
+
|
12
|
+
def query_url(query)
|
13
|
+
url_base_path(query) + url_query_string(query)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def url_base_path(query)
|
19
|
+
query.reverse_geocode? ? reverse_geocode_url_base_path : search_url_base_path
|
20
|
+
end
|
21
|
+
|
22
|
+
def search_url_base_path
|
23
|
+
"#{protocol}://api.geoportail.lu/geocoder/search?"
|
24
|
+
end
|
25
|
+
|
26
|
+
def reverse_geocode_url_base_path
|
27
|
+
"#{protocol}://api.geoportail.lu/geocoder/reverseGeocode?"
|
28
|
+
end
|
29
|
+
|
30
|
+
def query_url_geoportail_lu_params(query)
|
31
|
+
query.reverse_geocode? ? reverse_geocode_params(query) : search_params(query)
|
32
|
+
end
|
33
|
+
|
34
|
+
def search_params(query)
|
35
|
+
{
|
36
|
+
queryString: query.sanitized_text
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def reverse_geocode_params(query)
|
41
|
+
lat_lon = query.coordinates
|
42
|
+
{
|
43
|
+
lat: lat_lon.first,
|
44
|
+
lon: lat_lon.last
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def query_url_params(query)
|
49
|
+
query_url_geoportail_lu_params(query).merge(super)
|
50
|
+
end
|
51
|
+
|
52
|
+
def results(query)
|
53
|
+
return [] unless doc = fetch_data(query)
|
54
|
+
if doc['success'] == true
|
55
|
+
result = doc['results']
|
56
|
+
else
|
57
|
+
result = []
|
58
|
+
raise_error(Geocoder::Error) ||
|
59
|
+
warn("Geportail.lu Geocoding API error")
|
60
|
+
end
|
61
|
+
result
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -36,7 +36,7 @@ module Geocoder::Lookup
|
|
36
36
|
addr = IPAddr.new(query.text).to_i
|
37
37
|
q = "SELECT l.country, l.region, l.city, l.latitude, l.longitude
|
38
38
|
FROM maxmind_geolite_city_location l WHERE l.loc_id = (SELECT b.loc_id FROM maxmind_geolite_city_blocks b
|
39
|
-
WHERE b.start_ip_num <= #{addr} AND #{addr} <= b.end_ip_num
|
39
|
+
WHERE b.start_ip_num <= #{addr} AND #{addr} <= b.end_ip_num)"
|
40
40
|
format_result(q, [:country_name, :region_name, :city_name, :latitude, :longitude])
|
41
41
|
elsif configuration[:package] == :country
|
42
42
|
addr = IPAddr.new(query.text).to_i
|
@@ -4,13 +4,13 @@ module Geocoder::Result
|
|
4
4
|
class Esri < Base
|
5
5
|
|
6
6
|
def address
|
7
|
-
|
8
|
-
attributes[
|
7
|
+
address_key = reverse_geocode? ? 'Address' : 'Match_addr'
|
8
|
+
attributes[address_key]
|
9
9
|
end
|
10
10
|
|
11
11
|
def city
|
12
12
|
if !reverse_geocode? && is_city?
|
13
|
-
|
13
|
+
place_name
|
14
14
|
else
|
15
15
|
attributes['City']
|
16
16
|
end
|
@@ -23,8 +23,8 @@ module Geocoder::Result
|
|
23
23
|
alias_method :state, :state_code
|
24
24
|
|
25
25
|
def country
|
26
|
-
|
27
|
-
attributes[
|
26
|
+
country_key = reverse_geocode? ? "CountryCode" : "Country"
|
27
|
+
attributes[country_key]
|
28
28
|
end
|
29
29
|
|
30
30
|
alias_method :country_code, :country
|
@@ -33,6 +33,15 @@ module Geocoder::Result
|
|
33
33
|
attributes['Postal']
|
34
34
|
end
|
35
35
|
|
36
|
+
def place_name
|
37
|
+
place_name_key = reverse_geocode? ? "Address" : "PlaceName"
|
38
|
+
attributes[place_name_key]
|
39
|
+
end
|
40
|
+
|
41
|
+
def place_type
|
42
|
+
reverse_geocode? ? "Address" : attributes['Type']
|
43
|
+
end
|
44
|
+
|
36
45
|
def coordinates
|
37
46
|
[geometry["y"], geometry["x"]]
|
38
47
|
end
|
@@ -52,7 +61,7 @@ module Geocoder::Result
|
|
52
61
|
end
|
53
62
|
|
54
63
|
def is_city?
|
55
|
-
['City', 'State Capital', 'National Capital'].include?(
|
64
|
+
['City', 'State Capital', 'National Capital'].include?(place_type)
|
56
65
|
end
|
57
66
|
end
|
58
67
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class GeoportailLu < Base
|
5
|
+
|
6
|
+
def coordinates
|
7
|
+
geomlonlat['coordinates'].reverse if geolocalized?
|
8
|
+
end
|
9
|
+
|
10
|
+
def address
|
11
|
+
full_address
|
12
|
+
end
|
13
|
+
|
14
|
+
def city
|
15
|
+
try_to_extract 'locality', detailled_address
|
16
|
+
end
|
17
|
+
|
18
|
+
def state
|
19
|
+
'Luxembourg'
|
20
|
+
end
|
21
|
+
|
22
|
+
def state_code
|
23
|
+
'LU'
|
24
|
+
end
|
25
|
+
|
26
|
+
def postal_code
|
27
|
+
try_to_extract 'zip', detailled_address
|
28
|
+
end
|
29
|
+
|
30
|
+
def street_address
|
31
|
+
[street_number, street].compact.join(' ')
|
32
|
+
end
|
33
|
+
|
34
|
+
def street_number
|
35
|
+
try_to_extract 'postnumber', detailled_address
|
36
|
+
end
|
37
|
+
|
38
|
+
def street
|
39
|
+
try_to_extract 'street', detailled_address
|
40
|
+
end
|
41
|
+
|
42
|
+
def full_address
|
43
|
+
data['address']
|
44
|
+
end
|
45
|
+
|
46
|
+
def geomlonlat
|
47
|
+
data['geomlonlat']
|
48
|
+
end
|
49
|
+
|
50
|
+
def detailled_address
|
51
|
+
data['AddressDetails']
|
52
|
+
end
|
53
|
+
|
54
|
+
alias_method :country, :state
|
55
|
+
alias_method :province, :state
|
56
|
+
alias_method :country_code, :state_code
|
57
|
+
alias_method :province_code, :state_code
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def geolocalized?
|
62
|
+
try_to_extract('coordinates', geomlonlat).present?
|
63
|
+
end
|
64
|
+
|
65
|
+
def try_to_extract(key, nullable_hash)
|
66
|
+
nullable_hash.try(:[], key)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -11,38 +11,6 @@ module Geocoder::Store
|
|
11
11
|
scope :not_geocoded, lambda {
|
12
12
|
where(geocoder_options[:coordinates] => nil)
|
13
13
|
}
|
14
|
-
|
15
|
-
scope :near, lambda{ |location, *args|
|
16
|
-
warn "DEPRECATION WARNING: The .near method will be removed for MongoDB-backed models in Geocoder 1.3.0. Please use MongoDB's built-in query language instead."
|
17
|
-
coords = Geocoder::Calculations.extract_coordinates(location)
|
18
|
-
|
19
|
-
# no results if no lat/lon given
|
20
|
-
return where(:id => false) unless coords.is_a?(Array)
|
21
|
-
|
22
|
-
radius = args.size > 0 ? args.shift : 20
|
23
|
-
options = args.size > 0 ? args.shift : {}
|
24
|
-
options[:units] ||= geocoder_options[:units]
|
25
|
-
|
26
|
-
# Use BSON::OrderedHash if Ruby's hashes are unordered.
|
27
|
-
# Conditions must be in order required by indexes (see mongo gem).
|
28
|
-
version = RUBY_VERSION.split('.').map { |i| i.to_i }
|
29
|
-
empty = version[0] < 2 && version[1] < 9 ? BSON::OrderedHash.new : {}
|
30
|
-
|
31
|
-
conds = empty.clone
|
32
|
-
field = geocoder_options[:coordinates]
|
33
|
-
conds[field] = empty.clone
|
34
|
-
conds[field]["$nearSphere"] = coords.reverse
|
35
|
-
|
36
|
-
if radius
|
37
|
-
conds[field]["$maxDistance"] = \
|
38
|
-
Geocoder::Calculations.distance_to_radians(radius, options[:units])
|
39
|
-
end
|
40
|
-
|
41
|
-
if obj = options[:exclude]
|
42
|
-
conds[:_id.ne] = obj.id
|
43
|
-
end
|
44
|
-
where(conds)
|
45
|
-
}
|
46
14
|
end
|
47
15
|
end
|
48
16
|
|
@@ -56,18 +24,6 @@ module Geocoder::Store
|
|
56
24
|
coords.is_a?(Array) ? coords.reverse : []
|
57
25
|
end
|
58
26
|
|
59
|
-
##
|
60
|
-
# Get nearby geocoded objects.
|
61
|
-
# Takes the same options hash as the near class method (scope).
|
62
|
-
# Returns nil if the object is not geocoded.
|
63
|
-
#
|
64
|
-
def nearbys(radius = 20, options = {})
|
65
|
-
warn "DEPRECATION WARNING: The #nearbys method will be removed for MongoDB-backed models in Geocoder 1.3.0. Please use MongoDB's built-in query language instead."
|
66
|
-
return nil unless geocoded?
|
67
|
-
options.merge!(:exclude => self) unless send(self.class.primary_key).nil?
|
68
|
-
self.class.near(self, radius, options)
|
69
|
-
end
|
70
|
-
|
71
27
|
##
|
72
28
|
# Look up coordinates and assign to +latitude+ and +longitude+ attributes
|
73
29
|
# (or other as specified in +geocoded_by+). Returns coordinates (array).
|
data/lib/geocoder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Reisner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Provides object geocoding (by street or IP address), reverse geocoding
|
14
14
|
(coordinates to street address), distance queries for ActiveRecord and Mongoid,
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/geocoder/lookups/geocoder_us.rb
|
58
58
|
- lib/geocoder/lookups/geocodio.rb
|
59
59
|
- lib/geocoder/lookups/geoip2.rb
|
60
|
+
- lib/geocoder/lookups/geoportail_lu.rb
|
60
61
|
- lib/geocoder/lookups/google.rb
|
61
62
|
- lib/geocoder/lookups/google_places_details.rb
|
62
63
|
- lib/geocoder/lookups/google_premier.rb
|
@@ -96,6 +97,7 @@ files:
|
|
96
97
|
- lib/geocoder/results/geocoder_us.rb
|
97
98
|
- lib/geocoder/results/geocodio.rb
|
98
99
|
- lib/geocoder/results/geoip2.rb
|
100
|
+
- lib/geocoder/results/geoportail_lu.rb
|
99
101
|
- lib/geocoder/results/google.rb
|
100
102
|
- lib/geocoder/results/google_places_details.rb
|
101
103
|
- lib/geocoder/results/google_premier.rb
|
@@ -148,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
150
|
version: '0'
|
149
151
|
requirements: []
|
150
152
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.5.1
|
152
154
|
signing_key:
|
153
155
|
specification_version: 4
|
154
156
|
summary: Complete geocoding solution for Ruby.
|