Skip to content

Commit

Permalink
Show warnings (capture log) when using processing algorithm "Computat…
Browse files Browse the repository at this point in the history
…ional grid from schematisation" (#944)
  • Loading branch information
benvanbasten-ns committed Dec 8, 2023
1 parent 29b1c2a commit 88d3ea9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Fixed issue that no netcdf could be loaded in Water Depth Algorithm (caused by h5py breaking change) (#966)
- Water depth algorithm: include days in time display (#661)
- Show warnings (capture log) when using processing algorithm "Computational grid from schematisation" (#944)


3.3 (2023-12-01)
Expand Down
16 changes: 16 additions & 0 deletions processing/grid_creation_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
)
from threedigrid_builder import make_gridadmin, SchematisationError
from threedi_results_analysis.processing.processing_utils import gridadmin2geopackage, load_computational_layers
import logging
import io


class ThreeDiGenerateCompGridAlgorithm(QgsProcessingAlgorithm):
Expand Down Expand Up @@ -105,11 +107,25 @@ def progress_rep(progress, info):
feedback.setProgress(int(progress * 100))
feedback.pushInfo(info)

# Capture threedigridbuilder logging
logger = logging.getLogger("threedigrid_builder.grid.connection_nodes")
log_capture_string = io.StringIO()
ch = logging.StreamHandler(log_capture_string)
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
try:
make_gridadmin(input_spatialite, set_dem_path, gridadmin_file, progress_callback=progress_rep)
except SchematisationError as e:
err = f"Creating grid file failed with the following error: {repr(e)}"
raise QgsProcessingException(err)
finally:
# Pull the contents back into a string and close the stream
log_contents = log_capture_string.getvalue()
log_capture_string.close()
logger.removeHandler(ch)
if log_contents:
feedback.pushWarning("3Di gridbuilder log:")
feedback.pushWarning(log_contents)

feedback.setProgress(0)
gpkg_layers = gridadmin2geopackage(gridadmin_file, output_gpkg_file, context, feedback)
Expand Down

0 comments on commit 88d3ea9

Please sign in to comment.