Skip to content

Commit

Permalink
Waarschuwingen toegevoegd
Browse files Browse the repository at this point in the history
Waterpasserende verharding
BGT/BAG vergelijking
Begin van relatieve hoogteligging vlakken
  • Loading branch information
ruben123zaag committed Oct 18, 2024
1 parent d0ead66 commit 7ffa99c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
11 changes: 6 additions & 5 deletions QGIS_plugin/bgtinlooptool/BGTInloopTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,17 @@ def run(self):

self.increase_progress()

#print("alleen nog opslaan")
#output_path =r"C:\Users\ruben.vanderzaag\Documents\Github\bgt-inlooptool\QGIS_plugin\bgtinlooptool\style\output_bgtinlooptool_connecting_codes_testing.gpkg"
#self.it._database._save_to_gpkg_test(output_path)

QgsMessageLog.logMessage(
"Importing surfaces", MESSAGE_CATEGORY, level=Qgis.Info
)
self.it.import_surfaces(self.bgt_file,self.input_extent_mask_wkt)
self.increase_progress()

#print("alleen nog opslaan")
#output_path =r"C:\Users\ruben.vanderzaag\Documents\Z0141_BGT_inlooptool\Test data Soest warnings (klein)\test_bgt_inputs_relatieve_hoogteligging.gpkg"
#self.it._database._save_to_gpkg_test(output_path)


QgsMessageLog.logMessage(
"Importing pipes", MESSAGE_CATEGORY, level=Qgis.Info
)
Expand Down Expand Up @@ -261,7 +262,7 @@ def run(self):
else:
self.it._database._save_to_gpkg(self.output_folder,GPKG_TEMPLATE_HIDDEN)
self.increase_progress()

QgsMessageLog.logMessage("Finished", MESSAGE_CATEGORY, level=Qgis.Success)

return True
Expand Down
58 changes: 52 additions & 6 deletions core/inlooptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(self, parameters):
"""Constructor."""
self.parameters = parameters
self._database = Database()
self.inf_pavements_green_roof_surfaces = []

def set_settings_start(self,bgt_file,pipe_file,building_file, kolken_file):
settings_table = self._database.settings_table
Expand Down Expand Up @@ -841,6 +842,7 @@ def intersect_inf_pavement_green_roofs(self):

# Update the feature in the result table
result_table.SetFeature(result_feature)
self.inf_pavements_green_roof_surfaces.append(result_feature)


def calculate_statistics(self, stats_path):
Expand Down Expand Up @@ -971,6 +973,7 @@ def generate_warnings(self): #TO DO: aanvullen met andere waarschuwing, evt. nog
#print(feature_defn)
fid = 0

#Check 1: large areas
warning_large_area = f"Dit BGT vlak is groter dan {CHECKS_LARGE_AREA} m2. De kans is groot dat dit vlak aangesloten is op meerdere stelseltypen. Controleer en corrigeer dit wanneer nodig."

for it_feature in it_layer:
Expand All @@ -991,7 +994,47 @@ def generate_warnings(self): #TO DO: aanvullen met andere waarschuwing, evt. nog
checks_table.CreateFeature(check_feature)
check_feature = None # Cleanup after creating the feature

#Check 2: buildings that are in the BGT but not in the BAG
warning_bgt_bag_mismatch = "Dit pand komt wel voor in de BGT, maar niet in de BAG. Er is daarom geen bouwjaar toegewezen aan het pand."
non_matching = self._database.non_matching_buildings

for building in non_matching:
fid += 1
geom = building.GetGeometryRef()
check_feature = ogr.Feature(feature_defn)
check_feature.SetGeometry(geom.Clone())
check_feature.SetField(CHECKS_TABLE_FIELD_ID,fid)
check_feature.SetField(CHECKS_TABLE_FIELD_LEVEL, "Info")
check_feature.SetField(CHECKS_TABLE_FIELD_CODE,2)
check_feature.SetField(CHECKS_TABLE_FIELD_TABLE,"4. BGT inlooptabel")
check_feature.SetField(CHECKS_TABLE_FIELD_COLUMN,"BGT Identificatie")
check_feature.SetField(CHECKS_TABLE_FIELD_VALUE,building["identificatie_lokaalid"]) #identificatiebagpnd
check_feature.SetField(CHECKS_TABLE_FIELD_DESCRIPTION,warning_bgt_bag_mismatch
)
checks_table.CreateFeature(check_feature)
check_feature = None # Cleanup after creating the feature

#Check 3: surface which intersect with green roofs or infiltrating pavement
warning_infiltrating_surfaces = "Dit oppervlak is waterpasserende verharding of een groen dak. Het type verharding is daarop aangepast, maar de percentuele afwatering nog niet."
infiltrating_surfaces = self.inf_pavements_green_roof_surfaces

