当前位置: 首页>>代码示例>>Python>>正文


Python QgsSpatialIndex.deleteFeature方法代码示例

本文整理汇总了Python中qgis.core.QgsSpatialIndex.deleteFeature方法的典型用法代码示例。如果您正苦于以下问题:Python QgsSpatialIndex.deleteFeature方法的具体用法?Python QgsSpatialIndex.deleteFeature怎么用?Python QgsSpatialIndex.deleteFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core.QgsSpatialIndex的用法示例。


在下文中一共展示了QgsSpatialIndex.deleteFeature方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: processAlgorithm

# 需要导入模块: from qgis.core import QgsSpatialIndex [as 别名]
# 或者: from qgis.core.QgsSpatialIndex import deleteFeature [as 别名]
    def processAlgorithm(self, parameters, context, feedback):
        """
        Here is where the processing itself takes place.
        """

        # Retrieve the feature source and sink. The 'dest_id' variable is used
        # to uniquely identify the feature sink, and must be included in the
        # dictionary returned by the processAlgorithm function.
        couche_lines = self.parameterAsVectorLayer(parameters, self.LINES, context)
        couche_points = self.parameterAsVectorLayer(parameters, self.NODES, context)
        radius=self.parameterAsDouble(parameters,self.RAYON,context)

        # Compute the number of steps to display within the progress bar and
        # get features from source
        delta=float(radius)
        index=QgsSpatialIndex()
        lines=couche_lines.getFeatures()
        for i in lines:
            if i.geometry().isMultipart():
                i.setGeometry(QgsGeometry.fromPolylineXY(i.geometry().asMultiPolyline()[0]))
            index.insertFeature(i)

        couche_lines.startEditing()
        couche_lines.beginEditCommand(self.tr("Split polylines at connections"))
        points=couche_points.getFeatures()
        nb=couche_points.featureCount()
        feedback.setProgressText(self.tr("Connecting points to lines..."))
        for pos,pt in enumerate(points):
            feedback.setProgress(pos*100.0/nb)
            ptg=pt.geometry()
            if ptg.isMultipart():
                ptg=QgsGeometry.fromPoint(ptg.asMultiPoint()[0])
            coor=ptg.asPoint()
            nearest=index.intersects(QgsRectangle(coor.x()-delta,coor.y()-delta,coor.x()+delta,coor.y()+delta))
            dmin=1e38
            if len(nearest)>0:
                for n in nearest:
                    f=couche_lines.getFeatures(request=QgsFeatureRequest(n))
                    for g in f:
                        d=g.geometry().distance(pt.geometry())
                        if d<=dmin:
                            dmin=d
                            gmin=g
                            gid=g.id()
                g=gmin
                if g.geometry().distance(pt.geometry())<delta:
                    a=g.geometry().closestSegmentWithContext(ptg.asPoint())
                    if not(a[2]==0):
                        geom=g.geometry()
                        geom.convertToSingleType()
                        geom_id=g.id()
                        att=g.attributes()
                        connexion=QgsFeature()
                        connexion.setGeometry(QgsGeometry.fromPolylineXY([ptg.asPoint(),a[1]]))
                        connexion.setAttributes(att)
                        couche_lines.addFeature(connexion)
                        geom.insertVertex(a[1][0],a[1][1],a[2])
                        geoma=geom.asPolyline()[:a[2]+1]
                        geomb=geom.asPolyline()[a[2]:]
                        feedback.setProgressText(unicode(geomb))
                        fa=QgsFeature()
                        fa.setGeometry(QgsGeometry.fromPolylineXY(geoma))
                        fa.setAttributes(att)
                        couche_lines.addFeature(fa)
                        index.insertFeature(fa)
                        fb=QgsFeature()
                        fb.setGeometry(QgsGeometry.fromPolylineXY(geomb))
                        fb.setAttributes(att)
                        couche_lines.addFeature(fb)
                        index.insertFeature(fb)
                        couche_lines.deleteFeature(g.id())
                        index.deleteFeature(g)
        couche_lines.commitChanges()
        couche_lines.endEditCommand()
        return {self.LINES: 'OK'}
开发者ID:crocovert,项目名称:networks,代码行数:77,代码来源:connect_nodes2lines.py


注:本文中的qgis.core.QgsSpatialIndex.deleteFeature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。