class Geocoder::Result::BanDataGouvFr
def self.response_attributes
def self.response_attributes %w[limit attribution version licence type features center] end
def administrative_weight
def administrative_weight properties['adm_weight'].to_i if city?(result_type) end
def city?(result_type)
def city?(result_type) result_type == 'municipality' end
def city_code
def city_code properties['citycode'] end
def city_name
def city_name properties['city'] end
def context
def context properties['context'].split(/,/).map(&:strip) end
def coordinates
def coordinates coords = geometry["coordinates"] return [coords[1].to_f, coords[0].to_f] end
def country
def country "France" end
def country_code
Will need refacto to handle different country codes, but BAN API
PF : Polynésie française
MU : Maurice
MQ : Martinique
GP : Guadeloupe
NC : Nouvelle-Calédonie
RE : Réunion
GF : Guyane Française
FR : France
Country code types
def country_code "FR" end
def department_code
def department_code context[0] if context.length > 0 end
def department_name
Monkey logic to handle fact Paris is both a city and a department
def department_name if context.length > 1 if context[1] == "Île-de-France" "Paris" else context[1] end end end
def geometry
def geometry result['geometry'] if result end
def international_address
def international_address "#{national_address}, #{country}" end
def location_id
def location_id properties['id'] end
def national_address
def national_address properties['label'] end
def population
def population (properties['population'].to_f * 1000).to_i if city?(result_type) end
def postal_code
def postal_code properties['postcode'] end
def precision
def precision geometry['type'] if geometry end
def properties
For up to date doc (in french only) : https://adresse.data.gouv.fr/api/
:population => [float] number of inhabitants with a 1000 factor
the city
:adm_weight => [string] administrative weight (importance) of
CITIES ONLY PROPERTIES
and country code
:label => [string] full address without state, country name
region code
:context => [string] department code, department name and
:city => [string] city name
consider it as a french institutional UUID)
:citycode => [string] city code (INSEE reference,
beware many cities got severeal postcodes)
:postcode => [string] city post code (used for mails by La Poste,
:name => [string] housenumber and street name
:street => [string] street name
(bis, ter, A, B)
:housenumber => [string] street number and extra information
relevancy
:score => [float] value between 0 and 1 giving result's
town, village, locality)
:type => [string] result type (housenumber, street, city,
l'information géographique et forestière)
atm, based on IGN reference (Institut national de
:id => [string] UUID of the result, said to be not stable
List of raw attrbutes returned by BAN data gouv fr API:
def properties result['properties'] if result end
def region_code
def region_code STATE_CODE_MAPPINGS[region_name] end
def region_name
def region_name if context.length == 2 && context[1] == "Île-de-France" context[1] elsif context.length > 2 context[2] end end
def result
def result features[0] if features.any? end
def result_type
locality
village
town
city
street
housenumber
Types
def result_type properties['type'] end
def score
from 6 (capital city) to 1 (regular village)
administrative_weight => [integer] city's importance on a scale
population => [string] city's inhabitants count
region_name => [string] city's region name
department_code => [string] city's department INSEE UUID
demartment_name => [string] city's department name
name and region name
context => [string] city's department code, department
postal_code => [string] city's postal code (used for mails)
city_code => [string] city's INSEE UUID
city_name => [string] city's name
street_name => [string] street's name
(bis, ter, etc)
street_number => [string] housenumber + extra inf
+ street name
street_address => [string] housenumber + extra inf
national_address => [string] full address with country code
international_address => [string] full address with country code
/ town / village / locality
result_type => [string] housenumber / street / city
location_id => [string] location's IGN UUID
score => [float] result relevance 0 to 1
List of usable Geocoder results' methods
def score properties['score'] end
def street_address
def street_address properties['name'] end
def street_name
def street_name properties['street'] end
def street_number
def street_number properties['housenumber'] end