From: Reino Ruusu Date: Wed, 3 Apr 2019 14:41:43 +0000 (+0300) Subject: Add minimum span length paremeter to CSV generator script. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=0dac716501acd53b9c98896d0960e3064eeb6249;p=simantics%2Fdistrict.git Add minimum span length paremeter to CSV generator script. Also set units for distance parameters. gitlab #40 Change-Id: If5d39eccf4f93d8efd472c765ec4d8a79bffc203 --- diff --git a/org.simantics.district.feature/rootFiles/QGIS scripts/generateCSV.py b/org.simantics.district.feature/rootFiles/QGIS scripts/generateCSV.py index c724d89e..5a9197a4 100644 --- a/org.simantics.district.feature/rootFiles/QGIS scripts/generateCSV.py +++ b/org.simantics.district.feature/rootFiles/QGIS scripts/generateCSV.py @@ -23,7 +23,8 @@ from qgis.core import (QgsProcessing, QgsProcessingParameterDistance, QgsVectorDataProvider, QgsFields, - QgsField) + QgsField, + QgsUnitTypes) import processing import re @@ -49,6 +50,7 @@ class SpanCoordinatesAlgorithm(QgsProcessingAlgorithm): PIPE = 'PIPE' SPAN = 'SPAN' TOLERANCE = 'TOLERANCE' + MINIMUM_LENGTH = 'MINIMUM_LENGTH' OUTPUT = 'OUTPUT' # Constants for feature field names @@ -133,14 +135,23 @@ class SpanCoordinatesAlgorithm(QgsProcessingAlgorithm): ) ) - self.addParameter( - QgsProcessingParameterDistance( - self.TOLERANCE, - self.tr('Location tolerance'), - 0.0, - minValue = 0.0 - ) + tol = QgsProcessingParameterDistance( + self.TOLERANCE, + self.tr('Location tolerance'), + 0.001, + minValue = 0.0 ) + tol.setDefaultUnit(QgsUnitTypes.DistanceMeters) + self.addParameter( tol ) + + dist = QgsProcessingParameterDistance( + self.MINIMUM_LENGTH, + self.tr('Minimum span length'), + 0.25, + minValue = 0.0 + ) + dist.setDefaultUnit(QgsUnitTypes.DistanceMeters) + self.addParameter( dist ) self.addParameter( QgsProcessingParameterFeatureSink( @@ -176,6 +187,14 @@ class SpanCoordinatesAlgorithm(QgsProcessingAlgorithm): context ) + minLength = self.parameterAsDouble( + parameters, + self.MINIMUM_LENGTH, + context + ) + + feedback.pushInfo('Tolerance: {} m\nMinimum span length: {} m'.format(eps, minLength)) + sourceFields = span.fields() sourceNames = sourceFields.names() outputFields = QgsFields(sourceFields) @@ -227,10 +246,10 @@ class SpanCoordinatesAlgorithm(QgsProcessingAlgorithm): fatherID = feature[self.FATHER_ID] # Length - length = geometry.length() + myLength = geometry.length() oldLength = lengths.get(fatherID, 0.0) - lengths[fatherID] = oldLength + length + lengths[fatherID] = oldLength + myLength # Segment points pointList = strings.get(fatherID, []) @@ -267,7 +286,11 @@ class SpanCoordinatesAlgorithm(QgsProcessingAlgorithm): #feedback.pushInfo(str(id)) # Length - length = lengths.get(id, None) + myLength = feature['Length'] + + # Ignore short stumps + if myLength <= minLength: + continue # Vertices mypoints = list(feature.geometry().vertices()) @@ -327,7 +350,7 @@ class SpanCoordinatesAlgorithm(QgsProcessingAlgorithm): outputFeature['x2'] = feature['x2'] outputFeature['y2'] = feature['y2'] outputFeature['z2'] = feature['z2'] - outputFeature['Length'] = feature['length'] # length + outputFeature['Length'] = feature['Length'] # myLength outputFeature['LineString'] = result label = feature['Label']