Skip to content

Commit

Permalink
Changes in pointtool for continuity of single line
Browse files Browse the repository at this point in the history
  • Loading branch information
mkondratyev85 committed Dec 12, 2019
1 parent 40ce1c2 commit e413d58
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions pointtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .astar import find_path
from .line_simplification import smooth, simplify
from .utils import get_indxs_from_raster_coords, get_coords_from_raster_indxs, get_whole_raster, PossiblyIndexedImageError
from .utils import get_whole_raster, PossiblyIndexedImageError


class OutsideMapError(Exception):
Expand All @@ -30,7 +30,6 @@ def __init__(self, canvas, iface, turn_off_snap):
self.iface = iface
self.anchor_points = []
self.anchor_points_ij = []
self.last_points = []
self.is_tracing = True
self.turn_off_snap = turn_off_snap

Expand All @@ -51,7 +50,6 @@ def __init__(self, canvas, iface, turn_off_snap):
self.marker_snap = QgsVertexMarker(self.canvas())
self.marker_snap.setColor(QColor(255, 0, 255))

self.is_new_line_segment = True

def snap_tolerance_changed(self, snap_tolerance):
self.snap_tolerance = snap_tolerance
Expand Down Expand Up @@ -131,11 +129,6 @@ def keyPressEvent(self, e):
if vlayer.featureCount() < 1: return

remove_last_feature(vlayer)
self.last_points.pop()
print(len(self.last_points))
#if len(self.last_points)=1:



# remove last marker
if len(self.markers)>0:
Expand Down Expand Up @@ -203,6 +196,7 @@ def canvasReleaseEvent(self, mouseEvent):
self.iface.messageBar().pushMessage("Missing Layer",
"Please select raster layer to trace",
level=Qgis.Warning, duration=2)

self.last_mouse_event_pos = mouseEvent.pos()
# hide rubber_band
self.rubber_band.hide()
Expand All @@ -211,9 +205,6 @@ def canvasReleaseEvent(self, mouseEvent):
# finish point path if it was last point
self.anchor_points = []

self.is_new_line_segment = True
self.last_points = []

# hide all markers
while len(self.markers)>0:
marker = self.markers.pop()
Expand All @@ -237,7 +228,6 @@ def canvasReleaseEvent(self, mouseEvent):

# we need at least two points to draw
if len(self.anchor_points)<2:
self.last_points.append((x1,y1))
return

if self.is_tracing:
Expand All @@ -256,19 +246,21 @@ def canvasReleaseEvent(self, mouseEvent):
path = find_path(grid.astype(np.dtype('l')), start_point, end_point)
path = smooth(path, size=5)
path = simplify(path)
current_last_point = self.to_coords(*path[-1])
path_ref = [self.to_coords_provider(i,j) for i,j in path]
else:
x0, y0 = self.anchor_points[-2]
path_ref = [self.to_coords_provider2(x0,y0),
self.to_coords_provider2(x1,y1)]
current_last_point = (x1,y1)

if self.is_new_line_segment:
if len(self.anchor_points) == 2:
add_features_to_vlayer(vlayer, path_ref)
self.is_new_line_segment=False
else:
path_ref = [self.last_points[-1]] + path_ref[1:]
last_point = self.to_coords_provider2(*self.anchor_points[-2])
path_ref = [last_point] + path_ref[1:]
add_to_last_feature(vlayer, path_ref)
self.last_points.append(path_ref[-1])
self.anchor_points[-1] = current_last_point
self.redraw()


Expand Down

0 comments on commit e413d58

Please sign in to comment.