-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2892 from tchak/carte-rpg
Add RPG carte source
- Loading branch information
Showing
29 changed files
with
404 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,49 @@ | ||
class ApiGeo::API | ||
TIMEOUT = 15 | ||
|
||
def self.regions | ||
url = [API_GEO_URL, "regions"].join("/") | ||
call(url) | ||
call(url, { fields: :nom }) | ||
end | ||
|
||
def self.departements | ||
url = [API_GEO_URL, "departements"].join("/") | ||
call(url) | ||
call(url, { fields: :nom }) | ||
end | ||
|
||
def self.pays | ||
File.open('app/lib/api_geo/pays.json').read | ||
parse(File.open('app/lib/api_geo/pays.json').read) | ||
end | ||
|
||
def self.search_rpg(geojson) | ||
url = [API_GEO_SANDBOX_URL, "rpg", "parcelles", "search"].join("/") | ||
call(url, geojson, :post) | ||
end | ||
|
||
private | ||
|
||
def self.call(url) | ||
RestClient.get(url, params: { fields: :nom }) | ||
rescue RestClient::ServiceUnavailable | ||
nil | ||
def self.parse(body) | ||
JSON.parse(body, symbolize_names: true) | ||
end | ||
|
||
def self.call(url, body, method = :get) | ||
response = Typhoeus::Request.new( | ||
url, | ||
method: method, | ||
params: method == :get ? body : nil, | ||
body: method == :post ? body : nil, | ||
timeout: TIMEOUT, | ||
accept_encoding: 'gzip', | ||
headers: { | ||
'Accept' => 'application/json', | ||
'Accept-Encoding' => 'gzip, deflate' | ||
}.merge(method == :post ? { 'Content-Type' => 'application/json' } : {}) | ||
).run | ||
|
||
if response.success? | ||
parse(response.body) | ||
else | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class ApiGeo::RPGAdapter | ||
def initialize(coordinates) | ||
@coordinates = GeojsonService.to_json_polygon_for_rpg(coordinates) | ||
end | ||
|
||
def data_source | ||
@data_source ||= ApiGeo::API.search_rpg(@coordinates) | ||
end | ||
|
||
def results | ||
data_source[:features].map do |feature| | ||
feature[:properties] | ||
.stringify_keys | ||
.transform_keys(&:underscore) | ||
.symbolize_keys | ||
.slice( | ||
:culture, | ||
:code_culture, | ||
:surface, | ||
:bio | ||
).merge({ geometry: feature[:geometry] }) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class Champs::DepartementChamp < Champs::TextChamp | ||
def self.departements | ||
JSON.parse(ApiGeo::API.departements).map { |liste| "#{liste['code']} - #{liste['nom']}" }.push('99 - Étranger') | ||
ApiGeo::API.departements.map { |liste| "#{liste[:code]} - #{liste[:nom]}" }.push('99 - Étranger') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class Champs::PaysChamp < Champs::TextChamp | ||
def self.pays | ||
JSON.parse(ApiGeo::API.pays).pluck("nom") | ||
ApiGeo::API.pays.pluck(:nom) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class Champs::RegionChamp < Champs::TextChamp | ||
def self.regions | ||
JSON.parse(ApiGeo::API.regions).sort_by { |e| e['nom'] }.pluck("nom") | ||
ApiGeo::API.regions.sort_by { |e| e[:nom] }.pluck(:nom) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
class GeoAreaSerializer < ActiveModel::Serializer | ||
attributes :geometry, | ||
:source, | ||
:surface_intersection, | ||
:surface_parcelle, | ||
:numero, | ||
:feuille, | ||
:section, | ||
:code_dep, | ||
:nom_com, | ||
:code_com, | ||
:code_arr, | ||
:code, | ||
:nom, | ||
:commune | ||
attributes :geometry, :source | ||
|
||
attribute :surface_intersection, if: :include_cadastre? | ||
attribute :surface_parcelle, if: :include_cadastre? | ||
attribute :numero, if: :include_cadastre? | ||
attribute :feuille, if: :include_cadastre? | ||
attribute :section, if: :include_cadastre? | ||
attribute :code_dep, if: :include_cadastre? | ||
attribute :nom_com, if: :include_cadastre? | ||
attribute :code_com, if: :include_cadastre? | ||
attribute :code_arr, if: :include_cadastre? | ||
|
||
attribute :code, if: :include_quartier_prioritaire? | ||
attribute :nom, if: :include_quartier_prioritaire? | ||
attribute :commune, if: :include_quartier_prioritaire? | ||
|
||
attribute :culture, if: :include_parcelle_agricole? | ||
attribute :code_culture, if: :include_parcelle_agricole? | ||
attribute :surface, if: :include_parcelle_agricole? | ||
attribute :bio, if: :include_parcelle_agricole? | ||
|
||
def include_cadastre? | ||
object.source == GeoArea.sources.fetch(:cadastre) | ||
end | ||
|
||
def include_quartier_prioritaire? | ||
object.source == GeoArea.sources.fetch(:quartier_prioritaire) | ||
end | ||
|
||
def include_parcelle_agricole? | ||
object.source == GeoArea.sources.fetch(:parcelle_agricole) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Typhoeus::Config.user_agent = "demarches-simplifiees.fr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.