Class: Geocoder::Result::BanDataGouvFr

Inherits:
Base
  • Object
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

Constructor Details

This class inherits a constructor from Geocoder::Result::Base

Class Method Details

.response_attributesObject

BASE METHODS ####


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 center]
end

Instance Method Details

#administrative_weightObject


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_codeObject


176
177
178
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 176

def city_code
  properties['citycode']
end

#city_nameObject Also known as: city


172
173
174
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 172

def city_name
  properties['city']
end

#contextObject


184
185
186
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 184

def context
  properties['context'].split(/,/).map(&:strip)
end

#coordinatesObject


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

#countryObject


212
213
214
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 212

def country
  "France"
end

#country_codeObject

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_codeObject


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_nameObject

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

#geometryObject

GEOMETRY ####


29
30
31
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 29

def geometry
  result['geometry'] if result
end

#international_addressObject 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_idObject


135
136
137
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 135

def location_id
  properties['id']
end

#national_addressObject


156
157
158
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 156

def national_address
  properties['label']
end

#populationObject

CITIES' METHODS ####


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_codeObject


180
181
182
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 180

def postal_code
  properties['postcode']
end

#precisionObject


33
34
35
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 33

def precision
  geometry['type'] if geometry
end

#propertiesObject

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_nameObject 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

#resultObject

BEST RESULT ####


23
24
25
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 23

def result
  features[0] if features.any?
end

#result_typeObject

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

#scoreObject

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_addressObject


160
161
162
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 160

def street_address
  properties['name']
end

#street_nameObject 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_numberObject


164
165
166
# File 'lib/geocoder/results/ban_data_gouv_fr.rb', line 164

def street_number
  properties['housenumber']
end