Class: Geocoder::Result::BanDataGouvFr
- Inherits:
-
Base
- Object
- Base
- Geocoder::Result::BanDataGouvFr
show all
- Defined in:
- lib/geocoder/results/ban_data_gouv_fr.rb
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
9
10
11
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 9
def self.response_attributes
%w[limit attribution version licence type features]
end
|
Instance Method Details
#administrative_weight ⇒ Object
246
247
248
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 246
def administrative_weight
properties['adm_weight'].to_i if city?(result_type)
end
|
#city_code ⇒ Object
176
177
178
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 176
def city_code
properties['citycode']
end
|
#city_name ⇒ Object
Also known as:
city
172
173
174
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 172
def city_name
properties['city']
end
|
#context ⇒ Object
184
185
186
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 184
def context
properties['context'].split(/,/).map(&:strip)
end
|
#coordinates ⇒ Object
37
38
39
40
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 37
def coordinates
coords = geometry["coordinates"]
return [coords[1].to_f, coords[0].to_f]
end
|
#country ⇒ Object
212
213
214
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 212
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
228
229
230
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 228
def country_code
"FR"
end
|
#department_code ⇒ Object
188
189
190
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 188
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
194
195
196
197
198
199
200
201
202
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 194
def department_name
if context.length > 1
if context[1] == "Île-de-France"
"Paris"
else
context[1]
end
end
end
|
#geometry ⇒ Object
29
30
31
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 29
def geometry
result['geometry'] if result
end
|
#international_address ⇒ Object
Also known as:
address
152
153
154
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 152
def international_address
"#{national_address}, #{country}"
end
|
#location_id ⇒ Object
135
136
137
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 135
def location_id
properties['id']
end
|
#national_address ⇒ Object
156
157
158
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 156
def national_address
properties['label']
end
|
#population ⇒ Object
242
243
244
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 242
def population
(properties['population'].to_f * 1000).to_i if city?(result_type)
end
|
#postal_code ⇒ Object
180
181
182
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 180
def postal_code
properties['postcode']
end
|
#precision ⇒ Object
33
34
35
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 33
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/
86
87
88
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 86
def properties
result['properties'] if result
end
|
#region_name ⇒ Object
Also known as:
state
204
205
206
207
208
209
210
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 204
def region_name
if context.length == 2 && context[1] == "Île-de-France"
context[1]
elsif context.length > 2
context[2]
end
end
|
#result ⇒ Object
23
24
25
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 23
def result
features[0] if features.any?
end
|
#result_type ⇒ Object
Types
housenumber
street
city
town
village
locality
148
149
150
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 148
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)
131
132
133
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 131
def score
properties['score']
end
|
#street_address ⇒ Object
160
161
162
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 160
def street_address
properties['name']
end
|
#street_name ⇒ Object
Also known as:
street
168
169
170
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 168
def street_name
properties['street']
end
|
#street_number ⇒ Object
164
165
166
|
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 164
def street_number
properties['housenumber']
end
|