Class: Geocoder::Result::BanDataGouvFr
- Inherits:
-
Base
- Object
- Base
- Geocoder::Result::BanDataGouvFr
show all
- Defined in:
- lib/geocoder/results/ban_data_gouv_fr.rb
Constant Summary
collapse
- STATE_CODE_MAPPINGS =
{
"Guadeloupe" => "01",
"Martinique" => "02",
"Guyane" => "03",
"La Réunion" => "04",
"Mayotte" => "06",
"Île-de-France" => "11",
"Centre-Val de Loire" => "24",
"Bourgogne-Franche-Comté" => "27",
"Normandie" => "28",
"Hauts-de-France" => "32",
"Grand Est" => "44",
"Pays de la Loire" => "52",
"Bretagne" => "53",
"Nouvelle-Aquitaine" => "75",
"Occitanie" => "76",
"Auvergne-Rhône-Alpes" => "84",
"Provence-Alpes-Côte d'Azur" => "93",
"Corse" => "94"
}.freeze
Instance Attribute Summary
Attributes inherited from Base
#cache_hit, #data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #latitude, #longitude, #province, #province_code
Class Method Details
.response_attributes ⇒ Object
30
31
32
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 30
def self.response_attributes
%w[limit attribution version licence type features center]
end
|
Instance Method Details
#administrative_weight ⇒ Object
271
272
273
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 271
def administrative_weight
properties['adm_weight'].to_i if city?(result_type)
end
|
#city_code ⇒ Object
197
198
199
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 197
def city_code
properties['citycode']
end
|
#city_name ⇒ Object
Also known as:
city
193
194
195
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 193
def city_name
properties['city']
end
|
#context ⇒ Object
205
206
207
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 205
def context
properties['context'].split(/,/).map(&:strip)
end
|
#coordinates ⇒ Object
58
59
60
61
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 58
def coordinates
coords = geometry["coordinates"]
return [coords[1].to_f, coords[0].to_f]
end
|
#country ⇒ Object
237
238
239
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 237
def country
"France"
end
|
#country_code ⇒ Object
Country code types
FR : France
GF : Guyane Française
RE : Réunion
NC : Nouvelle-Calédonie
GP : Guadeloupe
MQ : Martinique
MU : Maurice
PF : Polynésie française
Will need refacto to handle different country codes, but BAN API is currently mainly designed for geocode FR country code addresses
253
254
255
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 253
def country_code
"FR"
end
|
#department_code ⇒ Object
209
210
211
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 209
def department_code
context[0] if context.length > 0
end
|
#department_name ⇒ Object
Monkey logic to handle fact Paris is both a city and a department in Île-de-France region
215
216
217
218
219
220
221
222
223
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 215
def department_name
if context.length > 1
if context[1] == "Île-de-France"
"Paris"
else
context[1]
end
end
end
|
#geometry ⇒ Object
50
51
52
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 50
def geometry
result['geometry'] if result
end
|
#international_address ⇒ Object
Also known as:
address
173
174
175
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 173
def international_address
"#{national_address}, #{country}"
end
|
#location_id ⇒ Object
156
157
158
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 156
def location_id
properties['id']
end
|
#national_address ⇒ Object
177
178
179
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 177
def national_address
properties['label']
end
|
#population ⇒ Object
267
268
269
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 267
def population
(properties['population'].to_f * 1000).to_i if city?(result_type)
end
|
#postal_code ⇒ Object
201
202
203
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 201
def postal_code
properties['postcode']
end
|
#precision ⇒ Object
54
55
56
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 54
def precision
geometry['type'] if geometry
end
|
#properties ⇒ Object
List of raw attrbutes returned by BAN data gouv fr API:
:id => [string] UUID of the result, said to be not stable
atm, based on IGN reference (Institut national de
l'information géographique et forestière)
:type => [string] result type (housenumber, street, city,
town, village, locality)
:score => [float] value between 0 and 1 giving result's
relevancy
:housenumber => [string] street number and extra information
(bis, ter, A, B)
:street => [string] street name
:name => [string] housenumber and street name
:postcode => [string] city post code (used for mails by La Poste,
beware many cities got severeal postcodes)
:citycode => [string] city code (INSEE reference,
consider it as a french institutional UUID)
:city => [string] city name
:context => [string] department code, department name and
region code
:label => [string] full address without state, country name
and country code
CITIES ONLY PROPERTIES
:adm_weight => [string] administrative weight (importance) of
the city
:population => [float] number of inhabitants with a 1000 factor
For up to date doc (in french only) : adresse.data.gouv.fr/api/
107
108
109
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 107
def properties
result['properties'] if result
end
|
#region_code ⇒ Object
Also known as:
state_code
233
234
235
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 233
def region_code
STATE_CODE_MAPPINGS[region_name]
end
|
#region_name ⇒ Object
Also known as:
state
225
226
227
228
229
230
231
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 225
def region_name
if context.length == 2 && context[1] == "Île-de-France"
context[1]
elsif context.length > 2
context[2]
end
end
|
#result ⇒ Object
44
45
46
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 44
def result
features[0] if features.any?
end
|
#result_type ⇒ Object
Types
housenumber
street
city
town
village
locality
169
170
171
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 169
def result_type
properties['type']
end
|
#score ⇒ Object
List of usable Geocoder results’ methods
score => [float] result relevance 0 to 1
location_id => [string] location's IGN UUID
result_type => [string] housenumber / street / city
/ town / village / locality
international_address => [string] full address with country code
national_address => [string] full address with country code
street_address => [string] housenumber + extra inf
+ street name
street_number => [string] housenumber + extra inf
(bis, ter, etc)
street_name => [string] street's name
city_name => [string] city's name
city_code => [string] city's INSEE UUID
postal_code => [string] city's postal code (used for mails)
context => [string] city's department code, department
name and region name
demartment_name => [string] city's department name
department_code => [string] city's department INSEE UUID
region_name => [string] city's region name
population => [string] city's inhabitants count
administrative_weight => [integer] city's importance on a scale
from 6 (capital city) to 1 (regular village)
152
153
154
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 152
def score
properties['score']
end
|
#street_address ⇒ Object
181
182
183
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 181
def street_address
properties['name']
end
|
#street_name ⇒ Object
Also known as:
street
189
190
191
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 189
def street_name
properties['street']
end
|
#street_number ⇒ Object
185
186
187
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 185
def street_number
properties['housenumber']
end
|