本文整理匯總了Python中qgis.analysis.QgsGeometrySnapper類的典型用法代碼示例。如果您正苦於以下問題:Python QgsGeometrySnapper類的具體用法?Python QgsGeometrySnapper怎麽用?Python QgsGeometrySnapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了QgsGeometrySnapper類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: processAlgorithm
def processAlgorithm(self, feedback):
layer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
reference_layer = dataobjects.getLayerFromString(self.getParameterValue(self.REFERENCE_LAYER))
tolerance = self.getParameterValue(self.TOLERANCE)
mode = self.getParameterValue(self.BEHAVIOR)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layer.fields(), layer.wkbType(), layer.crs())
features = vector.features(layer)
self.processed = 0
self.feedback = feedback
self.total = 100.0 / len(features)
if self.getParameterValue(self.INPUT) != self.getParameterValue(self.REFERENCE_LAYER):
snapper = QgsGeometrySnapper(reference_layer)
snapper.featureSnapped.connect(self.featureSnapped)
snapped_features = snapper.snapFeatures(features, tolerance, mode)
for f in snapped_features:
writer.addFeature(QgsFeature(f))
else:
# snapping internally
snapper = QgsInternalGeometrySnapper(tolerance, mode)
processed = 0
for f in features:
out_feature = f
out_feature.setGeometry(snapper.snapFeature(f))
writer.addFeature(out_feature)
processed += 1
feedback.setProgress(processed * self.total)
del writer
示例2: processAlgorithm
def processAlgorithm(self, parameters, context, feedback):
source = self.parameterAsSource(parameters, self.INPUT, context)
if source is None:
raise QgsProcessingException(self.invalidSourceError(parameters, self.INPUT))
reference_source = self.parameterAsSource(parameters, self.REFERENCE_LAYER, context)
if reference_source is None:
raise QgsProcessingException(self.invalidSourceError(parameters, self.REFERENCE_LAYER))
tolerance = self.parameterAsDouble(parameters, self.TOLERANCE, context)
mode = self.parameterAsEnum(parameters, self.BEHAVIOR, context)
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
source.fields(), source.wkbType(), source.sourceCrs())
if sink is None:
raise QgsProcessingException(self.invalidSinkError(parameters, self.OUTPUT))
features = source.getFeatures()
total = 100.0 / source.featureCount() if source.featureCount() else 0
if parameters[self.INPUT] != parameters[self.REFERENCE_LAYER]:
if mode == 7:
raise QgsProcessingException(self.tr('This mode applies when the input and reference layer are the same.'))
snapper = QgsGeometrySnapper(reference_source)
processed = 0
for f in features:
if feedback.isCanceled():
break
if f.hasGeometry():
out_feature = f
out_feature.setGeometry(snapper.snapGeometry(f.geometry(), tolerance, mode))
sink.addFeature(out_feature, QgsFeatureSink.FastInsert)
else:
sink.addFeature(f)
processed += 1
feedback.setProgress(processed * total)
elif mode == 7:
# input layer == ref layer
modified_count = QgsGeometrySnapperSingleSource.run(source, sink, tolerance, feedback)
feedback.pushInfo(self.tr('Snapped {} geometries.').format(modified_count))
else:
# snapping internally
snapper = QgsInternalGeometrySnapper(tolerance, mode)
processed = 0
for f in features:
if feedback.isCanceled():
break
out_feature = f
out_feature.setGeometry(snapper.snapFeature(f))
sink.addFeature(out_feature, QgsFeatureSink.FastInsert)
processed += 1
feedback.setProgress(processed * total)
return {self.OUTPUT: dest_id}
示例3: processAlgorithm
def processAlgorithm(self, parameters, context, feedback):
source = self.parameterAsSource(parameters, self.INPUT, context)
reference_source = self.parameterAsSource(parameters, self.REFERENCE_LAYER, context)
tolerance = self.parameterAsDouble(parameters, self.TOLERANCE, context)
mode = self.parameterAsEnum(parameters, self.BEHAVIOR, context)
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
source.fields(), source.wkbType(), source.sourceCrs())
features = source.getFeatures()
total = 100.0 / source.featureCount() if source.featureCount() else 0
if parameters[self.INPUT] != parameters[self.REFERENCE_LAYER]:
snapper = QgsGeometrySnapper(reference_source)
processed = 0
for f in features:
if feedback.isCanceled():
break
if f.hasGeometry():
out_feature = f
out_feature.setGeometry(snapper.snapGeometry(f.geometry(), tolerance, mode))
sink.addFeature(out_feature, QgsFeatureSink.FastInsert)
else:
sink.addFeature(f)
processed += 1
feedback.setProgress(processed * total)
else:
# snapping internally
snapper = QgsInternalGeometrySnapper(tolerance, mode)
processed = 0
for f in features:
if feedback.isCanceled():
break
out_feature = f
out_feature.setGeometry(snapper.snapFeature(f))
sink.addFeature(out_feature, QgsFeatureSink.FastInsert)
processed += 1
feedback.setProgress(processed * total)
return {self.OUTPUT: dest_id}
示例4: processAlgorithm
def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT))
reference_layer = dataobjects.getObjectFromUri(self.getParameterValue(self.REFERENCE_LAYER))
tolerance = self.getParameterValue(self.TOLERANCE)
mode = self.getParameterValue(self.BEHAVIOUR)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.fields(), layer.wkbType(), layer.crs())
features = vector.features(layer)
self.processed = 0
self.progress = progress
self.total = 100.0 / len(features)
snapper = QgsGeometrySnapper(reference_layer)
snapper.featureSnapped.connect(self.featureSnapped)
snapped_features = snapper.snapFeatures(features, tolerance, mode)
for f in snapped_features:
writer.addFeature(QgsFeature(f))
del writer