[GRASS-user] Re: Importing lines from database

Seb spluque at gmail.com
Fri May 29 11:58:31 EDT 2009

On Mon, 14 Jan 2008 14:43:33 +0100,
Moritz Lennert <mlennert at club.worldonline.be> wrote:

> 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...

Is this still the best solution for creating lines from a points ASCII
file?  So assuming one has an ASCII file like:

---<--------------------cut here---------------start------------------->---
---<--------------------cut here---------------end--------------------->---

and we'd like to create lines for each code in the "id" column, we'd
have to reformat the file so that it conforms to the "standard" GRASS
format for ASCII lines files?  If so, it seems we'd also need to recode
such an "id" column into integer, so that it can be used as category.
Or perhaps there is a better approach to importing this kind of data
that are typical in animal tracking studies, where coordinates
correspond to measurements taken at sequential times for each animal
(id)?  Thanks in advance for any input.


More information about the grass-user mailing list