本文整理匯總了Python中qgis.analysis.QgsGeometrySnapper.snapGeometry方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsGeometrySnapper.snapGeometry方法的具體用法?Python QgsGeometrySnapper.snapGeometry怎麽用?Python QgsGeometrySnapper.snapGeometry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qgis.analysis.QgsGeometrySnapper
的用法示例。
在下文中一共展示了QgsGeometrySnapper.snapGeometry方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: processAlgorithm
# 需要導入模塊: from qgis.analysis import QgsGeometrySnapper [as 別名]
# 或者: from qgis.analysis.QgsGeometrySnapper import snapGeometry [as 別名]
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}
示例2: processAlgorithm
# 需要導入模塊: from qgis.analysis import QgsGeometrySnapper [as 別名]
# 或者: from qgis.analysis.QgsGeometrySnapper import snapGeometry [as 別名]
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}