You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.1 KiB
Python
125 lines
4.1 KiB
Python
|
|
|
|
|
|
|
|
|
|
# "C:\Program Files\QGIS 3.26.3\bin\Ogr2ogr.exe" -f GMLAS C:\temp-GIS\2026-04-08_export.xml C:\temp-GIS\fridolfing_kanal.gpkg
|
|
|
|
|
|
# "C:\Program Files\QGIS 3.26.3\bin\Ogr2ogr.exe" -f GML C:\temp-GIS\2026-04-08_export.xml C:\temp-GIS\fridolfing_kanal.gpkg -lco GML_ID=YES -lco XSD="C:\temp-GIS\_isy\2013\1_XML-Schema\1302-metadaten.xsd"
|
|
|
|
##"C:\Program Files\QGIS 3.26.3\bin"\ogr2ogr.exe -f GPKG %GPKGDatei% GMLAS:%IsybauXMLDatei% -oo XSD=C:\temp-GIS\_isy\2013\1_XML-Schema\1302-metadaten.xsd -forceNullable -oo CONFIG_FILE=C:\temp-GIS\_isy\gmlasconf.xml -oo REMOVE_UNUSED_LAYERS=YES -oo REMOVE_UNUSED_FIELDS=YES
|
|
|
|
|
|
import re
|
|
import xml.etree.ElementTree as ET
|
|
|
|
filedir = "C:/temp-GIS/"
|
|
xmlfile = "2026-04-08_export"
|
|
|
|
with open(filedir+xmlfile+".xml", "r") as infile:
|
|
content = infile.read()
|
|
|
|
pattern = re.compile(r"<wfs:[\s\S]*?>")
|
|
content = pattern.sub("", content)
|
|
|
|
pattern = re.compile(r"</wfs:.*?>")
|
|
content = pattern.sub("", content)
|
|
|
|
pattern = re.compile(r"<Identifikation>")
|
|
content = pattern.sub("<Identifikation xmlns=\"http://www.bfr-abwasser.de\">", content)
|
|
|
|
pattern = re.compile(r"2017/07/01")
|
|
content = pattern.sub("2017-07", content)
|
|
|
|
pattern = re.compile(r" xsi:nil=\"true\"")
|
|
content = pattern.sub("", content)
|
|
|
|
pattern = re.compile(r"<Baujahr>0</Baujahr>")
|
|
content = pattern.sub("", content)
|
|
|
|
|
|
xmlReplaceTag = ["Datenkollektive", "Geometrie", "Geometriedaten", "Knoten"]
|
|
|
|
for x in xmlReplaceTag:
|
|
pattern = re.compile(r"</"+x+">\s*<"+x+">")
|
|
content = pattern.sub("", content)
|
|
|
|
|
|
pattern = re.compile(r"<Knoten>\s*</Knoten>")
|
|
content = pattern.sub("", content)
|
|
|
|
|
|
|
|
###
|
|
### Boolean korrigieren
|
|
###
|
|
### 14.04.2026: Tabelle: _ogr_fields_metadata wurde field_type von boolean auf string verändert, da es bei boolean zur Ausgabe Null = False gekommen ist.
|
|
###
|
|
|
|
list_bool = ["Bautechnik", "Geometrie", "Sanierung", "Umfeld", "Inspektion", "Dichtheit", "Film", "Verfahren", "Rechennetz", "Gebiet", "Flaechen", "Belastung", "Berechnung", "Beobachtung", "SonderprofilVorhanden", "DrainageAngeschlossen","Einstieghilfe", "Uebergabeschacht", "Abdeckplatte", "Konus", "Uebergangsplatte", "Podest", "Uebergabepunkt", "Uebergabebauwerk", "Bypass", "Schwimmerabschluss", "ExistenzPumpe", "ExistenzUeberlauf", "ExistenzFiltersack", "Ueberschwemmungsgebiet", "Schmutzfaenger", "Dichtheitspruefung", "Reinigung", "Verbindung", "BDEZulaufDrainage", "DDEZulaufDrainage", "Pruefergebnis", "FilmpfadIstAbsolut", "VerlustansatzA110", "DruckdichterDeckel", "Rueckschlagklappe", "Bezugslinie"]
|
|
|
|
# Setze 0 = False und 1 = True
|
|
for i in list_bool:
|
|
pattern = re.compile(r"<"+i+">0</"+i+">")
|
|
content = pattern.sub(r"<"+i+">false</"+i+">", content)
|
|
pattern = re.compile(r"<"+i+">1</"+i+">")
|
|
content = pattern.sub(r"<"+i+">true</"+i+">", content)
|
|
|
|
|
|
|
|
|
|
|
|
with open(filedir+xmlfile+"_new.xml", "w") as outfile:
|
|
outfile.write(content)
|
|
|
|
#######
|
|
####### RUNDUNG
|
|
#######
|
|
|
|
input_xml = filedir+xmlfile+"_new.xml"
|
|
output_xml = filedir+xmlfile+"_new2.xml"
|
|
|
|
# Hier pro Tag die Rundung definieren
|
|
tag_rules = {
|
|
"Rechtswert": 3,
|
|
"Hochwert": 3,
|
|
"Punkthoehe": 3,
|
|
"Schachttiefe": 2,
|
|
"Laenge": 2,
|
|
"Entfernung": 2,
|
|
"Rohrlaenge": 2,
|
|
"SohlhoeheZulauf": 3,
|
|
"SohlhoeheAblauf": 3,
|
|
"DMPLaenge": 2
|
|
}
|
|
|
|
# Regex: <tag>wert</tag>
|
|
pattern = re.compile(r"<(\w+)>(.*?)</\1>")
|
|
|
|
def process_line(line):
|
|
def replace(match):
|
|
tag = match.group(1)
|
|
content = match.group(2)
|
|
|
|
# Nur bearbeiten, wenn Tag in Regeln
|
|
if tag in tag_rules:
|
|
try:
|
|
value = float(content)
|
|
decimals = tag_rules[tag]
|
|
rounded = round(value, decimals)
|
|
return f"<{tag}>{rounded}</{tag}>"
|
|
except ValueError:
|
|
pass # kein numerischer Wert → unverändert
|
|
|
|
return match.group(0) # Original zurückgeben
|
|
|
|
return pattern.sub(replace, line)
|
|
|
|
with open(input_xml, "r", encoding="utf-8") as infile, \
|
|
open(output_xml, "w", encoding="utf-8") as outfile:
|
|
|
|
for line in infile:
|
|
new_line = process_line(line)
|
|
outfile.write(new_line)
|