#131 WIP: EGON exporter
* adds incomplete WIP implementation of an EGON exporter
This commit is contained in:
parent
98a1a70a69
commit
06ad0fdc2d
150
intervention/utils/egon_export.py
Normal file
150
intervention/utils/egon_export.py
Normal file
@ -0,0 +1,150 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 07.03.22
|
||||
|
||||
"""
|
||||
import xmltodict
|
||||
from django.contrib.gis.gdal import OGRGeometry
|
||||
from django.db.models import Sum
|
||||
from django.utils import formats
|
||||
|
||||
from intervention.models import Intervention
|
||||
from xml.etree import ElementTree as etree
|
||||
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
|
||||
|
||||
class EgonExporter:
|
||||
"""
|
||||
EGON is the payment management system of SNU RLP. Due to compatibility reasons we need to provide the old style
|
||||
of data transmission between KSP and EGON:
|
||||
1. Create GML from intervention object
|
||||
2. Send created GML to the appropriate RabbitMQ channel
|
||||
"""
|
||||
intervention = None
|
||||
gml_builder = None
|
||||
|
||||
def __init__(self, intervention: Intervention):
|
||||
self.intervention = intervention
|
||||
self.gml_builder = EgonGmlBuilder(intervention)
|
||||
|
||||
def export_to_rabbitmq(self):
|
||||
raise NotImplementedError("ToDo!")
|
||||
|
||||
|
||||
class EgonGmlBuilder:
|
||||
"""
|
||||
Creates the GML for EGON export
|
||||
"""
|
||||
intervention = None
|
||||
gml = None
|
||||
|
||||
def __init__(self, intervention: Intervention):
|
||||
self.intervention = intervention
|
||||
self.gml = self.build_gml()
|
||||
|
||||
def build_gml(self):
|
||||
all_payments = self.intervention.payments.aggregate(
|
||||
summed=Sum("amount")
|
||||
)["summed"]
|
||||
|
||||
comp_type = "Ersatzzahlung"
|
||||
if self.intervention.compensations.exists():
|
||||
comp_type += " und Kompensation"
|
||||
|
||||
geom = self.intervention.geometry.geom
|
||||
geom.transform(DEFAULT_SRID_RLP)
|
||||
geoms_list = [
|
||||
{
|
||||
"gml:polygonMember": {
|
||||
"gml:Polygon": {
|
||||
"gml:exterior": {
|
||||
"gml:LinearRing": {
|
||||
"gml:posList": " ".join([f"{str(coord[0])},{str(coord[1])}" for coord in coords[0]])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} for coords in geom.coords
|
||||
]
|
||||
|
||||
parcels = self.intervention.get_underlying_parcels()
|
||||
spatial_reference_list = [
|
||||
{
|
||||
"oneo:Raumreferenz": {
|
||||
"oneo:datumAbgleich": None,
|
||||
"oneo:ortsangabe": {
|
||||
"oneo:Ortsangaben": {
|
||||
"oneo:kreisSchluessel": parcel.district.krs,
|
||||
"oneo:gemeindeSchluessel": parcel.district.gmnd,
|
||||
"oneo:verbandsgemeindeSchluessel": parcel.gmrkng,
|
||||
"oneo:flurstuecksKennzeichen": None,
|
||||
}
|
||||
},
|
||||
}
|
||||
} for parcel in parcels
|
||||
]
|
||||
|
||||
t = {
|
||||
"wfs:FeatureCollection": {
|
||||
"oneo:Eingriffsverfahren": {
|
||||
"@gml:id": self.intervention.identifier,
|
||||
"oneo:azEintragungsstelle": self.intervention.responsible.conservation_file_number,
|
||||
"oneo:azZulassungsstelle": self.intervention.responsible.registration_file_number,
|
||||
"oneo:bemerkungZulassungsstelle": None,
|
||||
"oneo:eintragungsstelle": self.intervention.responsible.conservation_office.long_name,
|
||||
"oneo:zulassungsstelle": self.intervention.responsible.registration_office.long_name,
|
||||
"oneo:ersatzzahlung": all_payments,
|
||||
"oneo:kompensationsart": comp_type,
|
||||
"oneo:verfahrensrecht": self.intervention.legal.laws.first().short_name,
|
||||
"oneo:verfahrenstyp": self.intervention.legal.process_type.long_name,
|
||||
"oneo:eingreifer": {
|
||||
"oneo:Eingreifer": {
|
||||
"oneo:art": self.intervention.responsible.handler.type.long_name,
|
||||
"oneo:bemerkung": self.intervention.responsible.handler.type.long_name,
|
||||
}
|
||||
},
|
||||
"oneo:erfasser": {
|
||||
"oneo:Erfasser": {
|
||||
"oneo:name": None,
|
||||
"oneo:bemerkung": None,
|
||||
}
|
||||
},
|
||||
"oneo:zulassung": {
|
||||
"oneo:Zulassungstermin": {
|
||||
"oneo:bauBeginn": formats.localize(self.intervention.payments.first().due_on),
|
||||
"oneo:erlass": formats.localize(self.intervention.legal.registration_date),
|
||||
"oneo:rechtsKraft": formats.localize(self.intervention.legal.binding_date),
|
||||
}
|
||||
},
|
||||
"oneo:geometrie": {
|
||||
"gml:multiSurfaceProperty": {
|
||||
"gml:MultiPolygon": {
|
||||
"@srsName": f"http://www.opengis.net/gml/srs/epsg.xml#{DEFAULT_SRID_RLP}",
|
||||
"#text": geoms_list,
|
||||
}
|
||||
},
|
||||
},
|
||||
"oneo:kennung": self.intervention.identifier,
|
||||
"oneo:bezeichnung": self.intervention.title,
|
||||
"oneo:bemerkung": self.intervention.comment,
|
||||
"oneo:verantwortlicheStelle": None,
|
||||
"oneo:veroffentlichtAm": None,
|
||||
"oneo:raumreferenz": spatial_reference_list,
|
||||
"oneo:foto": {
|
||||
"oneo:Foto": {
|
||||
"oneo:aufnahmezeitpunkt": None,
|
||||
"oneo:bemerkung": None,
|
||||
"oneo:fotoverweis": None,
|
||||
"oneo:dateiname": None,
|
||||
"oneo:hauptfoto": False,
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
gml = xmltodict.unparse(t, pretty=True)
|
||||
print(gml)
|
||||
return gml
|
Loading…
Reference in New Issue
Block a user