class Geocoder::Result::BanDataGouvFr

Constants

STATE_CODE_MAPPINGS

Public Class Methods

response_attributes() click to toggle source

BASE METHODS ####

# File lib/geocoder/results/ban_data_gouv_fr.rb, line 30
def self.response_attributes
  %w[limit attribution version licence type features center]
end

Public Instance Methods

address()

ALIAS METHODS ####

administrative_weight() click to toggle source
# 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()
Alias for: city_name
city_code() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 197
def city_code
  properties['citycode']
end
city_name() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 193
def city_name
  properties['city']
end
Also aliased as: city
context() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 205
def context
  properties['context'].split(/,/).map(&:strip)
end
coordinates() click to toggle source
# 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() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 237
def country
  "France"
end
country_code() click to toggle source

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

# File lib/geocoder/results/ban_data_gouv_fr.rb, line 253
def country_code
  "FR"
end
department_code() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 209
def department_code
  context[0] if context.length > 0
end
department_name() click to toggle source

Monkey logic to handle fact Paris is both a city and a department in Île-de-France region

# 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() click to toggle source

GEOMETRY ####

# File lib/geocoder/results/ban_data_gouv_fr.rb, line 50
def geometry
  result['geometry'] if result
end
international_address() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 173
def international_address
  "#{national_address}, #{country}"
end
Also aliased as: address
location_id() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 156
def location_id
  properties['id']
end
national_address() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 177
def national_address
  properties['label']
end
population() click to toggle source

CITIES’ METHODS ####

# 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() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 201
def postal_code
  properties['postcode']
end
precision() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 54
def precision
  geometry['type'] if geometry
end
properties() click to toggle source

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/

# File lib/geocoder/results/ban_data_gouv_fr.rb, line 107
def properties
  result['properties'] if result
end
region_code() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 233
def region_code
  STATE_CODE_MAPPINGS[region_name]
end
Also aliased as: state_code
region_name() click to toggle source
# 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
Also aliased as: state
result() click to toggle source

BEST RESULT ####

# File lib/geocoder/results/ban_data_gouv_fr.rb, line 44
def result
  features[0] if features.any?
end
result_type() click to toggle source

Types

housenumber
street
city
town
village
locality
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 169
def result_type
  properties['type']
end
score() click to toggle source

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)
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 152
def score
  properties['score']
end
state()
Alias for: region_name
state_code()
Alias for: region_code
street()
Alias for: street_name
street_address() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 181
def street_address
  properties['name']
end
street_name() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 189
def street_name
  properties['street']
end
Also aliased as: street
street_number() click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 185
def street_number
  properties['housenumber']
end

Private Instance Methods

city?(result_type) click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 277
def city?(result_type)
  result_type == 'municipality'
end