[GRASS-user] Importing lines from database

Moritz Lennert mlennert at club.worldonline.be
Mon Jan 14 08:43:33 EST 2008


On 14/01/08 07:02, Richard Chirgwin wrote:
> All,
> 
> I have a database containing pairs of points, each with lat/long. For 
> convenience (there are lots of points) I would like to use this (and the 
> distance between the points if necessary) to create a vector map 
> containing lines joining the points. This way, I don't have to hand-draw 
> a couple of thousand lines.

If you have a text file which looks like this:

From;lat;long;To;lat;long;cat
"AJA";41.92;8.8;"MRS";43.43;5.22;103
"AJA";41.92;8.8;"NCE";43.67;7.22;95
"AJA";41.92;8.8;"ORY";48.72;2.38;98


You can use:

awk -F";" 'BEGIN{i=0} {i++;print "L 2 1";print $3,$2,i;i++;print 
$6,$5,i;print "1", $7'} YourTextFile | v.in.ascii -n format=standard 
out=NewMapName

to import it and create the GRASS line map NewMapName.

If you then create a table containing the cats (field #7 in the above 
sample):

echo "create table NewTableName (cat int)" | db.execute
v.db.connect -p NewMapName table=NewTableName

and upload the cats from the map to the table:

v.to.db map=NewMapName option=cat colum=cat

you can use the wcolumn option of d.vect to display your lines in width 
proportionate to the cat value (or add any other relevant column to your 
newly created table and use that).

> 
> I can't see any support in the database import ( v.in.db ) to do this - 
> is there some way to create lines directly from my database?

I agree that v.in.db could probably be extended to also allow straight 
line import, but currently v.in.ascii is your friend...

Moritz


More information about the grass-user mailing list