Skip to content

Commit

Permalink
Implemented smoothing parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroalberti committed Jun 2, 2019
1 parent b3233f8 commit 78f2f72
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 49 deletions.
2 changes: 1 addition & 1 deletion beePen_QWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def setup_gui(self):

pen_layout.addWidget(self.pencolor_QgsColorButtonV2)

line_advanced_QPushButton = QPushButton("Advanced parameters")
line_advanced_QPushButton = QPushButton("Smooth parameters")
line_advanced_QPushButton.clicked.connect(self.open_advanced_form)
pen_layout.addWidget(line_advanced_QPushButton)

Expand Down
58 changes: 41 additions & 17 deletions beePen_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,37 +206,61 @@ def createFeature(self, geom):

layerCRSSrsid = layer_crs.srsid()
projectCRSSrsid = project_crs.srsid()
f = QgsFeature()
feature = QgsFeature()

# on-the-fly re-projection

if layerCRSSrsid != projectCRSSrsid:
geom.transform(
QgsCoordinateTransform(
project_crs,
layer_crs,
QgsProject.instance()))

# simplification and smoothing section

settings = QSettings()
simplify_tolerance=settings.value("/%s/simplify_tolerance" % self.plugin_name, 0.0, type=float)
smooth_iterations=settings.value("/%s/smooth_iterations" % self.plugin_name, 0, type=int)
smooth_offset=settings.value("/%s/smooth_offset" % self.plugin_name, 0.25, type=float)
smooth_mindistance=settings.value("/%s/smooth_mindistance" % self.plugin_name, -1.0, type=float)
smooth_maxangle=settings.value("/%s/smooth_maxangle" % self.plugin_name, 180.0, type=float)

# let the feature unchanged when CRS is in polar coordinates

if layer.crs().projectionAcronym() == "longlat":
tolerance = 0.000
simplify_tolerance = 0.0
smooth_iterations = 0

if simplify_tolerance:
s = geom.simplify(simplify_tolerance)
else:
settings = QSettings()
tolerance = settings.value("/%s/tolerance" % self.plugin_name,
0.000,
type=float)
s = geom

# on-the-fly re-projection
if smooth_iterations:
s = s.smooth(
iterations=smooth_iterations,
offset=smooth_offset,
minimumDistance=smooth_mindistance,
maxAngle=smooth_maxangle
)

if layerCRSSrsid != projectCRSSrsid:
geom.transform(QgsCoordinateTransform(project_crs,
layer_crs,
QgsProject.instance()))
s = geom.simplify(tolerance)
del geom
feature.setGeometry(s)

f.setGeometry(s)
del geom

# add attribute fields to feature

fields = layer.fields()
f.initAttributes(fields.count())
feature.initAttributes(fields.count())
record_values = [self.beePen_QWidget.pencil_width,
self.beePen_QWidget.color_name,
note]
for ndx, value in enumerate(record_values):
f.setAttribute(ndx, value)
layer.addFeature(f)
feature.setAttribute(ndx, value)

layer.addFeature(feature)

layer.commitChanges()

def deleteFeatures(self, geom):
Expand Down
93 changes: 62 additions & 31 deletions dialog_line.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>291</width>
<height>430</height>
<width>344</width>
<height>459</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -16,8 +16,8 @@
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>360</y>
<x>50</x>
<y>410</y>
<width>191</width>
<height>32</height>
</rect>
Expand All @@ -32,8 +32,8 @@
<widget class="QDoubleSpinBox" name="simplify_tolerance">
<property name="geometry">
<rect>
<x>171</x>
<y>70</y>
<x>200</x>
<y>133</y>
<width>71</width>
<height>32</height>
</rect>
Expand All @@ -45,8 +45,8 @@
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>31</x>
<y>30</y>
<x>60</x>
<y>93</y>
<width>141</width>
<height>18</height>
</rect>
Expand All @@ -69,8 +69,8 @@
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>31</x>
<y>130</y>
<x>60</x>
<y>187</y>
<width>141</width>
<height>18</height>
</rect>
Expand All @@ -93,8 +93,8 @@
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>40</x>
<y>77</y>
<x>69</x>
<y>140</y>
<width>60</width>
<height>18</height>
</rect>
Expand All @@ -106,24 +106,21 @@
<widget class="QSpinBox" name="smooth_iterations">
<property name="geometry">
<rect>
<x>171</x>
<y>169</y>
<x>200</x>
<y>226</y>
<width>71</width>
<height>32</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Number of smoothing iterations to run. More iterations results in a smoother geometry&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>40</x>
<y>176</y>
<x>69</x>
<y>233</y>
<width>60</width>
<height>18</height>
</rect>
Expand All @@ -138,8 +135,8 @@
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>40</x>
<y>214</y>
<x>69</x>
<y>271</y>
<width>38</width>
<height>18</height>
</rect>
Expand All @@ -154,8 +151,8 @@
<widget class="QDoubleSpinBox" name="smooth_offset">
<property name="geometry">
<rect>
<x>171</x>
<y>207</y>
<x>200</x>
<y>264</y>
<width>71</width>
<height>32</height>
</rect>
Expand All @@ -176,8 +173,8 @@
<widget class="QDoubleSpinBox" name="smooth_mindistance">
<property name="geometry">
<rect>
<x>171</x>
<y>245</y>
<x>200</x>
<y>302</y>
<width>71</width>
<height>32</height>
</rect>
Expand All @@ -195,8 +192,8 @@
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>40</x>
<y>252</y>
<x>69</x>
<y>309</y>
<width>114</width>
<height>18</height>
</rect>
Expand All @@ -211,8 +208,8 @@
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>40</x>
<y>290</y>
<x>69</x>
<y>347</y>
<width>99</width>
<height>18</height>
</rect>
Expand All @@ -227,8 +224,8 @@
<widget class="QDoubleSpinBox" name="smooth_maxangle">
<property name="geometry">
<rect>
<x>171</x>
<y>283</y>
<x>200</x>
<y>340</y>
<width>71</width>
<height>32</height>
</rect>
Expand All @@ -243,6 +240,40 @@
<double>180.000000000000000</double>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>701</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<italic>true</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Line smoothing parameters </string>
</property>
</widget>
<widget class="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>20</x>
<y>50</y>
<width>321</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>(work only for projected layers, i.e. not in lat-long)</string>
</property>
</widget>
</widget>
<resources/>
<connections>
Expand Down
1 change: 1 addition & 0 deletions freehandeditingtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def canvasReleaseEvent(self, event):
geom = None

# reset rubberband and refresh the canvas

self.rb.reset()
self.rb = None
self.canvas.refresh()
Expand Down

0 comments on commit 78f2f72

Please sign in to comment.