[GRASS-user] Re: How to convert from point to line ?

Hermann Peifer peifer at gmx.eu
Sat Oct 10 13:48:41 EDT 2009


SGW00412 at nifty.com wrote:
> Dear all
> 
> I am a beginner user of grass gis.
> 

So am I. But as nobody else seems to have a better idea... here is what I would do:

a) reformat yourdata into GMT format (yourdata.gmt) with a small AWK script

$ awk -f reformat_to_gmt.awk yourdata > yourdata.gmt

b) import yourdata.gmt into GRASS via v.in.ogr

$ v.in.ogr -o yourdata.gmt out=yourdata

(This assumes that you already have a GRASS location with the same projection as the coordinates in your data file).

Below some more details.

Hope this helps, Hermann


$ cat yourdata
id,x,y,time
1,857.8629761,-785.6849976,1
1,987.9949951,-682.4140015,2
1,964.4849854,-710.6849976,3
2,1689.578979,-1070.564941,4
2,1654.074951,-1061.333008,5
2,1618.218018,-1040.505981,6
3,2335.930908,-1180.246948,7
3,2336.694092,-1197.869019,8
3,2336.658936,-1218.124023,9
4,2512.673096,-1689.875977,10
4,2494.010986,-1710.625977,11
5,1826.724976,-1731.743042,12
5,1808.57605,-1726.490967,13
5,1793.598999,-1723.034058,14

$ cat reformat_to_gmt.awk
BEGIN { FS = "," }

NR == 1 {
        print "# @VGMT2.0 @GLINESTRING"
        print "# @NID"
        print "# @Tinteger"
        print "# FEATURE_DATA"
        next
}

prev != $1 { print ">" ORS "# @D" $1 }

{ print $2,$3 ; prev = $1 }




$ cat yourdata.gmt
# @VGMT2.0 @GLINESTRING
# @NID
# @Tinteger
# FEATURE_DATA
>
# @D1
857.8629761 -785.6849976
987.9949951 -682.4140015
964.4849854 -710.6849976
>
# @D2
1689.578979 -1070.564941
1654.074951 -1061.333008
1618.218018 -1040.505981
>
# @D3
2335.930908 -1180.246948
2336.694092 -1197.869019
2336.658936 -1218.124023
>
# @D4
2512.673096 -1689.875977
2494.010986 -1710.625977
>
# @D5
1826.724976 -1731.743042
1808.57605 -1726.490967
1793.598999 -1723.034058



More information about the grass-user mailing list