class Geocoder::Result::BanDataGouvFr
Public Class Methods
response_attributes()
click to toggle source
BASE METHODS ####
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 9 def self.response_attributes %w[limit attribution version licence type features] end
Public Instance Methods
administrative_weight()
click to toggle source
# 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()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 176 def city_code properties['citycode'] end
city_name()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 172 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 184 def context properties['context'].split(/,/).map(&:strip) end
coordinates()
click to toggle source
# 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()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 212 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 228 def country_code "FR" end
department_code()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 188 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 194 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 29 def geometry result['geometry'] if result end
international_address()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 152 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 135 def location_id properties['id'] end
national_address()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 156 def national_address properties['label'] end
population()
click to toggle source
CITIES' METHODS ####
# 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()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 180 def postal_code properties['postcode'] end
precision()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 33 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 86 def properties result['properties'] if result end
region_name()
click to toggle source
# 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
Also aliased as: state
result()
click to toggle source
BEST RESULT ####
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 23 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 148 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 131 def score properties['score'] end
street_address()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 160 def street_address properties['name'] end
street_name()
click to toggle source
# File lib/geocoder/results/ban_data_gouv_fr.rb, line 168 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 164 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 252 def city?(result_type) %w(village town city).include?(result_type) end