Ejemplo n.º 1
0
    def process(self):
        layer = self.iface.activeLayer()
        layer.featureAdded.connect(self.featureAdded)
        numRingsFilled = 0
        aborted = False

        for featureToFill in layer.selectedFeatures():
            geom = featureToFill.geometry()
            rings = dtutils.dtExtractRings(geom)

            for aRing in rings:

                if numRingsFilled == 0:
                    defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(layer)
                    layer.beginEditCommand(QtCore.QCoreApplication.translate("editcommand", "Fill rings"))

                    if self.iface.vectorLayerTools().addFeature(layer, defaultValues = defaultAttributeMap, defaultGeometry = aRing):
                        layer.featureAdded.disconnect(self.featureAdded)
                    else:
                        layer.featureAdded.disconnect(self.featureAdded)
                        layer.destroyEditCommand()
                        aborted = True
                        break
                else:
                    aFeat = dtutils.dtCopyFeature(layer,  srcFid = self.newFid)
                    aFeat.setGeometry(aRing)
                    layer.addFeature(aFeat)

                numRingsFilled += 1

                if aborted:
                    break

        layer.endEditCommand()
        self.canvas.refresh()
Ejemplo n.º 2
0
    def vertexSnapped(self,  snapResult):
        snappedVertex = snapResult[0][0]
        snappedFid = snapResult[2][0]
        layer = self.iface.activeLayer()
        feat = dtutils.dtGetFeatureForId(layer,  snappedFid)

        if feat != None:
            geom = feat.geometry()
            rings = dtutils.dtExtractRings(geom)
            thisRing = None

            for aRing in rings:
                for aPoint in dtutils.dtExtractPoints(aRing):
                    if aPoint.x() == snappedVertex.x() and aPoint.y() == snappedVertex.y():
                        thisRing = aRing
                        break

            if thisRing != None:
                defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(layer)
                layer.beginEditCommand(QtCore.QCoreApplication.translate("editcommand", "Fill ring"))

                if self.iface.vectorLayerTools().addFeature(layer, defaultValues = defaultAttributeMap, defaultGeometry = thisRing):
                    layer.endEditCommand()
                    self.canvas.refresh()
                else:
                    layer.destroyEditCommand()

        self.tool.reset()
Ejemplo n.º 3
0
    def vertexSnapped(self, snapResult):
        snappedVertex = snapResult[0][0]
        snappedFid = snapResult[2][0]
        layer = self.iface.activeLayer()
        feat = dtutils.dtGetFeatureForId(layer, snappedFid)

        if feat != None:
            geom = feat.geometry()
            rings = dtutils.dtExtractRings(geom)
            thisRing = None

            for aRing in rings:
                for aPoint in dtutils.dtExtractPoints(aRing):
                    if aPoint.x() == snappedVertex.x() and aPoint.y(
                    ) == snappedVertex.y():
                        thisRing = aRing
                        break

            if thisRing != None:
                defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(layer)
                layer.beginEditCommand(
                    QtCore.QCoreApplication.translate("editcommand",
                                                      "Fill ring"))

                if self.iface.vectorLayerTools().addFeature(
                        layer,
                        defaultValues=defaultAttributeMap,
                        defaultGeometry=thisRing):
                    layer.endEditCommand()
                    self.canvas.refresh()
                else:
                    layer.destroyEditCommand()

        self.tool.reset()
