[GRASS-user] Re: grass-user Digest, Vol 33, Issue 39
Moritz Lennert
mlennert at club.worldonline.be
Wed Jan 21 11:43:37 EST 2009
Richard,
(almost missed you question because of the digest subject line...)
On 20/01/09 05:10, Richard Chirgwin wrote:
>> I think that a GRASS module for connecting lines between chosen points
>> is a definite yes (think of point coordinates of airports with
>> information about flight connections between airports). Up to now I've
>> been doing it with a simple script + v.in.ascii.
>>
> I think a module would be wonderful, since I've struggled with this task
> a few times. Would it be rude to ask about your script, Moritz?
Now that Martin has implemented it in v.net, this is probably mostly
hypothetical, but I just used very simple awk magic to massage point
ascii data into lines. I.e. from an ascii file in the format of
StartX,StartY,EndX,EndY,LineCat
this command line creates the GRASS lines map:
awk -F"," 'BEGIN{i=0} {i++;print "L 2 1";print $1,$2,i;i++;print
$3,$4,i;print "1", $5 }' YourFile | v.in.ascii -n format=standard
out=YourMapName fs=" "
How to get to the input ascii file depends on your data setup, but I
would use something like this (assuming you use a real db, have one map
with points of which you would like to connect some and that you have a
table called Connections in your db in the form of StartCat, EndCat, Value):
v.addcol PointMap col="x double precision"
v.addcol PointMap col="y double precision"
v.to.db PointMap option=coor
Then, some SQL to add StartX,StartY,EndX,EndY to your table Connections.
Then update your Connections table with something like:
UPDATE Connections SET StartX = PointMap.x, StartY=PointMap.y FROM PointMap
WHERE StartCat=PointMap.cat
UPDATE Connections SET EndX = PointMap.x, EndY=PointMap.y FROM PointMap
WHERE EndCat=PointMap.cat
And then extract the relevant values in an ascii file which you can then
feed into the above awk line.
Moritz
More information about the grass-user
mailing list