Beispiel #1
0
    def process(self):
        layer = self.iface.activeLayer()
        newFeat = dtutils.dtCreateFeature(layer)
        numRingsFilled = 0

        if self.iface.openFeatureForm(layer,  newFeat):
            for featureToFill in layer.selectedFeatures():
                geom = featureToFill.geometry()
                rings = dtutils.dtExtractRings(geom)

                for aRing in rings:

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

                    aFeat = dtutils.dtCopyFeature(layer,  newFeat)
                    aFeat.setGeometry(aRing)
                    #for i in range(layer.pendingFields().count()):
                    layer.addFeature(aFeat)
                    numRingsFilled += 1

            layer.endEditCommand()
            self.canvas.refresh()
        else:
            layer.destroyEditCommand()
Beispiel #2
0
    def process(self):
        layer = self.iface.activeLayer()
        newFeat = dtutils.dtCreateFeature(layer)
        numRingsFilled = 0

        if self.iface.openFeatureForm(layer, newFeat):
            for featureToFill in layer.selectedFeatures():
                geom = featureToFill.geometry()
                rings = dtutils.dtExtractRings(geom)

                for aRing in rings:

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

                    aFeat = dtutils.dtCopyFeature(layer, newFeat)
                    aFeat.setGeometry(aRing)
                    #for i in range(layer.pendingFields().count()):
                    layer.addFeature(aFeat)
                    numRingsFilled += 1

            layer.endEditCommand()
            self.canvas.refresh()
        else:
            layer.destroyEditCommand()
Beispiel #3
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()
Beispiel #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()
Beispiel #5
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()
Beispiel #6
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()
    def partSelected(self, part):
        fid = part[0]
        partNumber = part[1]
        aPart = part[2]
        layer = self.iface.mapCanvas().currentLayer()
        feature = dtutils.dtGetFeatureForId(layer,  fid)
        geom = QgsGeometry(feature.geometry())

        if geom.deletePart(partNumber):
            layer.beginEditCommand(QtCore.QCoreApplication.translate("editcommand", "Extract part"))
            aFeat = dtutils.dtCopyFeature(layer,  feature)
            aFeat.setGeometry(aPart)
            layer.addFeature(aFeat)
            feature.setGeometry(geom)
            layer.updateFeature(feature)
            layer.endEditCommand()
            self.canvas.refresh()

        self.tool.reset()
    def partSelected(self, part):
        fid = part[0]
        partNumber = part[1]
        aPart = part[2]
        layer = self.iface.mapCanvas().currentLayer()
        feature = dtutils.dtGetFeatureForId(layer, fid)
        geom = QgsGeometry(feature.geometry())

        if geom.deletePart(partNumber):
            layer.beginEditCommand(
                QtCore.QCoreApplication.translate("editcommand",
                                                  "Extract part"))
            aFeat = dtutils.dtCopyFeature(layer, feature)
            aFeat.setGeometry(aPart)
            layer.addFeature(aFeat)
            feature.setGeometry(geom)
            layer.updateFeature(feature)
            layer.endEditCommand()
            self.canvas.refresh()

        self.tool.reset()
Beispiel #9
0
    def vertexSnapped(self,  snapResult):
        snappedVertex = snapResult[0][0]
        fid = snapResult[2][0]
        layer = self.iface.mapCanvas().currentLayer()
        feature = dtutils.dtGetFeatureForId(layer,  fid)
        geom = feature.geometry()
        # if feature geometry is multipart start split processing
        if geom.isMultipart():
            # Get parts from original feature
            parts = geom.asGeometryCollection ()
            foundPart = False

            for i in range(len(parts)):
                # find the part that was snapped
                aPart = parts[i]
                points = dtutils.dtExtractPoints(aPart)

                for aPoint in points:
                    if aPoint.x() == snappedVertex.x() and aPoint.y() == snappedVertex.y():
                        foundPart = True
                        break

                if foundPart:
                    break

            if foundPart:
                if geom.deletePart(i):
                    layer.beginEditCommand(QtCore.QCoreApplication.translate("editcommand", "Extract part"))
                    aFeat = dtutils.dtCopyFeature(layer,  feature)
                    aFeat.setGeometry(aPart)
                    layer.addFeature(aFeat)
                    feature.setGeometry(geom)
                    layer.updateFeature(feature)
                    layer.endEditCommand()
                    self.canvas.refresh()

        self.tool.reset()
