[GRASS-dev] [bug #2793] (grass) v.segment: side offset is ignored

https://intevation.de/rt/webrt?serial_num=2793

Apparently Vect_point_on_line() lacks support for side offset. Indeed, it
doesn't even have such a parameter.

We can now either remove all the side_offset stuff from the manual page or
convince a developer to expand Vect_point_on_line(). The functions used in
v.buffer/v.parallel might be helpful in this regard.

Markus

-------------------------------------------- Managed by Request Tracker

Markus Neteler via RT wrote:

https://intevation.de/rt/webrt?serial_num=2793

Apparently Vect_point_on_line() lacks support for side offset. Indeed,
it doesn't even have such a parameter.

We can now either remove all the side_offset stuff from the manual
page or convince a developer to expand Vect_point_on_line(). The
functions used in v.buffer/v.parallel might be helpful in this regard.

Vect_point_on_line() is fine, the adjustment should come just after:

ret = Vect_point_on_line ( LPoints, offset1, &x, &y, &z, &angle, NULL);

/* Should Vect_point_on_line be passed the side offset here? */
/*** (YES) ***/

if(side_offset != 0.0) better? if(fabs(side_offset) > 0.0)
  shift_point_90(&x, &y, side_offset, angle);
...
Vect_append_point ( SPoints, x, y, z );

if we know the slope of the line at the point (angle*), it is easy
enough to calculate a point perpendicular to it (in the x,y plane)
offset by a certain distance with a little trig.

Vect_point_on_line()
  *angle - pointer to angle of line in that point (radians,
               counter clockwise from x axis) or NULL

with luck the line direction is ok- shift off to the left or right?

can anyone compose a nicer example for the v.segment help page?
(v.to.points -n or -v to get points?)

or is <side offset> for a threshold? (I'm not really sure how v.segment
is supposed to work)

For 6.2 we should <!-- comment out --> the references to it in the help
page.

Hamish

Markus Neteler via RT wrote:
> https://intevation.de/rt/webrt?serial_num=2793
>
> Apparently Vect_point_on_line() lacks support for side offset.
> Indeed, it doesn't even have such a parameter.

Hamish:

if we know the slope of the line at the point (angle*), it is easy
enough to calculate a point perpendicular to it (in the x,y plane)
offset by a certain distance with a little trig.

..

with luck the line direction is ok- shift off to the left or right?

see attached patch. raw & completely untested. All I know is that it
compiles.

can anyone compose a nicer example for the v.segment help page?
(v.to.points -n or -v to get points?)

Hamish

(attachments)

side_off.diff (1.68 KB)

On Thu, May 03, 2007 at 10:18:24PM +1200, Hamish wrote:

> Markus Neteler via RT wrote:
> > https://intevation.de/rt/webrt?serial_num=2793
> >
> > Apparently Vect_point_on_line() lacks support for side offset.
> > Indeed, it doesn't even have such a parameter.

Hamish:
> if we know the slope of the line at the point (angle*), it is easy
> enough to calculate a point perpendicular to it (in the x,y plane)
> offset by a certain distance with a little trig.
..
> with luck the line direction is ok- shift off to the left or right?

see attached patch. raw & completely untested. All I know is that it
compiles.

Will do, thanks.

> can anyone compose a nicer example for the v.segment help page?
> (v.to.points -n or -v to get points?)

Will try...

BTW: v.lrs.segment suffers from the same problem:
http://grass.itc.it/grass63/manuals/html63_user/v.lrs.segment.html
P <pid> <lid> <milepost>+<offset> [<side offset>]
L <sid> <lid> <milepost>+<offset> <milepost>+<offset> [<side offset>]

:slight_smile: (hint hint)

Markus

> Markus Neteler via RT wrote:
> > https://intevation.de/rt/webrt?serial_num=2793
> >
> > Apparently Vect_point_on_line() lacks support for side offset.
> > Indeed, it doesn't even have such a parameter.

Hamish:
> if we know the slope of the line at the point (angle*), it is easy
> enough to calculate a point perpendicular to it (in the x,y plane)
> offset by a certain distance with a little trig.

now functional in CVS. please test.

Backport to 6.2 or comment out references to offset in the help page?

> shift offset to the left or right?

I have set it to shift to the left as you go along the line, for little
reason other than I had to pick something and that's the side of the
road we drive on here. If there is a reason to have positive offsets
shift to the right (e.g. v.lrs or vector topology side 1,2 conventions;
Cartesian axes make +x go to the right; electro-magnetic interactions;
other..) let me know and I'll swap it.

Untested on 3D points & lines. Right now it outputs in the xy plane, but
full 3D points would be possible using Vect_point_on_line(...,slope);
(probably reuse Lat/lon code for that!) but offset is only 1D right now.
Vect_line_parallel() is only 2D AFAICT, so lines would require more
work, but would be a cool feature to have. (but again with the 1D offset)

still open:

can anyone compose a nice example (x2) for the v.segment help page?

Hamish

On Thu, May 03, 2007 at 09:53:27PM +1200, Hamish wrote:
...

can anyone compose a nicer example for the v.segment help page?
(v.to.points -n or -v to get points?)

or is <side offset> for a threshold? (I'm not really sure how v.segment
is supposed to work)

I think that you can

- generate parallel segments using <side offset> (create left and
  right lanes of a highway which you have as single line only)

   ----------------------------- back
   . . . . . . . . . . . . . . . . . . <- your original highway line
   ----------------------------- forth

- generate points along the line with <side offset>, such as

   + + + +
   ---------* +
   + + + +\ + + + + +
              *---------------
             + + + + + +

  (trees along an alley?)

Our power users may invent some nice example for Spearfish :slight_smile:

Markus

On Fri, May 04, 2007 at 12:08:02AM +1200, Hamish wrote:

> > Markus Neteler via RT wrote:
> > > https://intevation.de/rt/webrt?serial_num=2793
> > >
> > > Apparently Vect_point_on_line() lacks support for side offset.
> > > Indeed, it doesn't even have such a parameter.
>
> Hamish:
> > if we know the slope of the line at the point (angle*), it is easy
> > enough to calculate a point perpendicular to it (in the x,y plane)
> > offset by a certain distance with a little trig.

now functional in CVS. please test.

Excellent:

d.vect myrailroads disp=shape,dir
echo "P 1 1 5000 -100" | v.segment myrailroads out=myrailroads_segp2
d.vect myrailroads_segp2 col=blue
-> works (to the right of vector direction with negative side offset)

echo "L 1 1 400 5000 -100" | v.segment myrailroads out=myrailroads_segl2
d.vect myrailroads_segl2 disp=shape,dir
-> works (to the right of vector direction with negative side offset)

Backport to 6.2 or comment out references to offset in the help page?

+1 for backport.

> > shift offset to the left or right?

I have set it to shift to the left as you go along the line, for little
reason other than I had to pick something and that's the side of the
road we drive on here. If there is a reason to have positive offsets
shift to the right (e.g. v.lrs or vector topology side 1,2 conventions;
Cartesian axes make +x go to the right; electro-magnetic interactions;
other..) let me know and I'll swap it.

At least it should be consistent within GRASS.

Untested on 3D points & lines. Right now it outputs in the xy plane, but
full 3D points would be possible using Vect_point_on_line(...,slope);
(probably reuse Lat/lon code for that!) but offset is only 1D right now.
Vect_line_parallel() is only 2D AFAICT, so lines would require more
work, but would be a cool feature to have. (but again with the 1D offset)

Indeed:

with vertical offset we could easily approximate powerlines and
such for trams in the city (cable over a street). On the other
hand, v.transform with z shift already does this.

still open:
> can anyone compose a nice example (x2) for the v.segment help page?

...

Markus

Markus Neteler wrote:

> > > > https://intevation.de/rt/webrt?serial_num=2793

..

> now functional in CVS.

..

> Backport to 6.2 or comment out references to offset in the help
> page?

+1 for backport.

done.

> > > shift offset to the left or right?

Markus:

At least it should be consistent within GRASS.

I have now changed it to match Vect_line_parallel(). Positive side-
offsets now go to the right side of the line.

> > can anyone compose a nice example (x2) for the v.segment help
> > page?

Markus did this, and just now I've added a little more.

Markus:

BTW: v.lrs.segment suffers from the same problem:
http://grass.itc.it/grass63/manuals/html63_user/v.lrs.segment.html
P <pid> <lid> <milepost>+<offset> [<side offset>]
L <sid> <lid> <milepost>+<offset> <milepost>+<offset> [<side offset>]

Yes, code is mostly cloned so it would be easy to copy & paste in the
same solution.

BUG: (adding to the tracker)
There is a problem with side-offset parallel line generation for inside
corners. It is in Vect_line_parallel(), so v.parallel et al. are also
affected. See it by doing the "-500" side-offset example in the
v.segment help page and changing -500 to +500. Or "v.parallel dist=500"
using the railroads vector map.

Hamish

Markus:
> BTW: v.lrs.segment suffers from the same problem:
> http://grass.itc.it/grass63/manuals/html63_user/v.lrs.segment.html
> P <pid> <lid> <milepost>+<offset> [<side offset>]
> L <sid> <lid> <milepost>+<offset> <milepost>+<offset> [<side
> offset>]

H:

Yes, code is mostly cloned so it would be easy to copy & paste in the
same solution.

v.lrs.segment updated in 6.3 CVS to observe side_offset.

I also added a file= option to both v.segment and v.lrs.segment to read
the instructions from a file instead of stdin. This is so the modules
can work from the GUI menu where stdin is not available.

none of the v.lrs.segment changes have been tested, as I've never used
LRS. I'd appreciate if someone who has can test that the side_offset
and file= options work properly.

Hamish