geocoder 1.2.6 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +266 -1
- data/LICENSE +1 -1
- data/README.md +530 -804
- data/bin/console +13 -0
- data/examples/app_defined_lookup_services.rb +22 -0
- data/examples/reverse_geocode_job.rb +40 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +22 -16
- data/lib/generators/geocoder/maxmind/geolite_city_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/geolite_country_generator.rb +2 -0
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +1 -1
- data/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +1 -1
- data/lib/generators/geocoder/migration_version.rb +15 -0
- data/lib/geocoder/cache.rb +20 -33
- data/lib/geocoder/cache_stores/base.rb +40 -0
- data/lib/geocoder/cache_stores/generic.rb +35 -0
- data/lib/geocoder/cache_stores/redis.rb +34 -0
- data/lib/geocoder/calculations.rb +30 -38
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +36 -9
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/esri_token.rb +38 -0
- data/lib/geocoder/exceptions.rb +19 -0
- data/lib/geocoder/ip_address.rb +26 -11
- data/lib/geocoder/kernel_logger.rb +25 -0
- data/lib/geocoder/logger.rb +47 -0
- data/lib/geocoder/lookup.rb +63 -13
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/amap.rb +63 -0
- data/lib/geocoder/lookups/amazon_location_service.rb +55 -0
- data/lib/geocoder/lookups/baidu.rb +17 -9
- data/lib/geocoder/lookups/baidu_ip.rb +7 -31
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +143 -0
- data/lib/geocoder/lookups/base.rb +75 -26
- data/lib/geocoder/lookups/bing.rb +38 -15
- data/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +78 -12
- data/lib/geocoder/lookups/freegeoip.rb +22 -7
- data/lib/geocoder/lookups/geoapify.rb +78 -0
- data/lib/geocoder/lookups/geocoder_ca.rb +5 -6
- data/lib/geocoder/lookups/geocodio.rb +8 -8
- data/lib/geocoder/lookups/geoip2.rb +13 -4
- data/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/lib/geocoder/lookups/google.rb +44 -11
- data/lib/geocoder/lookups/google_places_details.rb +31 -17
- data/lib/geocoder/lookups/google_places_search.rb +76 -0
- data/lib/geocoder/lookups/google_premier.rb +15 -1
- data/lib/geocoder/lookups/here.rb +38 -27
- data/lib/geocoder/lookups/ip2location.rb +71 -0
- data/lib/geocoder/lookups/ipapi_com.rb +82 -0
- data/lib/geocoder/lookups/ipbase.rb +49 -0
- data/lib/geocoder/lookups/ipdata_co.rb +62 -0
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +44 -0
- data/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/ipstack.rb +63 -0
- data/lib/geocoder/lookups/latlon.rb +58 -0
- data/lib/geocoder/lookups/location_iq.rb +54 -0
- data/lib/geocoder/lookups/mapbox.rb +59 -0
- data/lib/geocoder/lookups/mapquest.rb +7 -9
- data/lib/geocoder/lookups/maxmind.rb +7 -7
- data/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
- data/lib/geocoder/lookups/maxmind_local.rb +16 -3
- data/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/nominatim.rb +18 -6
- data/lib/geocoder/lookups/opencagedata.rb +16 -9
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pc_miler.rb +85 -0
- data/lib/geocoder/lookups/pelias.rb +63 -0
- data/lib/geocoder/lookups/photon.rb +89 -0
- data/lib/geocoder/lookups/pickpoint.rb +41 -0
- data/lib/geocoder/lookups/pointpin.rb +14 -13
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +7 -8
- data/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/lib/geocoder/lookups/smarty_streets.rb +29 -6
- data/lib/geocoder/lookups/telize.rb +42 -7
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/test.rb +5 -0
- data/lib/geocoder/lookups/twogis.rb +58 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +20 -13
- data/lib/geocoder/models/active_record.rb +4 -3
- data/lib/geocoder/models/mongo_base.rb +0 -2
- data/lib/geocoder/query.rb +15 -1
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/request.rb +103 -14
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/amap.rb +87 -0
- data/lib/geocoder/results/amazon_location_service.rb +57 -0
- data/lib/geocoder/results/baidu.rb +10 -14
- data/lib/geocoder/results/ban_data_gouv_fr.rb +282 -0
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +5 -1
- data/lib/geocoder/results/db_ip_com.rb +58 -0
- data/lib/geocoder/results/esri.rb +35 -8
- data/lib/geocoder/results/freegeoip.rb +2 -7
- data/lib/geocoder/results/geoapify.rb +179 -0
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geocodio.rb +15 -3
- data/lib/geocoder/results/geoip2.rb +37 -25
- data/lib/geocoder/results/geoportail_lu.rb +71 -0
- data/lib/geocoder/results/google.rb +26 -0
- data/lib/geocoder/results/google_places_details.rb +4 -0
- data/lib/geocoder/results/google_places_search.rb +52 -0
- data/lib/geocoder/results/here.rb +30 -15
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipapi_com.rb +45 -0
- data/lib/geocoder/results/ipbase.rb +40 -0
- data/lib/geocoder/results/ipdata_co.rb +40 -0
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipinfo_io.rb +48 -0
- data/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/lib/geocoder/results/ipregistry.rb +304 -0
- data/lib/geocoder/results/ipstack.rb +60 -0
- data/lib/geocoder/results/latlon.rb +71 -0
- data/lib/geocoder/results/location_iq.rb +6 -0
- data/lib/geocoder/results/mapbox.rb +63 -0
- data/lib/geocoder/results/mapquest.rb +5 -8
- data/lib/geocoder/results/maxmind.rb +0 -5
- data/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/lib/geocoder/results/maxmind_local.rb +0 -5
- data/lib/geocoder/results/melissa_street.rb +46 -0
- data/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/lib/geocoder/results/nominatim.rb +41 -14
- data/lib/geocoder/results/opencagedata.rb +20 -2
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/pc_miler.rb +98 -0
- data/lib/geocoder/results/pelias.rb +58 -0
- data/lib/geocoder/results/photon.rb +119 -0
- data/lib/geocoder/results/pickpoint.rb +6 -0
- data/lib/geocoder/results/pointpin.rb +0 -4
- data/lib/geocoder/results/postcodes_io.rb +40 -0
- data/lib/geocoder/results/smarty_streets.rb +55 -19
- data/lib/geocoder/results/telize.rb +0 -5
- data/lib/geocoder/results/tencent.rb +72 -0
- data/lib/geocoder/results/test.rb +1 -1
- data/lib/geocoder/results/twogis.rb +76 -0
- data/lib/geocoder/results/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/results/yandex.rb +240 -32
- data/lib/geocoder/sql.rb +9 -6
- data/lib/geocoder/stores/active_record.rb +49 -10
- data/lib/geocoder/stores/base.rb +2 -14
- data/lib/geocoder/stores/mongo_base.rb +0 -31
- data/lib/geocoder/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- data/lib/geocoder.rb +2 -1
- data/lib/maxmind_database.rb +9 -9
- data/lib/tasks/geocoder.rake +29 -4
- data/lib/tasks/maxmind.rake +1 -1
- metadata +91 -169
- data/.gitignore +0 -6
- data/.travis.yml +0 -31
- data/Rakefile +0 -25
- data/examples/autoexpire_cache_dalli.rb +0 -62
- data/examples/autoexpire_cache_redis.rb +0 -28
- data/gemfiles/Gemfile.mongoid-2.4.x +0 -16
- data/lib/geocoder/lookups/geocoder_us.rb +0 -39
- data/lib/geocoder/lookups/okf.rb +0 -43
- data/lib/geocoder/lookups/ovi.rb +0 -62
- data/lib/geocoder/lookups/yahoo.rb +0 -88
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/geocoder/results/okf.rb +0 -106
- data/lib/geocoder/results/ovi.rb +0 -62
- data/lib/geocoder/results/yahoo.rb +0 -55
- data/lib/hash_recursive_merge.rb +0 -74
- data/lib/oauth_util.rb +0 -112
- data/test/fixtures/baidu_invalid_key +0 -1
- data/test/fixtures/baidu_ip_202_198_16_3 +0 -19
- data/test/fixtures/baidu_ip_invalid_key +0 -1
- data/test/fixtures/baidu_ip_no_results +0 -1
- data/test/fixtures/baidu_no_results +0 -1
- data/test/fixtures/baidu_reverse +0 -1
- data/test/fixtures/baidu_shanghai_pearl_tower +0 -12
- data/test/fixtures/bing_invalid_key +0 -1
- data/test/fixtures/bing_madison_square_garden +0 -40
- data/test/fixtures/bing_no_results +0 -16
- data/test/fixtures/bing_reverse +0 -42
- data/test/fixtures/cloudmade_invalid_key +0 -1
- data/test/fixtures/cloudmade_madison_square_garden +0 -1
- data/test/fixtures/cloudmade_no_results +0 -1
- data/test/fixtures/esri_madison_square_garden +0 -59
- data/test/fixtures/esri_no_results +0 -8
- data/test/fixtures/esri_reverse +0 -21
- data/test/fixtures/freegeoip_74_200_247_59 +0 -12
- data/test/fixtures/freegeoip_no_results +0 -1
- data/test/fixtures/geocoder_ca_madison_square_garden +0 -1
- data/test/fixtures/geocoder_ca_no_results +0 -1
- data/test/fixtures/geocoder_ca_reverse +0 -34
- data/test/fixtures/geocoder_us_madison_square_garden +0 -1
- data/test/fixtures/geocoder_us_no_results +0 -1
- data/test/fixtures/geocodio_1101_pennsylvania_ave +0 -1
- data/test/fixtures/geocodio_bad_api_key +0 -3
- data/test/fixtures/geocodio_invalid +0 -4
- data/test/fixtures/geocodio_no_results +0 -1
- data/test/fixtures/geocodio_over_query_limit +0 -4
- data/test/fixtures/google_garbage +0 -456
- data/test/fixtures/google_madison_square_garden +0 -57
- data/test/fixtures/google_no_city_data +0 -44
- data/test/fixtures/google_no_locality +0 -51
- data/test/fixtures/google_no_results +0 -4
- data/test/fixtures/google_over_limit +0 -4
- data/test/fixtures/google_places_details_invalid_request +0 -4
- data/test/fixtures/google_places_details_madison_square_garden +0 -120
- data/test/fixtures/google_places_details_no_results +0 -4
- data/test/fixtures/google_places_details_no_reviews +0 -60
- data/test/fixtures/google_places_details_no_types +0 -66
- data/test/fixtures/here_madison_square_garden +0 -72
- data/test/fixtures/here_no_results +0 -8
- data/test/fixtures/mapquest_error +0 -16
- data/test/fixtures/mapquest_invalid_api_key +0 -16
- data/test/fixtures/mapquest_invalid_request +0 -16
- data/test/fixtures/mapquest_madison_square_garden +0 -52
- data/test/fixtures/mapquest_no_results +0 -16
- data/test/fixtures/maxmind_24_24_24_21 +0 -1
- data/test/fixtures/maxmind_24_24_24_22 +0 -1
- data/test/fixtures/maxmind_24_24_24_23 +0 -1
- data/test/fixtures/maxmind_24_24_24_24 +0 -1
- data/test/fixtures/maxmind_74_200_247_59 +0 -1
- data/test/fixtures/maxmind_invalid_key +0 -1
- data/test/fixtures/maxmind_no_results +0 -1
- data/test/fixtures/nominatim_madison_square_garden +0 -150
- data/test/fixtures/nominatim_no_results +0 -1
- data/test/fixtures/nominatim_over_limit +0 -1
- data/test/fixtures/okf_kirstinmaki +0 -67
- data/test/fixtures/okf_no_results +0 -4
- data/test/fixtures/opencagedata_invalid_api_key +0 -25
- data/test/fixtures/opencagedata_invalid_request +0 -26
- data/test/fixtures/opencagedata_madison_square_garden +0 -73
- data/test/fixtures/opencagedata_no_results +0 -29
- data/test/fixtures/opencagedata_over_limit +0 -31
- data/test/fixtures/ovi_madison_square_garden +0 -72
- data/test/fixtures/ovi_no_results +0 -8
- data/test/fixtures/pointpin_10_10_10_10 +0 -1
- data/test/fixtures/pointpin_555_555_555_555 +0 -1
- data/test/fixtures/pointpin_80_111_555_555 +0 -1
- data/test/fixtures/pointpin_no_results +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_WR26NJ +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_generic_error +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_hampshire +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_key_limit_exceeded +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_no_results +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_romsey +0 -1
- data/test/fixtures/postcode_anywhere_uk_geocode_v2_00_unknown_key +0 -1
- data/test/fixtures/smarty_streets_11211 +0 -1
- data/test/fixtures/smarty_streets_madison_square_garden +0 -47
- data/test/fixtures/smarty_streets_no_results +0 -1
- data/test/fixtures/telize_10_10_10_10 +0 -1
- data/test/fixtures/telize_555_555_555_555 +0 -4
- data/test/fixtures/telize_74_200_247_59 +0 -1
- data/test/fixtures/telize_no_results +0 -1
- data/test/fixtures/yahoo_error +0 -1
- data/test/fixtures/yahoo_invalid_key +0 -2
- data/test/fixtures/yahoo_madison_square_garden +0 -52
- data/test/fixtures/yahoo_no_results +0 -10
- data/test/fixtures/yahoo_over_limit +0 -2
- data/test/fixtures/yandex_canada_rue_dupuis_14 +0 -446
- data/test/fixtures/yandex_invalid_key +0 -1
- data/test/fixtures/yandex_kremlin +0 -48
- data/test/fixtures/yandex_new_york +0 -1
- data/test/fixtures/yandex_no_city_and_town +0 -112
- data/test/fixtures/yandex_no_results +0 -16
- data/test/integration/http_client_test.rb +0 -31
- data/test/mongoid_test_helper.rb +0 -43
- data/test/test_helper.rb +0 -416
- data/test/unit/active_record_test.rb +0 -16
- data/test/unit/cache_test.rb +0 -37
- data/test/unit/calculations_test.rb +0 -220
- data/test/unit/configuration_test.rb +0 -55
- data/test/unit/error_handling_test.rb +0 -56
- data/test/unit/geocoder_test.rb +0 -78
- data/test/unit/https_test.rb +0 -17
- data/test/unit/ip_address_test.rb +0 -27
- data/test/unit/lookup_test.rb +0 -153
- data/test/unit/lookups/bing_test.rb +0 -68
- data/test/unit/lookups/dstk_test.rb +0 -26
- data/test/unit/lookups/esri_test.rb +0 -48
- data/test/unit/lookups/freegeoip_test.rb +0 -27
- data/test/unit/lookups/geocoder_ca_test.rb +0 -17
- data/test/unit/lookups/geocodio_test.rb +0 -55
- data/test/unit/lookups/geoip2_test.rb +0 -27
- data/test/unit/lookups/google_places_details_test.rb +0 -122
- data/test/unit/lookups/google_premier_test.rb +0 -22
- data/test/unit/lookups/google_test.rb +0 -84
- data/test/unit/lookups/mapquest_test.rb +0 -60
- data/test/unit/lookups/maxmind_local_test.rb +0 -28
- data/test/unit/lookups/maxmind_test.rb +0 -63
- data/test/unit/lookups/nominatim_test.rb +0 -31
- data/test/unit/lookups/okf_test.rb +0 -38
- data/test/unit/lookups/opencagedata_test.rb +0 -64
- data/test/unit/lookups/pointpin_test.rb +0 -30
- data/test/unit/lookups/postcode_anywhere_uk_test.rb +0 -70
- data/test/unit/lookups/smarty_streets_test.rb +0 -71
- data/test/unit/lookups/telize_test.rb +0 -36
- data/test/unit/lookups/yahoo_test.rb +0 -35
- data/test/unit/method_aliases_test.rb +0 -26
- data/test/unit/model_test.rb +0 -38
- data/test/unit/mongoid_test.rb +0 -47
- data/test/unit/near_test.rb +0 -87
- data/test/unit/oauth_util_test.rb +0 -31
- data/test/unit/proxy_test.rb +0 -37
- data/test/unit/query_test.rb +0 -52
- data/test/unit/rake_task_test.rb +0 -21
- data/test/unit/request_test.rb +0 -35
- data/test/unit/result_test.rb +0 -72
- data/test/unit/test_mode_test.rb +0 -70
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'geocoder/results/base'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Result
|
|
5
|
+
class BanDataGouvFr < Base
|
|
6
|
+
|
|
7
|
+
STATE_CODE_MAPPINGS = {
|
|
8
|
+
"Guadeloupe" => "01",
|
|
9
|
+
"Martinique" => "02",
|
|
10
|
+
"Guyane" => "03",
|
|
11
|
+
"La Réunion" => "04",
|
|
12
|
+
"Mayotte" => "06",
|
|
13
|
+
"Île-de-France" => "11",
|
|
14
|
+
"Centre-Val de Loire" => "24",
|
|
15
|
+
"Bourgogne-Franche-Comté" => "27",
|
|
16
|
+
"Normandie" => "28",
|
|
17
|
+
"Hauts-de-France" => "32",
|
|
18
|
+
"Grand Est" => "44",
|
|
19
|
+
"Pays de la Loire" => "52",
|
|
20
|
+
"Bretagne" => "53",
|
|
21
|
+
"Nouvelle-Aquitaine" => "75",
|
|
22
|
+
"Occitanie" => "76",
|
|
23
|
+
"Auvergne-Rhône-Alpes" => "84",
|
|
24
|
+
"Provence-Alpes-Côte d'Azur" => "93",
|
|
25
|
+
"Corse" => "94"
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
#### BASE METHODS ####
|
|
29
|
+
|
|
30
|
+
def self.response_attributes
|
|
31
|
+
%w[limit attribution version licence type features center]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
response_attributes.each do |a|
|
|
35
|
+
unless method_defined?(a)
|
|
36
|
+
define_method a do
|
|
37
|
+
@data[a]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
#### BEST RESULT ####
|
|
43
|
+
|
|
44
|
+
def result
|
|
45
|
+
features[0] if features.any?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
#### GEOMETRY ####
|
|
49
|
+
|
|
50
|
+
def geometry
|
|
51
|
+
result['geometry'] if result
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def precision
|
|
55
|
+
geometry['type'] if geometry
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def coordinates
|
|
59
|
+
coords = geometry["coordinates"]
|
|
60
|
+
return [coords[1].to_f, coords[0].to_f]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
#### PROPERTIES ####
|
|
64
|
+
|
|
65
|
+
# List of raw attrbutes returned by BAN data gouv fr API:
|
|
66
|
+
#
|
|
67
|
+
# :id => [string] UUID of the result, said to be not stable
|
|
68
|
+
# atm, based on IGN reference (Institut national de
|
|
69
|
+
# l'information géographique et forestière)
|
|
70
|
+
#
|
|
71
|
+
# :type => [string] result type (housenumber, street, city,
|
|
72
|
+
# town, village, locality)
|
|
73
|
+
#
|
|
74
|
+
# :score => [float] value between 0 and 1 giving result's
|
|
75
|
+
# relevancy
|
|
76
|
+
#
|
|
77
|
+
# :housenumber => [string] street number and extra information
|
|
78
|
+
# (bis, ter, A, B)
|
|
79
|
+
#
|
|
80
|
+
# :street => [string] street name
|
|
81
|
+
#
|
|
82
|
+
# :name => [string] housenumber and street name
|
|
83
|
+
#
|
|
84
|
+
# :postcode => [string] city post code (used for mails by La Poste,
|
|
85
|
+
# beware many cities got severeal postcodes)
|
|
86
|
+
#
|
|
87
|
+
# :citycode => [string] city code (INSEE reference,
|
|
88
|
+
# consider it as a french institutional UUID)
|
|
89
|
+
#
|
|
90
|
+
# :city => [string] city name
|
|
91
|
+
#
|
|
92
|
+
# :context => [string] department code, department name and
|
|
93
|
+
# region code
|
|
94
|
+
#
|
|
95
|
+
# :label => [string] full address without state, country name
|
|
96
|
+
# and country code
|
|
97
|
+
#
|
|
98
|
+
# CITIES ONLY PROPERTIES
|
|
99
|
+
#
|
|
100
|
+
# :adm_weight => [string] administrative weight (importance) of
|
|
101
|
+
# the city
|
|
102
|
+
#
|
|
103
|
+
# :population => [float] number of inhabitants with a 1000 factor
|
|
104
|
+
#
|
|
105
|
+
# For up to date doc (in french only) : https://adresse.data.gouv.fr/api/
|
|
106
|
+
#
|
|
107
|
+
def properties
|
|
108
|
+
result['properties'] if result
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# List of usable Geocoder results' methods
|
|
112
|
+
#
|
|
113
|
+
# score => [float] result relevance 0 to 1
|
|
114
|
+
#
|
|
115
|
+
# location_id => [string] location's IGN UUID
|
|
116
|
+
#
|
|
117
|
+
# result_type => [string] housenumber / street / city
|
|
118
|
+
# / town / village / locality
|
|
119
|
+
#
|
|
120
|
+
# international_address => [string] full address with country code
|
|
121
|
+
#
|
|
122
|
+
# national_address => [string] full address with country code
|
|
123
|
+
#
|
|
124
|
+
# street_address => [string] housenumber + extra inf
|
|
125
|
+
# + street name
|
|
126
|
+
#
|
|
127
|
+
# street_number => [string] housenumber + extra inf
|
|
128
|
+
# (bis, ter, etc)
|
|
129
|
+
#
|
|
130
|
+
# street_name => [string] street's name
|
|
131
|
+
#
|
|
132
|
+
# city_name => [string] city's name
|
|
133
|
+
#
|
|
134
|
+
# city_code => [string] city's INSEE UUID
|
|
135
|
+
#
|
|
136
|
+
# postal_code => [string] city's postal code (used for mails)
|
|
137
|
+
#
|
|
138
|
+
# context => [string] city's department code, department
|
|
139
|
+
# name and region name
|
|
140
|
+
#
|
|
141
|
+
# demartment_name => [string] city's department name
|
|
142
|
+
#
|
|
143
|
+
# department_code => [string] city's department INSEE UUID
|
|
144
|
+
#
|
|
145
|
+
# region_name => [string] city's region name
|
|
146
|
+
#
|
|
147
|
+
# population => [string] city's inhabitants count
|
|
148
|
+
#
|
|
149
|
+
# administrative_weight => [integer] city's importance on a scale
|
|
150
|
+
# from 6 (capital city) to 1 (regular village)
|
|
151
|
+
#
|
|
152
|
+
def score
|
|
153
|
+
properties['score']
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def location_id
|
|
157
|
+
properties['id']
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Types
|
|
161
|
+
#
|
|
162
|
+
# housenumber
|
|
163
|
+
# street
|
|
164
|
+
# city
|
|
165
|
+
# town
|
|
166
|
+
# village
|
|
167
|
+
# locality
|
|
168
|
+
#
|
|
169
|
+
def result_type
|
|
170
|
+
properties['type']
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def international_address
|
|
174
|
+
"#{national_address}, #{country}"
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def national_address
|
|
178
|
+
properties['label']
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def street_address
|
|
182
|
+
properties['name']
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def street_number
|
|
186
|
+
properties['housenumber']
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def street_name
|
|
190
|
+
properties['street']
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def city_name
|
|
194
|
+
properties['city']
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def city_code
|
|
198
|
+
properties['citycode']
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def postal_code
|
|
202
|
+
properties['postcode']
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def context
|
|
206
|
+
properties['context'].split(/,/).map(&:strip)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def department_code
|
|
210
|
+
context[0] if context.length > 0
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Monkey logic to handle fact Paris is both a city and a department
|
|
214
|
+
# in Île-de-France region
|
|
215
|
+
def department_name
|
|
216
|
+
if context.length > 1
|
|
217
|
+
if context[1] == "Île-de-France"
|
|
218
|
+
"Paris"
|
|
219
|
+
else
|
|
220
|
+
context[1]
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def region_name
|
|
226
|
+
if context.length == 2 && context[1] == "Île-de-France"
|
|
227
|
+
context[1]
|
|
228
|
+
elsif context.length > 2
|
|
229
|
+
context[2]
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def region_code
|
|
234
|
+
STATE_CODE_MAPPINGS[region_name]
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def country
|
|
238
|
+
"France"
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# Country code types
|
|
242
|
+
# FR : France
|
|
243
|
+
# GF : Guyane Française
|
|
244
|
+
# RE : Réunion
|
|
245
|
+
# NC : Nouvelle-Calédonie
|
|
246
|
+
# GP : Guadeloupe
|
|
247
|
+
# MQ : Martinique
|
|
248
|
+
# MU : Maurice
|
|
249
|
+
# PF : Polynésie française
|
|
250
|
+
#
|
|
251
|
+
# Will need refacto to handle different country codes, but BAN API
|
|
252
|
+
# is currently mainly designed for geocode FR country code addresses
|
|
253
|
+
def country_code
|
|
254
|
+
"FR"
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
#### ALIAS METHODS ####
|
|
258
|
+
|
|
259
|
+
alias_method :address, :international_address
|
|
260
|
+
alias_method :street, :street_name
|
|
261
|
+
alias_method :city, :city_name
|
|
262
|
+
alias_method :state, :region_name
|
|
263
|
+
alias_method :state_code, :region_code
|
|
264
|
+
|
|
265
|
+
#### CITIES' METHODS ####
|
|
266
|
+
|
|
267
|
+
def population
|
|
268
|
+
(properties['population'].to_f * 1000).to_i if city?(result_type)
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
def administrative_weight
|
|
272
|
+
properties['adm_weight'].to_i if city?(result_type)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
private
|
|
276
|
+
|
|
277
|
+
def city?(result_type)
|
|
278
|
+
result_type == 'municipality'
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
end
|
|
282
|
+
end
|
|
@@ -20,8 +20,20 @@ module Geocoder
|
|
|
20
20
|
##
|
|
21
21
|
# A string in the given format.
|
|
22
22
|
#
|
|
23
|
+
# This default implementation dumbly follows the United States address
|
|
24
|
+
# format and will return incorrect results for most countries. Some APIs
|
|
25
|
+
# return properly formatted addresses and those should be funneled
|
|
26
|
+
# through this method.
|
|
27
|
+
#
|
|
23
28
|
def address(format = :full)
|
|
24
|
-
|
|
29
|
+
if state_code.to_s != ""
|
|
30
|
+
s = ", #{state_code}"
|
|
31
|
+
elsif state.to_s != ""
|
|
32
|
+
s = ", #{state}"
|
|
33
|
+
else
|
|
34
|
+
s = ""
|
|
35
|
+
end
|
|
36
|
+
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
|
|
25
37
|
end
|
|
26
38
|
|
|
27
39
|
##
|
|
@@ -24,7 +24,7 @@ module Geocoder::Result
|
|
|
24
24
|
alias_method :country_code, :country
|
|
25
25
|
|
|
26
26
|
def postal_code
|
|
27
|
-
@data['address']['postalCode']
|
|
27
|
+
@data['address']['postalCode'].to_s
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def coordinates
|
|
@@ -35,6 +35,10 @@ module Geocoder::Result
|
|
|
35
35
|
@data['address']
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
def viewport
|
|
39
|
+
@data['bbox']
|
|
40
|
+
end
|
|
41
|
+
|
|
38
42
|
def self.response_attributes
|
|
39
43
|
%w[bbox name confidence entityType]
|
|
40
44
|
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'geocoder/results/base'
|
|
2
|
+
|
|
3
|
+
module Geocoder::Result
|
|
4
|
+
class DbIpCom < Base
|
|
5
|
+
|
|
6
|
+
def coordinates
|
|
7
|
+
['latitude', 'longitude'].map{ |coordinate_name| @data[coordinate_name] }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def city
|
|
11
|
+
@data['city']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def district
|
|
15
|
+
@data['district']
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def state_code
|
|
19
|
+
@data['stateProvCode']
|
|
20
|
+
end
|
|
21
|
+
alias_method :state, :state_code
|
|
22
|
+
|
|
23
|
+
def zip_code
|
|
24
|
+
@data['zipCode']
|
|
25
|
+
end
|
|
26
|
+
alias_method :postal_code, :zip_code
|
|
27
|
+
|
|
28
|
+
def country_name
|
|
29
|
+
@data['countryName']
|
|
30
|
+
end
|
|
31
|
+
alias_method :country, :country_name
|
|
32
|
+
|
|
33
|
+
def country_code
|
|
34
|
+
@data['countryCode']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def continent_name
|
|
38
|
+
@data['continentName']
|
|
39
|
+
end
|
|
40
|
+
alias_method :continent, :continent_name
|
|
41
|
+
|
|
42
|
+
def continent_code
|
|
43
|
+
@data['continentCode']
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def time_zone
|
|
47
|
+
@data['timeZone']
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def gmt_offset
|
|
51
|
+
@data['gmtOffset']
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def currency_code
|
|
55
|
+
@data['currencyCode']
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -4,23 +4,30 @@ 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
|
+
place_name
|
|
14
|
+
else
|
|
15
|
+
attributes['City']
|
|
16
|
+
end
|
|
13
17
|
end
|
|
14
18
|
|
|
15
|
-
def
|
|
19
|
+
def state
|
|
16
20
|
attributes['Region']
|
|
17
21
|
end
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
def state_code
|
|
24
|
+
abbr = attributes['RegionAbbr']
|
|
25
|
+
abbr.to_s == "" ? state : abbr
|
|
26
|
+
end
|
|
20
27
|
|
|
21
28
|
def country
|
|
22
|
-
|
|
23
|
-
attributes[
|
|
29
|
+
country_key = reverse_geocode? ? "CountryCode" : "Country"
|
|
30
|
+
attributes[country_key]
|
|
24
31
|
end
|
|
25
32
|
|
|
26
33
|
alias_method :country_code, :country
|
|
@@ -29,10 +36,27 @@ module Geocoder::Result
|
|
|
29
36
|
attributes['Postal']
|
|
30
37
|
end
|
|
31
38
|
|
|
39
|
+
def place_name
|
|
40
|
+
place_name_key = reverse_geocode? ? "Address" : "PlaceName"
|
|
41
|
+
attributes[place_name_key]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def place_type
|
|
45
|
+
reverse_geocode? ? "Address" : attributes['Type']
|
|
46
|
+
end
|
|
47
|
+
|
|
32
48
|
def coordinates
|
|
33
49
|
[geometry["y"], geometry["x"]]
|
|
34
50
|
end
|
|
35
51
|
|
|
52
|
+
def viewport
|
|
53
|
+
north = attributes['Ymax']
|
|
54
|
+
south = attributes['Ymin']
|
|
55
|
+
east = attributes['Xmax']
|
|
56
|
+
west = attributes['Xmin']
|
|
57
|
+
[south, west, north, east]
|
|
58
|
+
end
|
|
59
|
+
|
|
36
60
|
private
|
|
37
61
|
|
|
38
62
|
def attributes
|
|
@@ -47,5 +71,8 @@ module Geocoder::Result
|
|
|
47
71
|
@data['locations'].nil?
|
|
48
72
|
end
|
|
49
73
|
|
|
74
|
+
def is_city?
|
|
75
|
+
['City', 'State Capital', 'National Capital'].include?(place_type)
|
|
76
|
+
end
|
|
50
77
|
end
|
|
51
|
-
end
|
|
78
|
+
end
|
|
@@ -3,11 +3,6 @@ require 'geocoder/results/base'
|
|
|
3
3
|
module Geocoder::Result
|
|
4
4
|
class Freegeoip < Base
|
|
5
5
|
|
|
6
|
-
def address(format = :full)
|
|
7
|
-
s = state_code.to_s == "" ? "" : ", #{state_code}"
|
|
8
|
-
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
|
9
|
-
end
|
|
10
|
-
|
|
11
6
|
def city
|
|
12
7
|
@data['city']
|
|
13
8
|
end
|
|
@@ -29,11 +24,11 @@ module Geocoder::Result
|
|
|
29
24
|
end
|
|
30
25
|
|
|
31
26
|
def postal_code
|
|
32
|
-
@data['zipcode']
|
|
27
|
+
@data['zipcode'] || @data['zip_code']
|
|
33
28
|
end
|
|
34
29
|
|
|
35
30
|
def self.response_attributes
|
|
36
|
-
%w[
|
|
31
|
+
%w[metro_code ip]
|
|
37
32
|
end
|
|
38
33
|
|
|
39
34
|
response_attributes.each do |a|
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'geocoder/results/base'
|
|
4
|
+
|
|
5
|
+
module Geocoder
|
|
6
|
+
module Result
|
|
7
|
+
# https://apidocs.geoapify.com/docs/geocoding/api
|
|
8
|
+
class Geoapify < Base
|
|
9
|
+
def address(_format = :full)
|
|
10
|
+
properties['formatted']
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def address_line1
|
|
14
|
+
properties['address_line1']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def address_line2
|
|
18
|
+
properties['address_line2']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def house_number
|
|
22
|
+
properties['housenumber']
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def street
|
|
26
|
+
properties['street']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def postal_code
|
|
30
|
+
properties['postcode']
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def district
|
|
34
|
+
properties['district']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def suburb
|
|
38
|
+
properties['suburb']
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def city
|
|
42
|
+
properties['city']
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def county
|
|
46
|
+
properties['county']
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def state
|
|
50
|
+
properties['state']
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Not currently available in the API
|
|
54
|
+
def state_code
|
|
55
|
+
''
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def country
|
|
59
|
+
properties['country']
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def country_code
|
|
63
|
+
return unless properties['country_code']
|
|
64
|
+
|
|
65
|
+
properties['country_code'].upcase
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def coordinates
|
|
69
|
+
return unless properties['lat']
|
|
70
|
+
return unless properties['lon']
|
|
71
|
+
|
|
72
|
+
[properties['lat'], properties['lon']]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# See: https://tools.ietf.org/html/rfc7946#section-3.1
|
|
76
|
+
#
|
|
77
|
+
# Each feature has a "Point" type in the Geoapify API.
|
|
78
|
+
def geometry
|
|
79
|
+
return unless data['geometry']
|
|
80
|
+
|
|
81
|
+
symbol_hash data['geometry']
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# See: https://tools.ietf.org/html/rfc7946#section-5
|
|
85
|
+
def bounds
|
|
86
|
+
data['bbox']
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Type of the result, one of:
|
|
90
|
+
#
|
|
91
|
+
# * :unknown
|
|
92
|
+
# * :amenity
|
|
93
|
+
# * :building
|
|
94
|
+
# * :street
|
|
95
|
+
# * :suburb
|
|
96
|
+
# * :district
|
|
97
|
+
# * :postcode
|
|
98
|
+
# * :city
|
|
99
|
+
# * :county
|
|
100
|
+
# * :state
|
|
101
|
+
# * :country
|
|
102
|
+
#
|
|
103
|
+
def type
|
|
104
|
+
return :unknown unless properties['result_type']
|
|
105
|
+
|
|
106
|
+
properties['result_type'].to_sym
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Distance in meters to given bias:proximity or to given coordinates for
|
|
110
|
+
# reverse geocoding
|
|
111
|
+
def distance
|
|
112
|
+
properties['distance']
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Calculated rank for the result, containing the following keys:
|
|
116
|
+
#
|
|
117
|
+
# * `popularity` - The popularity score of the result
|
|
118
|
+
# * `confidence` - The confidence value of the result (0-1)
|
|
119
|
+
# * `match_type` - The result's match type, one of following:
|
|
120
|
+
# * full_match
|
|
121
|
+
# * inner_part
|
|
122
|
+
# * match_by_building
|
|
123
|
+
# * match_by_street
|
|
124
|
+
# * match_by_postcode
|
|
125
|
+
# * match_by_city_or_disrict
|
|
126
|
+
# * match_by_country_or_state
|
|
127
|
+
#
|
|
128
|
+
# Example:
|
|
129
|
+
# {
|
|
130
|
+
# popularity: 8.615793062435909,
|
|
131
|
+
# confidence: 0.88,
|
|
132
|
+
# match_type: :full_match
|
|
133
|
+
# }
|
|
134
|
+
def rank
|
|
135
|
+
return unless properties['rank']
|
|
136
|
+
|
|
137
|
+
r = symbol_hash(properties['rank'])
|
|
138
|
+
r[:match_type] = r[:match_type].to_sym if r[:match_type]
|
|
139
|
+
r
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Examples:
|
|
143
|
+
#
|
|
144
|
+
# Open
|
|
145
|
+
# {
|
|
146
|
+
# sourcename: 'openstreetmap',
|
|
147
|
+
# wheelchair: 'limited',
|
|
148
|
+
# wikidata: 'Q186125',
|
|
149
|
+
# wikipedia: 'en:Madison Square Garden',
|
|
150
|
+
# website: 'http://www.thegarden.com/',
|
|
151
|
+
# phone: '12124656741',
|
|
152
|
+
# osm_type: 'W',
|
|
153
|
+
# osm_id: 138141251,
|
|
154
|
+
# continent: 'North America',
|
|
155
|
+
# }
|
|
156
|
+
def datasource
|
|
157
|
+
return unless properties['datasource']
|
|
158
|
+
|
|
159
|
+
symbol_hash properties['datasource']
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
private
|
|
163
|
+
|
|
164
|
+
def properties
|
|
165
|
+
@properties ||= data['properties'] || {}
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def symbol_hash(orig_hash)
|
|
169
|
+
{}.tap do |result|
|
|
170
|
+
orig_hash.each_key do |key|
|
|
171
|
+
next unless orig_hash[key]
|
|
172
|
+
|
|
173
|
+
result[key.to_sym] = orig_hash[key]
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -16,17 +16,17 @@ module Geocoder::Result
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def city
|
|
19
|
-
@data['city']
|
|
19
|
+
@data['city'] or (@data['standard'] and @data['standard']['city']) or ""
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def state
|
|
23
|
-
@data['prov']
|
|
23
|
+
@data['prov'] or (@data['standard'] and @data['standard']['prov']) or ""
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
alias_method :state_code, :state
|
|
27
27
|
|
|
28
28
|
def postal_code
|
|
29
|
-
@data['postal']
|
|
29
|
+
@data['postal'] or (@data['standard'] and @data['standard']['postal']) or ""
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def country
|