Beispiel #10
0
    def fillRings(self,  forFids):
        layer = self.iface.activeLayer()
        newFeat = dtutils.dtCreateFeature(layer)
        layer.beginEditCommand(QtCore.QCoreApplication.translate("editcommand", "Fill rings"))

        if self.iface.openFeatureForm(layer,  newFeat):
            for fid in forFids:
                featureToFill = dtutils.dtGetFeatureForId(layer,  fid)

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

                    for aRing in rings:
                        aFeat = dtutils.dtCopyFeature(layer,  newFeat)
                        aFeat.setGeometry(aRing)
                        #for i in range(layer.pendingFields().count()):

                        layer.addFeature(aFeat)

            layer.endEditCommand()
            self.canvas.refresh()
        else:
            layer.destroyEditCommand()
Beispiel #11
0
    def fillGaps(self, snappedVertex = None):
        layer = self.iface.activeLayer()
        if layer.selectedFeatureCount() == 0:
            layer.invertSelection()

        multiGeom = None

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

            if not aGeom.isGeosValid():
                QtGui.QMessageBox.warning(None,  self.title,  dtutils.dtGetInvalidGeomWarning())
                return None

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

                for poly in aGeom.asMultiPolygon():
                    noRingGeom = self.deleteRings(poly)

                    if tempGeom == None:
                        tempGeom = noRingGeom
                    else:
                        tempGeom = tempGeom.combine(noRingGeom)
            else:
                tempGeom = self.deleteRings(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:
            QtGui.QMessageBox.warning(None,  self.title,  QtCore.QCoreApplication.translate("digitizingtools",
                "There are no gaps between the polygons.") )
        else:
            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:
                    newFeat = dtutils.dtCreateFeature(layer)
                    layer.beginEditCommand(QtCore.QCoreApplication.translate("editcommand", "Fill gap"))

                    if self.iface.openFeatureForm(layer,  newFeat,  True):
                        newFeat.setGeometry(thisRing)
                        layer.addFeature(newFeat)
                        layer.endEditCommand()

                    else:
                        layer.destroyEditCommand()
                else:
                    QtGui.QMessageBox.warning(None,  self.title,  QtCore.QCoreApplication.translate("digitizingtools",
                        "The selected gap is not closed.") )
            else:
                newFeat = dtutils.dtCreateFeature(layer)
                layer.beginEditCommand(QtCore.QCoreApplication.translate("editcommand", "Fill gaps"))

                if self.iface.openFeatureForm(layer,  newFeat):
                    for aRing in rings:
                        aFeat = dtutils.dtCopyFeature(layer,  newFeat)
                        aFeat.setGeometry(aRing)
                        layer.addFeature(aFeat)

                    layer.endEditCommand()
            self.canvas.refresh()
Beispiel #12
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()
Beispiel #13
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()
Beispiel #14
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:
            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:
                    newFeat = dtutils.dtCreateFeature(layer)

                    if self.iface.openFeatureForm(layer, newFeat, True):
                        layer.beginEditCommand(
                            QtCore.QCoreApplication.translate(
                                "editcommand", "Fill gap"))
                        newFeat.setGeometry(thisRing)
                        layer.addFeature(newFeat)
                        layer.endEditCommand()
                else:
                    self.iface.messageBar().pushMessage(
                        title,
                        QtCore.QCoreApplication.translate(
                            "digitizingtools",
                            "The selected gap is not closed."),
                        level=QgsMessageBar.CRITICAL)
            else:
                newFeat = dtutils.dtCreateFeature(layer)

                if self.iface.openFeatureForm(layer, newFeat):
                    layer.beginEditCommand(
                        QtCore.QCoreApplication.translate(
                            "editcommand", "Fill gaps"))

                    for aRing in rings:
                        aFeat = dtutils.dtCopyFeature(layer, newFeat)
                        aFeat.setGeometry(aRing)
                        layer.addFeature(aFeat)

                    layer.endEditCommand()

            if hasNoSelection:
                layer.removeSelection()

            self.canvas.refresh()