Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions freehandediting.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def initGui(self):
# Add toolbar button and menu item
self.iface.digitizeToolBar().addAction(self.freehand_edit)
self.iface.editMenu().addAction(self.freehand_edit)

# Set up the keyboard shortcut
self.shortcut = QShortcut(QKeySequence("Ctrl+Shift+E"), self.iface.mainWindow())
self.shortcut.activated.connect(self.activateFreehandTool)

self.spinBox = QDoubleSpinBox(self.iface.mainWindow())
self.spinBox.setDecimals(3)
Expand Down Expand Up @@ -103,6 +107,13 @@ def initGui(self):
# Get the tool
self.tool = FreehandEditingTool(self.canvas)

def activateFreehandTool(self):
# Check if the current layer is compatible with the Freehand Editing Tool
layer = self.canvas.currentLayer()
if layer and layer.isEditable() and (layer.geometryType() == QgsWkbTypes.LineGeometry or layer.geometryType() == QgsWkbTypes.PolygonGeometry):
# Activate the Freehand Editing Tool
self.freehandediting()

def tolerancesettings(self):
settings = QSettings()
settings.setValue("/freehandEdit/tolerance", self.spinBox.value())
Expand Down Expand Up @@ -170,15 +181,20 @@ def createFeature(self, geom):

if layer.crs().projectionAcronym() == "longlat":
tolerance = 0.000
print("0 tolerance")
else:
tolerance = settings.value("/freehandEdit/tolerance",
0.000, type=float)
print("punkt oder komma ", tolerance)

#On the Fly reprojection.
if layerCRSSrsid != projectCRSSrsid:
p = QgsCoordinateReferenceSystem("EPSG:"+str(projectCRSSrsid))
l = QgsCoordinateReferenceSystem("EPSG:"+str(layerCRSSrsid))
geom.transform(QgsCoordinateTransform(p,l,QgsProject.instance()))


print(tolerance,"tolerance")
s = geom.simplify(tolerance)

#validate geometry
Expand Down