0

I followed the answer posted by @Micha in splitting a lines layer using points, because my points were not exactly on the line, I used v.distance and v.patch described in the answer.

Then I tied to run v.clean to get snapped point vector, but I tried every cleaning tool as the following figure

enter image description here

but all results looked like the original line I used in v.distance, not point vector. How to use v.clean to get the snapped points?

I am using GRASS 7.0.5 under WIN10 64bit.


Update#1

I tried the answer posted by @Micha and successfully get those snapped coords and add to the original points attribute table via v.db.addcolumn and v.distance, but as I tried the following command, error occurred,

v.out.ascii -c -r --overwrite input=tcpoint@nl columns=snap_x,snap_y format=standard separator=comma precision=20 | v.in.ascii --o input=- output=snapped_pts x=5 y=6 cat=3 columns="east double,north double,id integer,snap_x double,snap_y double" separator=comma skip=1

enter image description here

And if I type the command in GRASS GUI, another error showed up:

enter image description here

Heinz
  • 1,545
  • 5
  • 26
  • 42
  • 1
    Perhaps v.net is the right command to use here: https://grass.osgeo.org/grass70/manuals/v.net.html – markusN Oct 23 '16 at 13:38
  • I used v.net and tried both 'connection' and 'nodes' operations but still could not get snapped point vector, instead, the output was the same line vector. Or could I get point vector using this output line vector? – Heinz Oct 23 '16 at 13:50

1 Answers1

1

Here's a way to get a point vector of point locations that are snapped to a line vector. First, using the original (not on lines) points, I add columns for the snapped X and Y coordinates. Then using v.distance, I get those snapped coords and add to the original points attribute table. And then, using v.out.ascii, I extract a table of the new snapped coords, and pipe it directly into v.in.ascii to create the new vector of snapped points.

Here's how it goes:

# Add columns to the original vector for snapped_x and snapped_y and get coordinates 
echo -e "\n** Snapping stations to streams  **"
v.db.addcolumn map=orig_pts columns="snap_x double, snap_y double
v.distance --o from=stations to=streams output=connectors upload=to_x,to_y column=snap_x,snap_y
# Create a new vector with the snap_x and snap_y columns 
# Use v.out.ascii with -r option to export only drainage point in current region
# snap_x and snap_y columns become the X-Y coordinates for point vector
v.out.ascii -r -c orig_pts columns="id,snap_x,snap_y" separator=comma | v.in.ascii --o input=- output=snapped_pts x=5 y=6 cat=3 columns="east double,north double,id integer, snap_x double,snap_y double" separator=comma skip=1   
Micha
  • 15,555
  • 23
  • 29
  • I type v.out.ascii -r -c input=tcpoint@nl columns="snap_x,snap_y" separator=comma | v.in.ascii --o input=- output=snapped_pts x=5 y=6 cat=3 columns="east double,north double,id integer, snap_x double,snap_y double" separator=comma skip=1 in GRASS but error occurred, Unable to parse command 'the above command' – Heinz Oct 25 '16 at 15:51
  • Try to separate the two parts of the command before and after the pipe '|' symbol. First do just v.out.ascii to see if it works OK. THen add to the command an output= to send the output to a file. And use that filename as input (instead of the input=-) – Micha Oct 26 '16 at 12:52