CARTO::SGMAP → ApiCarto
This commit is contained in:
parent
442b4a241b
commit
d726fbf698
8 changed files with 13 additions and 13 deletions
27
app/lib/api_carto/api.rb
Normal file
27
app/lib/api_carto/api.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
class ApiCarto::API
|
||||
def initialize
|
||||
end
|
||||
|
||||
def self.search_qp(geojson)
|
||||
url = [API_CARTO_URL, "quartiers-prioritaires", "search"].join("/")
|
||||
call(url, geojson)
|
||||
end
|
||||
|
||||
def self.search_cadastre(geojson)
|
||||
url = [API_CARTO_URL, "cadastre", "geometrie"].join("/")
|
||||
call(url, geojson)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.call(url, geojson)
|
||||
verify_ssl_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
params = geojson.to_s
|
||||
|
||||
client = RestClient::Resource.new(url, verify_ssl: verify_ssl_mode)
|
||||
client.post(params, content_type: 'application/json')
|
||||
|
||||
rescue RestClient::InternalServerError
|
||||
raise RestClient::ResourceNotFound
|
||||
end
|
||||
end
|
29
app/lib/api_carto/cadastre/adapter.rb
Normal file
29
app/lib/api_carto/cadastre/adapter.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
class ApiCarto::Cadastre::Adapter
|
||||
def initialize(coordinates)
|
||||
@coordinates = GeojsonService.to_json_polygon_for_cadastre(coordinates)
|
||||
end
|
||||
|
||||
def data_source
|
||||
@data_source ||= JSON.parse(ApiCarto::API.search_cadastre(@coordinates), symbolize_names: true)
|
||||
end
|
||||
|
||||
def results
|
||||
data_source[:features].map do |feature|
|
||||
filter_properties(feature[:properties]).merge({ geometry: feature[:geometry] })
|
||||
end
|
||||
end
|
||||
|
||||
def filter_properties(properties)
|
||||
properties.slice(
|
||||
:surface_intersection,
|
||||
:surface_parcelle,
|
||||
:numero,
|
||||
:feuille,
|
||||
:section,
|
||||
:code_dep,
|
||||
:nom_com,
|
||||
:code_com,
|
||||
:code_arr
|
||||
)
|
||||
end
|
||||
end
|
15
app/lib/api_carto/quartiers_prioritaires/adapter.rb
Normal file
15
app/lib/api_carto/quartiers_prioritaires/adapter.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
class ApiCarto::QuartiersPrioritaires::Adapter
|
||||
def initialize(coordinates)
|
||||
@coordinates = GeojsonService.to_json_polygon_for_qp(coordinates)
|
||||
end
|
||||
|
||||
def data_source
|
||||
@data_source ||= JSON.parse(ApiCarto::API.search_qp(@coordinates), symbolize_names: true)
|
||||
end
|
||||
|
||||
def results
|
||||
data_source[:features].map do |feature|
|
||||
feature[:properties].merge({ geometry: feature[:geometry] })
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue