當前位置: 首頁>>代碼示例>>Python>>正文


Python QgsGeometrySnapper.snapFeature方法代碼示例

本文整理匯總了Python中qgis.analysis.QgsGeometrySnapper.snapFeature方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsGeometrySnapper.snapFeature方法的具體用法?Python QgsGeometrySnapper.snapFeature怎麽用?Python QgsGeometrySnapper.snapFeature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在qgis.analysis.QgsGeometrySnapper的用法示例。


在下文中一共展示了QgsGeometrySnapper.snapFeature方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: processAlgorithm

# 需要導入模塊: from qgis.analysis import QgsGeometrySnapper [as 別名]
# 或者: from qgis.analysis.QgsGeometrySnapper import snapFeature [as 別名]
    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
開發者ID:cayetanobv,項目名稱:QGIS,代碼行數:35,代碼來源:SnapGeometries.py

示例2: processAlgorithm

# 需要導入模塊: from qgis.analysis import QgsGeometrySnapper [as 別名]
# 或者: from qgis.analysis.QgsGeometrySnapper import snapFeature [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}
開發者ID:yoichigmf,項目名稱:QGIS,代碼行數:58,代碼來源:SnapGeometries.py

示例3: processAlgorithm

# 需要導入模塊: from qgis.analysis import QgsGeometrySnapper [as 別名]
# 或者: from qgis.analysis.QgsGeometrySnapper import snapFeature [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}
開發者ID:nyalldawson,項目名稱:QGIS,代碼行數:44,代碼來源:SnapGeometries.py


注:本文中的qgis.analysis.QgsGeometrySnapper.snapFeature方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。