Ejemplo n.º 4
0
    def process(self):
        # DtDualTool makes sure a selection exists
        layer = self.iface.activeLayer()
        multiGeom = dtutils.dtCombineSelectedPolygons(layer, self.iface)

        if multiGeom != None:
            rings = dtutils.dtExtractRings(multiGeom)

            if len(rings) == 0:
                self.iface.messageBar().pushWarning(
                    self.title,
                    QtCore.QCoreApplication.translate(
                        "digitizingtools",
                        "There are no gaps between the polygons."))
            else:
                defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(layer)
                layer.featureAdded.connect(self.featureAdded)
                numRingsFilled = 0
                aborted = False

                for aRing in rings:
                    if numRingsFilled == 0:
                        layer.beginEditCommand(
                            QtCore.QCoreApplication.translate(
                                "editcommand", "Fill gaps"))

                        if self.iface.vectorLayerTools().addFeature(
                                layer,
                                defaultValues=defaultAttributeMap,
                                defaultGeometry=aRing):
                            layer.featureAdded.disconnect(self.featureAdded)
                        else:
                            layer.featureAdded.disconnect(self.featureAdded)
                            aborted = True
                            break
                    else:
                        aFeat = dtutils.dtCopyFeature(layer,
                                                      srcFid=self.newFid)
                        aFeat.setGeometry(aRing)
                        layer.addFeature(aFeat)

                    numRingsFilled += 1

                if aborted:
                    layer.destroyEditCommand()
                else:
                    layer.endEditCommand()

            self.canvas.refresh()
Ejemplo n.º 5
0
    def gapFound(self, result):
        layer = self.iface.activeLayer()
        gap = result[0]
        defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(layer)
        layer.beginEditCommand(QtCore.QCoreApplication.translate(
            "editcommand", "Fill gap"))

        if self.iface.vectorLayerTools().addFeature(layer,
                defaultValues = defaultAttributeMap, defaultGeometry = gap):
            layer.endEditCommand()
            self.canvas.refresh()
        else:
            layer.destroyEditCommand()

        self.tool.reset()
Ejemplo n.º 6
0
    def gapFound(self, result):
        layer = self.iface.activeLayer()
        gap = result[0]
        defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(layer)
        layer.beginEditCommand(
            QtCore.QCoreApplication.translate("editcommand", "Fill gap"))

        if self.iface.vectorLayerTools().addFeature(
                layer, defaultValues=defaultAttributeMap, defaultGeometry=gap):
            layer.endEditCommand()
            self.canvas.refresh()
        else:
            layer.destroyEditCommand()

        self.tool.reset()
Ejemplo n.º 7
0
    def process(self):
        layer = self.iface.activeLayer()
        layer.featureAdded.connect(self.featureAdded)
        numRingsFilled = 0
        aborted = False

        for featureToFill in layer.selectedFeatures():
            geom = QgsGeometry(featureToFill.geometry())

            if not geom.isGeosValid():
                thisWarning = dtutils.dtGetInvalidGeomWarning(layer)
                dtutils.dtShowWarning(self.iface, thisWarning)
                continue

            rings = dtutils.dtExtractRings(geom)

            for aRing in rings:

                if numRingsFilled == 0:
                    defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(
                        layer)
                    layer.beginEditCommand(
                        QtCore.QCoreApplication.translate(
                            "editcommand", "Fill rings"))

                    if self.iface.vectorLayerTools().addFeature(
                            layer,
                            defaultValues=defaultAttributeMap,
                            defaultGeometry=aRing):
                        layer.featureAdded.disconnect(self.featureAdded)
                    else:
                        layer.featureAdded.disconnect(self.featureAdded)
                        layer.destroyEditCommand()
                        aborted = True
                        break
                else:
                    aFeat = dtutils.dtCopyFeature(layer, srcFid=self.newFid)
                    aFeat.setGeometry(aRing)
                    layer.addFeature(aFeat)

                numRingsFilled += 1

                if aborted:
                    break

        layer.endEditCommand()
        self.canvas.refresh()
