Skip to content

Commit

Permalink
Merge pull request #114 from CodeBardian/backport-113-to-ce
Browse files Browse the repository at this point in the history
[Backport ce] remove repeated points from geometries on civil import
  • Loading branch information
CodeBardian committed Nov 7, 2023
2 parents aed32a7 + 67b189c commit aed5cb6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/SAGisXPlanung/processing/import_civil.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def processPlan(self, plan_xid, conn, feedback) -> BP_Plan:
plan.name = res.name
plan.planArt = BP_PlanArt[res.art]

s = text("SELECT ST_AsText(ST_Multi(u.geometry)) AS g, ST_SRID(u.geometry) AS srid FROM "
# RemoveRepeatedPoints does not remove duplicated points from geometry column directly, most likely a bug???
# dump to wkt and create new geometry as workaround
s = text("SELECT ST_AsText(RemoveRepeatedPoints(ST_GeomFromText(ST_AsText(ST_Multi(u.geometry))))) AS g, ST_SRID(u.geometry) AS srid FROM "
"(SELECT ST_Union(geom) AS geometry FROM civil_line WHERE plan_id = :xid AND layer LIKE "
"'%15.13-Geltungsbereich%') u;")
res = conn.execute(s, {"xid": plan_xid}).first()
Expand Down Expand Up @@ -187,7 +189,9 @@ def processPlan(self, plan_xid, conn, feedback) -> BP_Plan:
return plan

def processPlaninhalt(self, planinhalt_xid, table, mapper, conn, feedback) -> XP_Objekt:
s = text(f"SELECT layer, rechtscharakter, ST_AsText(geom) AS geom, ST_SRID(geom) AS srid FROM {table} WHERE id = :xid")
# RemoveRepeatedPoints does not remove duplicated points from geometry column directly, most likely a bug???
# dump to wkt and create new geometry as workaround
s = text(f"SELECT layer, rechtscharakter, ST_AsText(RemoveRepeatedPoints(ST_GeomFromText(ST_AsText(geom)))) AS g, ST_SRID(geom) AS srid FROM {table} WHERE id = :xid")
res = conn.execute(s, {"xid": planinhalt_xid}).first()

# for each civil-styleid, check if the id is in the layer string, if yes create the corresponding object
Expand All @@ -200,7 +204,7 @@ def processPlaninhalt(self, planinhalt_xid, table, mapper, conn, feedback) -> XP
bp_objekt.rechtscharakter = BP_Rechtscharakter[res.rechtscharakter]

# parse and assign geometry
geometry = wkt.loads(res.geom)
geometry = wkt.loads(res.g)
if not geometry.is_valid:
raise QgsProcessingException(f'Geometrie ist nicht gültig: {explain_validity(geometry)}')
bp_objekt.position = WKTElement(geometry.wkt, srid=res.srid)
Expand Down

0 comments on commit aed5cb6

Please sign in to comment.