Convert points to lines

From GRASS-Wiki
Revision as of 03:24, 13 December 2010 by Neteler (talk | contribs) (+Converting CSV points file into lines map)

Jump to: navigation, search

Q: Is there a way to construct a vector line(s) map connecting selected points?

A: There are two possibilities:

Converting points map into lines map

You can use for that. The input can be generated with v.out.ascii.

Spearfish example:

  v.out.ascii archsites fs=, where="cat=1 or cat= 3"
  # so:
  v.out.ascii archsites fs=, where="cat=1 or cat= 3" | cut -d',' -f1,2 | \ in=- out=myline fs=,
  v.category in=myline out=line_with_cat option=add

Converting CSV points file into lines map

Suppose you have a CSV file "mypoints.csv" containing three point-pairs to be connected (start point coordinates, end point coordinates):


We can convert these three point pairs into three lines:

  cat mypoints.csv | grep -v "north1" | awk -F',' '{printf "%f,%f\n%f,%f\nNaN,NaN\n",$1, $2 ,$3 ,$4}' > mypoints_formatted.csv in=mypoints_formatted.csv out=mylines fs=,
  v.category in=mylines out=lines_with_cat option=add