Ejemplo n.º 8
0
    def process(self):
        # DtDualTool makes sure a selection exists
        layer = self.iface.activeLayer()
        multiGeom = dtutils.dtCombineSelectedPolygons(layer, self.iface)

        if multiGeom != None:
            rings = dtutils.dtExtractRings(multiGeom)

            if len(rings) == 0:
                self.iface.messageBar().pushMessage(self.title,
                    QtCore.QCoreApplication.translate("digitizingtools",
                    "There are no gaps between the polygons."),
                    level=QgsMessageBar.WARNING, duration = 10)
            else:
                defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(layer)
                layer.featureAdded.connect(self.featureAdded)
                numRingsFilled = 0
                aborted = False

                for aRing in rings:
                    if numRingsFilled == 0:
                        layer.beginEditCommand(QtCore.QCoreApplication.translate(
                            "editcommand", "Fill gaps"))

                        if self.iface.vectorLayerTools().addFeature(
                                layer, defaultValues = defaultAttributeMap, defaultGeometry = aRing):
                            layer.featureAdded.disconnect(self.featureAdded)
                        else:
                            layer.featureAdded.disconnect(self.featureAdded)
                            aborted = True
                            break
                    else:
                        aFeat = dtutils.dtCopyFeature(layer, srcFid = self.newFid)
                        aFeat.setGeometry(aRing)
                        layer.addFeature(aFeat)

                    numRingsFilled += 1

                if aborted:
                    layer.destroyEditCommand()
                else:
                    layer.endEditCommand()

            self.canvas.refresh()
Ejemplo n.º 9
0
    def fillGaps(self, snappedVertex=None):
        title = QtCore.QCoreApplication.translate("digitizingtools",
                                                  "Fill gap")
        layer = self.iface.activeLayer()
        hasNoSelection = (layer.selectedFeatureCount() == 0)

        if hasNoSelection:
            layer.invertSelection()

        multiGeom = None

        for aFeat in layer.selectedFeatures():
            aGeom = aFeat.geometry()

            if not aGeom.isGeosValid():
                self.iface.messageBar().pushMessage(
                    title,
                    dtutils.dtGetInvalidGeomWarning(layer),
                    level=QgsMessageBar.CRITICAL)
                return None

            # fill rings contained in the polygon
            if aGeom.isMultipart():
                tempGeom = None

                for poly in aGeom.asMultiPolygon():
                    noRingGeom = dtutils.dtDeleteRings(poly)

                    if tempGeom == None:
                        tempGeom = noRingGeom
                    else:
                        tempGeom = tempGeom.combine(noRingGeom)
            else:
                tempGeom = dtutils.dtDeleteRings(aGeom.asPolygon())

            # make a large polygon from all selected
            if multiGeom == None:
                multiGeom = tempGeom
            else:
                multiGeom = multiGeom.combine(tempGeom)

        rings = dtutils.dtExtractRings(multiGeom)

        if len(rings) == 0:
            self.iface.messageBar().pushMessage(
                title,
                QtCore.QCoreApplication.translate(
                    "digitizingtools",
                    "There are no gaps between the polygons."),
                level=QgsMessageBar.CRITICAL)
        else:
            defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(layer)

            if snappedVertex != None:
                thisRing = None

                for aRing in rings:
                    for aPoint in dtutils.dtExtractPoints(aRing):
                        if aPoint.x() == snappedVertex.x() and aPoint.y(
                        ) == snappedVertex.y():
                            thisRing = aRing
                            break

                if thisRing != None:
                    layer.beginEditCommand(
                        QtCore.QCoreApplication.translate(
                            "editcommand", "Fill gap"))

                    if self.iface.vectorLayerTools().addFeature(
                            layer,
                            defaultValues=defaultAttributeMap,
                            defaultGeometry=thisRing):
                        layer.endEditCommand()
                        self.canvas.refresh()
                    else:
                        layer.destroyEditCommand()
                else:
                    self.iface.messageBar().pushMessage(
                        title,
                        QtCore.QCoreApplication.translate(
                            "digitizingtools",
                            "The selected gap is not closed."),
                        level=QgsMessageBar.CRITICAL)
            else:
                layer.featureAdded.connect(self.featureAdded)
                numRingsFilled = 0
                aborted = False

                for aRing in rings:
                    if numRingsFilled == 0:
                        layer.beginEditCommand(
                            QtCore.QCoreApplication.translate(
                                "editcommand", "Fill gaps"))

                        if self.iface.vectorLayerTools().addFeature(
                                layer,
                                defaultValues=defaultAttributeMap,
                                defaultGeometry=aRing):
                            layer.featureAdded.disconnect(self.featureAdded)
                        else:
                            layer.featureAdded.disconnect(self.featureAdded)
                            aborted = True
                            break
                    else:
                        aFeat = dtutils.dtCopyFeature(layer,
                                                      srcFid=self.newFid)
                        aFeat.setGeometry(aRing)
                        layer.addFeature(aFeat)

                    numRingsFilled += 1

                if aborted:
                    layer.destroyEditCommand()
                else:
                    layer.endEditCommand()

            if hasNoSelection:
                layer.removeSelection()

            self.canvas.refresh()
