Opened 10 years ago

Last modified 6 years ago

#2649 new defect

r.to.vect diagonals defect fixed

Reported by: byronbest Owned by: grass-dev@…
Priority: normal Milestone: 7.6.2
Component: Raster Version: unspecified
Keywords: r.to.vect Cc:
CPU: x86-64 Platform: All

Description

fails to break lines when value changes along diagonals

patch for 7.0.0 attached

tested in 6.4.3 on Amazon

Attachments (11)

lines.c.patch (1.6 KB ) - added by byronbest 10 years ago.
raster/r.to.vect/lines.c patch
wrong_class_2.tiff (61.1 KB ) - added by byronbest 10 years ago.
draining top right to bottom left. The diagonal should be green
wrong_class_2a.tiff (15.4 KB ) - added by byronbest 10 years ago.
stepping over the corner. The segment needs to be three
right_class_2.tiff (59.7 KB ) - added by byronbest 10 years ago.
now r.to.vect notices another point is needed before leaving green
right_class_2a.tiff (17.4 KB ) - added by byronbest 10 years ago.
now r.to.vect correctly adds points at the edges of value changes
wrong_class_2.png (59.0 KB ) - added by byronbest 10 years ago.
can't see the TIFF? here they are as PNG
wrong_class_2a.png (13.2 KB ) - added by byronbest 10 years ago.
right_class_2.png (57.5 KB ) - added by byronbest 10 years ago.
right_class_2a.png (15.3 KB ) - added by byronbest 10 years ago.
alternative_line.grass (5.7 KB ) - added by byronbest 6 years ago.
drain on cost surface to build mask of ideal path
line_stats.grass (8.3 KB ) - added by byronbest 6 years ago.
mask and r.to.vect to make kml shapefile and csv by segment

Download all attachments as: .zip

Change History (25)

by byronbest, 10 years ago

Attachment: lines.c.patch added

raster/r.to.vect/lines.c patch

comment:1 by byronbest, 10 years ago

Component: DefaultRaster
Platform: UnspecifiedAll

comment:2 by neteler, 10 years ago

Keywords: r.to.vect added

Can you please post a test case/screenshot to better understand the problem?

by byronbest, 10 years ago

Attachment: wrong_class_2.tiff added

draining top right to bottom left. The diagonal should be green

by byronbest, 10 years ago

Attachment: wrong_class_2a.tiff added

stepping over the corner. The segment needs to be three

by byronbest, 10 years ago

Attachment: right_class_2.tiff added

now r.to.vect notices another point is needed before leaving green

by byronbest, 10 years ago

Attachment: right_class_2a.tiff added

now r.to.vect correctly adds points at the edges of value changes

comment:3 by byronbest, 10 years ago

Consider the result of r.drain, which is an already-thinned line of pixel centers, obviously in "runs" of x,y moving +/- 1 in x and/or y. We'd like for the runs be "collapsed" into only the corners where the direction changes. Further, we'd like that running the stream on another grid respect that we also need the corners where the color or value on the resulting line changes. The segments will be given the color of the pixel under the second of every pair. r.to.vect already handles these runs when they are straight in the x or y, but not in diagonals where both x and y change. The attached before/after screen shots show where this has become a visible defect.

Last edited 6 years ago by byronbest (previous) (diff)

comment:4 by neteler, 10 years ago

All the tiff attachments seem to be broken (I tried two browsers), please use PNG format for screenshots.

by byronbest, 10 years ago

Attachment: wrong_class_2.png added

can't see the TIFF? here they are as PNG

by byronbest, 10 years ago

Attachment: wrong_class_2a.png added

by byronbest, 10 years ago

Attachment: right_class_2.png added

by byronbest, 10 years ago

Attachment: right_class_2a.png added

comment:5 by mlennert, 9 years ago

Has anyone been able to take a closer look at this patch ?

comment:6 by neteler, 9 years ago

Milestone: 7.0.17.0.2

Ticket retargeted after 7.0.1 milestone closed

comment:7 by neteler, 9 years ago

Milestone: 7.0.27.0.3

Ticket retargeted after milestone closed

comment:8 by neteler, 9 years ago

Milestone: 7.0.3

Ticket retargeted after milestone closed

comment:9 by neteler, 9 years ago

Milestone: 7.0.4

Ticket retargeted after 7.0.3 milestone closed

comment:10 by martinl, 9 years ago

Milestone: 7.0.47.0.5

comment:11 by neteler, 8 years ago

Milestone: 7.0.57.0.6

comment:12 by neteler, 7 years ago

Milestone: 7.0.67.0.7

comment:13 by martinl, 6 years ago

Milestone: 7.0.77.6.2

by byronbest, 6 years ago

Attachment: alternative_line.grass added

drain on cost surface to build mask of ideal path

by byronbest, 6 years ago

Attachment: line_stats.grass added

mask and r.to.vect to make kml shapefile and csv by segment

comment:14 by byronbest, 6 years ago

The algorithm builds lines grid cell by grid cell, scanning over the entire raster row by row. The resulting line features have a cell value and a line segment, one or more grid cells long. Without my patch, the routine builds the vertex lists, lengthening the diagonal and horizontal or vertical. This is incorrect when the grid cell value changes-- the result will have a long line with the value of the last cell in the diagonal chain, instead of shorter lines with consistent value. The code is already doing runs in horizontal and vertical correctly.

Since the grid cell centers are the vertices of the result line, the value is associated with the segment from grid center to grid center neighboring, instead of the usual value change at the grid cell edges. However, for miles of line in each category, this is correct.

You may argue that the start_line should specify node=1 but since node is unused anyway, I used 0. I suspect that it is also not correct with other value types, but I only tested categorical data. The bug would show in a line feature with the entire line given the value (elevation) of the last point in long runs diagonally.

Version 1, edited 6 years ago by byronbest (previous) (next) (diff)
Note: See TracTickets for help on using tickets.