QgsProcessingParameterDistance,
QgsVectorDataProvider,
QgsFields,
- QgsField)
+ QgsField,
+ QgsUnitTypes)
import processing
import re
PIPE = 'PIPE'
SPAN = 'SPAN'
TOLERANCE = 'TOLERANCE'
+ MINIMUM_LENGTH = 'MINIMUM_LENGTH'
OUTPUT = 'OUTPUT'
# Constants for feature field names
)
)
- 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(
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)
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, [])
#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())
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']