Ejemplo n.º 10
0
    def fillGaps(self, snappedVertex = None):
        title = QtCore.QCoreApplication.translate("digitizingtools", "Fill gap")
        layer = self.iface.activeLayer()
        hasNoSelection = (layer.selectedFeatureCount() == 0)

        if hasNoSelection:
            layer.invertSelection()

        multiGeom = None

        for aFeat in layer.selectedFeatures():
            aGeom = aFeat.geometry()

            if not aGeom.isGeosValid():
                self.iface.messageBar().pushMessage(title,  dtutils.dtGetInvalidGeomWarning(layer), level=QgsMessageBar.CRITICAL)
                return None

            # fill rings contained in the polygon
            if aGeom.isMultipart():
                tempGeom = None

                for poly in aGeom.asMultiPolygon():
                    noRingGeom = dtutils.dtDeleteRings(poly)

                    if tempGeom == None:
                        tempGeom = noRingGeom
                    else:
                        tempGeom = tempGeom.combine(noRingGeom)
            else:
                tempGeom = dtutils.dtDeleteRings(aGeom.asPolygon())

            # make a large polygon from all selected
            if multiGeom == None:
                multiGeom = tempGeom
            else:
                multiGeom = multiGeom.combine(tempGeom)

        rings = dtutils.dtExtractRings(multiGeom)

        if len(rings) == 0:
            self.iface.messageBar().pushMessage(title,  QtCore.QCoreApplication.translate("digitizingtools",
                "There are no gaps between the polygons."), level=QgsMessageBar.CRITICAL)
        else:
            defaultAttributeMap = dtutils.dtGetDefaultAttributeMap(layer)

            if snappedVertex != None:
                thisRing = None

                for aRing in rings:
                    for aPoint in dtutils.dtExtractPoints(aRing):
                        if aPoint.x() == snappedVertex.x() and aPoint.y() == snappedVertex.y():
                            thisRing = aRing
                            break

                if thisRing != None:
                    layer.beginEditCommand(QtCore.QCoreApplication.translate("editcommand", "Fill gap"))

                    if self.iface.vectorLayerTools().addFeature(layer, defaultValues = defaultAttributeMap, defaultGeometry = thisRing):
                        layer.endEditCommand()
                        self.canvas.refresh()
                    else:
                        layer.destroyEditCommand()
                else:
                    self.iface.messageBar().pushMessage(title,  QtCore.QCoreApplication.translate("digitizingtools",
                        "The selected gap is not closed."), level=QgsMessageBar.CRITICAL)
            else:
                layer.featureAdded.connect(self.featureAdded)
                numRingsFilled = 0
                aborted = False

                for aRing in rings:
                    if numRingsFilled == 0:
                        layer.beginEditCommand(QtCore.QCoreApplication.translate("editcommand", "Fill gaps"))

                        if self.iface.vectorLayerTools().addFeature(layer, defaultValues = defaultAttributeMap, defaultGeometry = aRing):
                            layer.featureAdded.disconnect(self.featureAdded)
                        else:
                            layer.featureAdded.disconnect(self.featureAdded)
                            aborted = True
                            break
                    else:
                        aFeat = dtutils.dtCopyFeature(layer,  srcFid = self.newFid)
                        aFeat.setGeometry(aRing)
                        layer.addFeature(aFeat)

                    numRingsFilled += 1

                if aborted:
                    layer.destroyEditCommand()
                else:
                    layer.endEditCommand()

            if hasNoSelection:
                layer.removeSelection()

            self.canvas.refresh()