Open geowasser opened 1 month ago
Thank you for your feedback, and I apologize for replying so late, I am a bit overwhelmed and rarely have time to look into my personal projects.
Unfortunately, the plugin relies on the specific algorithms and naming of SAGA 2.X, which is what the code was developed with. The default SAGA provider has officially been removed in favor of SAGA Next Gen, but I have not yet update the code.
I will look into it when I have some time, but I can't promise it will be solved
Actually... I played around a bit, and it seems possible that it might be feasible to fix this. I already fixed the first module, the one you tried to run. Try creating a new Python Script (in the processing toolbox) with this code:
import os
from datetime import datetime
from qgis.core import QgsProject
from qgis.core import QgsProcessing
from qgis.core import QgsProcessingAlgorithm
from qgis.core import QgsProcessingMultiStepFeedback
from qgis.core import QgsProcessingParameterRasterLayer
from qgis.core import QgsProcessingParameterNumber
from qgis.core import QgsProcessingParameterRasterDestination
from qgis.core import QgsProcessingParameterVectorDestination
try:
from qgis import processing
except:
import processing
class geomelMainA(QgsProcessingAlgorithm):
def initAlgorithm(self, config=None):
basePath = QgsProject.instance().readPath("./")
self.addParameter(
QgsProcessingParameterRasterLayer("dem", "DEM", defaultValue=None)
)
self.addParameter(
QgsProcessingParameterNumber(
"channel_initiation_threshold",
"Channel initiation threshold (how many pixels must drain through a cell to be considered a channel)",
type=QgsProcessingParameterNumber.Integer,
minValue=1,
defaultValue=40000,
)
)
self.addParameter(
QgsProcessingParameterRasterDestination(
"Channel_network_raster",
"Channel network (raster)",
createByDefault=True,
defaultValue=os.path.join(basePath, "channel_network.sdat"),
)
)
self.addParameter(
QgsProcessingParameterVectorDestination(
"Channel_network_vector",
"Channel network (vector)",
type=QgsProcessing.TypeVectorLine,
createByDefault=True,
defaultValue=os.path.join(basePath, "channel_network.gpkg"),
)
)
self.addParameter(
QgsProcessingParameterRasterDestination(
"Filled_dem",
"Filled DEM",
createByDefault=True,
defaultValue=os.path.join(basePath, "filled_dem.sdat"),
)
)
self.addParameter(
QgsProcessingParameterRasterDestination(
"Flow_direction",
"Flow Directions",
createByDefault=True,
defaultValue=os.path.join(basePath, "flow_directions.sdat"),
)
)
def processAlgorithm(self, parameters, context, model_feedback):
# Use a multi-step feedback, so that individual child algorithm progress reports are adjusted for the
# overall progress through the model
feedback = QgsProcessingMultiStepFeedback(3, model_feedback)
results = {}
outputs = {}
# Fill sinks (wang & liu)
alg_params = {
"ELEV": parameters["dem"],
"MINSLOPE": 0.01,
"WSHED": "TEMPORARY_OUTPUT",
"FDIR": parameters["Flow_direction"],
"FILLED": parameters["Filled_dem"],
"WSHED": QgsProcessing.TEMPORARY_OUTPUT,
}
outputs["FillSinksWangLiu"] = processing.run(
"sagang:fillsinkswangliu",
alg_params,
context=context,
feedback=feedback,
is_child_algorithm=True,
)
results["Filled_dem"] = outputs["FillSinksWangLiu"]["FILLED"]
results["Flow_direction"] = outputs["FillSinksWangLiu"]["FDIR"]
feedback.setCurrentStep(1)
if feedback.isCanceled():
return {}
# Catchment area
alg_params = {
"ACCU_LEFT": "TEMPORARY_OUTPUT",
"ACCU_MATERIAL": None,
"ACCU_RIGHT": "TEMPORARY_OUTPUT",
"ACCU_TARGET": outputs["FillSinksWangLiu"]["FILLED"],
"ACCU_TOTAL": "TEMPORARY_OUTPUT",
"CONVERGENCE": 1.1,
"ELEVATION": outputs["FillSinksWangLiu"]["FILLED"],
"FLOW": "TEMPORARY_OUTPUT",
"FLOW_LENGTH": "TEMPORARY_OUTPUT",
"FLOW_UNIT": 1, # [1] cell area
"LINEAR_DIR": None,
"LINEAR_DO": False,
"LINEAR_MIN": 500,
"LINEAR_VAL": None,
"METHOD": 0, # [0] Deterministic 8
"MFD_CONTOUR": False,
"NO_NEGATIVES": True,
"SINKROUTE": None,
"STEP": 1,
"VAL_INPUT": None,
"VAL_MEAN": "TEMPORARY_OUTPUT",
"WEIGHTS": None,
"WEIGHT_LOSS": "TEMPORARY_OUTPUT",
"FLOW": QgsProcessing.TEMPORARY_OUTPUT,
"VAL_MEAN": QgsProcessing.TEMPORARY_OUTPUT,
}
outputs["CatchmentArea"] = processing.run(
"sagang:catchmentarea",
alg_params,
context=context,
feedback=feedback,
is_child_algorithm=True,
)
feedback.setCurrentStep(2)
if feedback.isCanceled():
return {}
# Channel network
alg_params = {
"DIV_CELLS": 5,
"DIV_GRID": None,
"ELEVATION": outputs["FillSinksWangLiu"]["FILLED"],
"INIT_GRID": outputs["CatchmentArea"]["FLOW"],
"INIT_METHOD": 2, # [2] Greater than
"INIT_VALUE": parameters["channel_initiation_threshold"],
"MINLEN": 1,
"SINKROUTE": None,
"TRACE_WEIGHT": None,
"CHNLNTWRK": parameters["Channel_network_raster"],
"CHNLROUTE": QgsProcessing.TEMPORARY_OUTPUT,
"SHAPES": parameters["Channel_network_vector"],
}
outputs["ChannelNetwork"] = processing.run(
"sagang:channelnetwork",
alg_params,
context=context,
feedback=feedback,
is_child_algorithm=True,
)
results["Channel_network_raster"] = outputs["ChannelNetwork"]["CHNLNTWRK"]
results["Channel_network_vector"] = outputs["ChannelNetwork"]["SHAPES"]
return results
def name(self):
return "geomelMainA"
def displayName(self):
return "1. Filled DEM & Channel Network"
def group(self):
return "Geomeletitiki Hydrology Analysis"
def groupId(self):
return "geomel_hydro_main"
def createInstance(self):
return geomelMainA()
Dear devolepment team,
when running step 1 of your plugin the following error message appears: error: algorithm saga:fillsinkswangliu not found.
I am running QGIS 3.34.10. Saga Toolbox (including "Fill sinks (wang & liu)") only available as SAGA NextGen (maybe that is why?).
Thank you/ευχαριστώ πολύ
Felix/Ευτύχιος