Skip to content

Commit

Permalink
Add GetCapabilities method to server CADASTRE service
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Jun 5, 2019
1 parent 8054794 commit f681adb
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions server/cadastre_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ def executeRequest(self, request: QgsServerRequest, response: QgsServerResponse,
try:
reqparam = params.get('REQUEST','').lower()

if reqparam == 'createpdf':
if reqparam == 'getcapabilities':
self.get_capabilities(params, response, project)
elif reqparam == 'createpdf':
self.create_pdf(params, response, project)
elif reqparam == 'getpdf':
self.get_pdf(params, response)
elif reqparam == 'gethtml':
self.get_html(params, response, project)
else:
raise CadastreError(400, ("Invalid REQUEST parameter: "
"must be one of GetHtml, CreatePdf or GetPdf,"
"must be one of GetCapabilities, GetHtml, CreatePdf or GetPdf,"
"found '%s'") % reqparam)

except CadastreError as err:
Expand All @@ -132,6 +134,66 @@ def executeRequest(self, request: QgsServerRequest, response: QgsServerResponse,
err.formatResponse(response)


def get_capabilities(self, params:Dict[str,str], response: QgsServerResponse, project: QgsProject) -> None:
""" Get cadastral capabilities based on config stored as project custom variables
"""
# get project custom variables
variables = project.customVariables()

if 'cadastre_parcelle_layer_id' not in variables or \
'cadastre_parcelle_unique_field' not in variables:
raise CadastreError(400, "Project has no cadastral capabilities")

parcelle_layer_id = variables['cadastre_parcelle_layer_id']
parcelle_layer_unique_field = variables['cadastre_parcelle_unique_field']

player = project.mapLayer(parcelle_layer_id)
if not player:
raise CadastreError(404, "Parcel layer not available")

capabilities = {
'parcelle': {
'id': player.id(),
'name': player.name(),
'title': player.title(),
'shortName': player.shortName(),
'unique_field': parcelle_layer_unique_field
}
}

if 'cadastre_section_layer_id' in variables:
section_layer_id = variables['cadastre_section_layer_id']
slayer = project.mapLayer(section_layer_id)
if slayer:
capabilities['section'] = {
'id': slayer.id(),
'name': slayer.name(),
'title': slayer.title(),
'shortName': slayer.shortName()
}
if 'cadastre_section_unique_field' in variables:
capabilities['section']['unique_field'] = variables['cadastre_section_unique_field']

if 'cadastre_commune_layer_id' in variables:
commune_layer_id = variables['cadastre_commune_layer_id']
slayer = project.mapLayer(commune_layer_id)
if slayer:
capabilities['commune'] = {
'id': slayer.id(),
'name': slayer.name(),
'title': slayer.title(),
'shortName': slayer.shortName()
}
if 'cadastre_commune_unique_field' in variables:
capabilities['commune']['unique_field'] = variables['cadastre_commune_unique_field']

write_json_response({
'status': 'success',
'message': 'Capabilities',
'data': capabilities
},response)


def create_pdf(self, params:Dict[str,str], response: QgsServerResponse, project: QgsProject) -> None:
""" Create a PDF from cadastral data
"""
Expand Down

0 comments on commit f681adb

Please sign in to comment.