diff --git a/crayfish/algs/__init__.py b/crayfish/algs/__init__.py index 877eb201..4b5bb8aa 100644 --- a/crayfish/algs/__init__.py +++ b/crayfish/algs/__init__.py @@ -33,6 +33,7 @@ from .cf_export_grid import ExportMeshGridAlgorithm from .cf_export_nodes import ExportMeshNodesAlgorithm from .cf_render import RenderMeshBedElevationAlgorithm +from .cf_export_contours import ExportContoursAlgorithm class CrayfishProcessingProvider(AlgorithmProvider): @@ -47,7 +48,8 @@ def __init__(self): ExportMeshElemsAlgorithm(), ExportMeshGridAlgorithm(), ExportMeshNodesAlgorithm(), - RenderMeshBedElevationAlgorithm()] + RenderMeshBedElevationAlgorithm(), + ExportContoursAlgorithm()] for alg in self.alglist: alg.provider = self diff --git a/crayfish/algs/cf_export_contours.py b/crayfish/algs/cf_export_contours.py new file mode 100644 index 00000000..2cb42735 --- /dev/null +++ b/crayfish/algs/cf_export_contours.py @@ -0,0 +1,41 @@ +from .cf_alg import CfGeoAlgorithm +from processing.core.outputs import OutputVector +from processing.core.parameters import ParameterFile, ParameterNumber, ParameterCrs, ParameterBoolean + +class ExportContoursAlgorithm(CfGeoAlgorithm): + IN_CF_MESH = 'CF_MESH' + IN_CF_MUPP = 'CF_MUPP' + IN_CF_CRS = 'CF_CRS' + IN_CF_INTERVAL = 'CF_INT' + IN_CF_LINES = 'CF_USE_LINES' + OUT_CF_SHP = "CF_SHP" + + def defineCharacteristics(self): + self.name, self.i18n_name = self.trAlgorithm('Export contours') + self.group, self.i18n_group = self.trAlgorithm('Mesh and Bed Elevation') + + self.addParameter(ParameterFile(self.IN_CF_MESH, self.tr('Crayfish Mesh'), optional=False)) + self.addParameter(ParameterNumber(self.IN_CF_MUPP, self.tr('Grid resolution'), default=5)) + self.addParameter(ParameterNumber(self.IN_CF_INTERVAL, self.tr('Contours interval'), default=1)) + self.addParameter(ParameterCrs(self.IN_CF_CRS, self.tr('CRS'))) + self.addParameter(ParameterBoolean(self.IN_CF_LINES, self.tr('Use lines'), default=True)) + self.addOutput(OutputVector(self.OUT_CF_SHP, self.tr('Contours shapefile'))) + + def processAlgorithm(self, progress): + m = self.get_mesh(self.IN_CF_MESH) + o = self.get_bed_elevation(m) + + outf = self.getOutputValue(self.OUT_CF_SHP) + mupp = self.getParameterValue(self.IN_CF_MUPP) + use_lines = self.getParameterValue(self.IN_CF_LINES) + interval = self.getParameterValue(self.IN_CF_INTERVAL) + crs = self.getParameterValue(self.IN_CF_CRS) + + res = o.export_contours(mupp, + interval, + outf, + crs, + use_lines, + None) + if not res: + raise CrayfishProccessingAlgorithmError("Unable to export contours") diff --git a/tools/cf_export_contours.py b/tools/cf_export_contours.py deleted file mode 100644 index 8f2d2589..00000000 --- a/tools/cf_export_contours.py +++ /dev/null @@ -1,21 +0,0 @@ - -import sys -sys.path.append('..') -import crayfish - -if len(sys.argv) != 3: - print "Syntax: %s <2dm file> " % sys.argv[0] - sys.exit(1) - -try: - m = crayfish.Mesh(sys.argv[1]) -except ValueError: - print "Failed to load mesh in %s" % sys.argv[1] - sys.exit(1) - -print "Exporting..." -resolution = 10 -interval = 3 -wkt = "" -m.dataset(0).output(0).export_contours(resolution, interval, sys.argv[2], wkt) -print "done."