for surface in infiltrating_surfaces:
fid += 1
geom = surface.GetGeometryRef()
check_feature = ogr.Feature(feature_defn)
check_feature.SetGeometry(geom.Clone())
check_feature.SetField(CHECKS_TABLE_FIELD_ID,fid)
check_feature.SetField(CHECKS_TABLE_FIELD_LEVEL, "Info")
check_feature.SetField(CHECKS_TABLE_FIELD_CODE,3)
check_feature.SetField(CHECKS_TABLE_FIELD_TABLE,"4. BGT inlooptabel")
check_feature.SetField(CHECKS_TABLE_FIELD_COLUMN,"Type verharding")
check_feature.SetField(CHECKS_TABLE_FIELD_VALUE,surface["type_verharding"])
check_feature.SetField(CHECKS_TABLE_FIELD_DESCRIPTION,warning_infiltrating_surfaces
)
checks_table.CreateFeature(check_feature)
check_feature = None # Cleanup after creating the feature

#Check 4:
checks_table = None
it_layer = None

Expand All @@ -1017,6 +1060,7 @@ def __init__(self, epsg=28992):
self.create_table(
table_name=CHECKS_TABLE_NAME, table_schema=CHECKS_TABLE_SCHEMA
)
self.non_matching_buildings = []

@property
def result_table(self):
Expand Down Expand Up @@ -1494,7 +1538,9 @@ def merge_surfaces(self):

if stype == SURFACE_TYPE_PAND:
new_feature["identificatiebagpnd"] = feature["identificatieBAGPND"]

print("Tot hier")
new_feature.SetField("relatieve_hoogteligging", feature["relatieveHoogteligging"])

target_geometry = ogr.ForceToPolygon(feature.geometry())
target_geometry.AssignSpatialReference(self.srs)
new_feature.SetGeometry(target_geometry)
Expand Down Expand Up @@ -1523,14 +1569,17 @@ def add_build_year_to_surface(self, file_path, field_name="bouwjaar"):
for building in buildings:
building_dict[building["identificatie"][1:]] = building[field_name]
building = None


# List to track bui;ding-surfaces that are in the BGT but not in the BAG
for surface in surfaces:
if surface["surface_type"] == SURFACE_TYPE_PAND:
if surface["identificatiebagpnd"] in building_dict.keys():
surface["build_year"] = building_dict[
surface["identificatiebagpnd"]
]
surfaces.SetFeature(surface)
else:
self.non_matching_buildings.append(surface)
surface = None

buildings = None
Expand Down Expand Up @@ -1576,11 +1625,8 @@ def copy_features_with_matching_fields(self,src_layer, dst_layer, primary_key_fi
dst_layer.SyncToDisk()

def _save_to_gpkg_test(self, file_path): #TO DO: weghalen, is alleen voor testen
print("Preparing template gpkg")
output_gpkg = r"C:\Users\ruben.vanderzaag\Documents\Github\bgt-inlooptool\QGIS_plugin\bgtinlooptool\style\output_bgtinlooptool_testing_rekeninstellingen.gpkg"

print("Testen van output wegschrijven!!")
self.out_db = GPKG_DRIVER.CopyDataSource(self.mem_database, output_gpkg)
self.out_db = GPKG_DRIVER.CopyDataSource(self.mem_database, file_path)
self.out_db = None

def _save_to_gpkg(self,file_folder,template_gpkg):
Expand Down
1 change: 1 addition & 0 deletions core/table_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, fields, primary_key, geometry_column, geometry_type):
RESULT_TABLE_FIELD_GRAAD_VERHARDING: ogr.OFTReal,
"build_year": ogr.OFTInteger,
"identificatiebagpnd": ogr.OFTString,
"relatieve_hoogteligging": ogr.OFTInteger,
}
for dist_type in DISTANCE_TYPES:
surfaces_table_fields["distance_" + dist_type] = ogr.OFTReal
Expand Down

1 comment on commit 7ffa99c

@reinout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even goed de non-matching-buildings nakijken. Ik zie het in deze commit in drie varianten langskomen.

  • self._database.non_matching_buildings
  • non_matching = self._database.non_matching_buildings (alleen in loop gebruikt geloof ik? dan kan je ook for building in self._database.non_matching_buildings ofzo doen).
  • self.non_matching_buildings

Oppassen dat er eentje niet de ander loopt te pesten.

Het ziet er namelijk uit als een lijst, en dan moet je bij python oppassen. Een variabele wijst achter de schermen naar een geheugenlocatie. a = 3, dan wijst a naar een waarde 3. Maar a = [], dan wijst a naar een lijst. En een lijst kan intern veranderd worden zonder dat het adres van de lijst zelf veranderd:

> a = []
> b = a  # wijst naar zelfde lijst
> b.append(2}  # de lijst waar beiden naar verwijzen wordt "in-place" veranderd
> a
[2]

Op dit soort punten kunnen subtiele bugs ontstaan, vandaar m'n hele verhaal :-)

Please sign in to comment.