def vertexSnapped(self, snapResult): if not self.doIgnoreTool: snappedVertex = snapResult[0][0] snappedFid = snapResult[2][0] layer = self.iface.activeLayer() thisRing = None feat = dtutils.dtGetFeatureForId(layer, snappedFid) if feat != None: geom = feat.geometry() rings = dtutils.dtExtractRings(geom) 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 ring")) if self.iface.openFeatureForm(layer, newFeat, True): # let user edit attributes newFeat.setGeometry(thisRing) layer.addFeature(newFeat) layer.endEditCommand() self.canvas.refresh() else: layer.destroyEditCommand() self.tool.clear()
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()
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()
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: newFeat = dtutils.dtCreateFeature(layer) if self.iface.openFeatureForm(layer, newFeat, True): # let user edit attributes layer.beginEditCommand( QtCore.QCoreApplication.translate( "editcommand", "Fill ring")) newFeat.setGeometry(thisRing) layer.addFeature(newFeat) layer.endEditCommand() self.canvas.refresh() self.tool.clear()
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()
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()
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()