parent
06ad0fdc2d
commit
17c954e844
@ -5,13 +5,13 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 07.03.22
|
||||
|
||||
"""
|
||||
import base64
|
||||
|
||||
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
|
||||
|
||||
@ -45,20 +45,38 @@ class EgonGmlBuilder:
|
||||
self.intervention = intervention
|
||||
self.gml = self.build_gml()
|
||||
|
||||
def build_gml(self):
|
||||
def _gen_flurstuecksKennzeichen(self, parcel):
|
||||
""" Generates oneo:flurstuecksKennzeichen to provide backwards compatibility
|
||||
|
||||
Args:
|
||||
parcel (Parcel): The requested parcel
|
||||
|
||||
Returns:
|
||||
str
|
||||
"""
|
||||
gmrkng_code = "000000"
|
||||
flr_code = "{0:03d}".format(int(parcel.flr or 0))
|
||||
flrstckzhlr_code = "{0:05d}".format(int(parcel.flrstck_zhlr or 0))
|
||||
flrstcknnr_code = "{0:06d}".format(int(parcel.flrstck_nnr or 0))
|
||||
return gmrkng_code + flr_code + flrstckzhlr_code + flrstcknnr_code
|
||||
|
||||
def _sum_all_payments(self):
|
||||
all_payments = self.intervention.payments.aggregate(
|
||||
summed=Sum("amount")
|
||||
)["summed"]
|
||||
return all_payments
|
||||
|
||||
def _gen_kompensationsArt(self):
|
||||
comp_type = "Ersatzzahlung"
|
||||
if self.intervention.compensations.exists():
|
||||
comp_type += " und Kompensation"
|
||||
return comp_type
|
||||
|
||||
def _gen_geometry_list(self):
|
||||
geom = self.intervention.geometry.geom
|
||||
geom.transform(DEFAULT_SRID_RLP)
|
||||
geoms_list = [
|
||||
{
|
||||
"gml:polygonMember": {
|
||||
"gml:Polygon": {
|
||||
"gml:exterior": {
|
||||
"gml:LinearRing": {
|
||||
@ -66,28 +84,44 @@ class EgonGmlBuilder:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} for coords in geom.coords
|
||||
]
|
||||
return geoms_list
|
||||
|
||||
def _gen_raumreferenz(self):
|
||||
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,
|
||||
"oneo:flurstuecksKennzeichen": self._gen_flurstuecksKennzeichen(parcel),
|
||||
}
|
||||
},
|
||||
}
|
||||
} for parcel in parcels
|
||||
]
|
||||
return spatial_reference_list
|
||||
|
||||
t = {
|
||||
def _gen_foto(self):
|
||||
revoc_docs, regular_docs = self.intervention.get_documents()
|
||||
docs_list = [
|
||||
{
|
||||
"oneo:Foto": {
|
||||
"oneo:aufnahmezeitpunkt": formats.localize(doc.date_of_creation),
|
||||
"oneo:bemerkung": doc.comment,
|
||||
"oneo:fotoverweis": base64.b64encode(doc.file.read()).decode("utf-8"),
|
||||
"oneo:dateiname": doc.title,
|
||||
"oneo:hauptfoto": False,
|
||||
}
|
||||
} for doc in regular_docs
|
||||
]
|
||||
return docs_list
|
||||
|
||||
def build_gml(self):
|
||||
xml_dict = {
|
||||
"wfs:FeatureCollection": {
|
||||
"oneo:Eingriffsverfahren": {
|
||||
"@gml:id": self.intervention.identifier,
|
||||
@ -96,8 +130,8 @@ class EgonGmlBuilder:
|
||||
"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:ersatzzahlung": self._sum_all_payments(),
|
||||
"oneo:kompensationsart": self._gen_kompensationsArt(),
|
||||
"oneo:verfahrensrecht": self.intervention.legal.laws.first().short_name,
|
||||
"oneo:verfahrenstyp": self.intervention.legal.process_type.long_name,
|
||||
"oneo:eingreifer": {
|
||||
@ -123,7 +157,7 @@ class EgonGmlBuilder:
|
||||
"gml:multiSurfaceProperty": {
|
||||
"gml:MultiPolygon": {
|
||||
"@srsName": f"http://www.opengis.net/gml/srs/epsg.xml#{DEFAULT_SRID_RLP}",
|
||||
"#text": geoms_list,
|
||||
"gml:polygonMember": self._gen_geometry_list(),
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -132,19 +166,12 @@ class EgonGmlBuilder:
|
||||
"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,
|
||||
"oneo:raumreferenz": {
|
||||
"oneo:Raumreferenz": self._gen_raumreferenz(),
|
||||
},
|
||||
"oneo:foto": self._gen_foto(),
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
gml = xmltodict.unparse(t, pretty=True)
|
||||
print(gml)
|
||||
gml = xmltodict.unparse(xml_dict)
|
||||
return gml
|
Loading…
Reference in New Issue
Block a user