Easy question/v.in.ascii

James Darrell McCauley mccauley at ecn.purdue.edu
Thu Jul 14 00:46:48 EDT 1994


Steve Dzurenko (steve at ocesun1.oce.uri.EDU) writes on 13 Jul 94:
>
>Referring to my message of 13 Jul 94 (Real easy question) and Darrell McCauley's
>reply on 13 Jul 94 (Re: Real easy question), I looked at v.in.ascii and it 
>appears to convert an existing map layer in ascii format to a map layer in
>binary format.  What I need to do is convert an ascii text file consisting 
>of lat lon in two columns to a vector map layer.  As far as I can tell from
>the manual, v.in.ascii will not do this.  Does anyone know what will?

awk will do it - no problem. Try running v.out.ascii on a spearfish
vector file. Look at the format - v.in.ascii expects the data to be
in this format. Then (this is just sketchy pseudo-code)
write a quick little awk program:

BEGIN { n=0;
        printf "ORGANIZATION: oce.uri.edu\n";
        printf "DIGIT DATE:   ...
        ... /* do rest of header stuff */
      }
{
  if ($0 != "") /* we'll assume that polygons/lines are separated by
                   a blank line */
  {
     printf "A %d\n", n; /* assume coordinates are area edges */
     for(i=0;i<n;++i)
       printf " %f %f\n", x[i],y[i]; /* format specifiers may have to 
                                       be adjusted to conform to standards */
     n=0;
  }
  else
  {
    x[n]=$1; y[n++]=$2;
  }
}

Now, if these lat long coords are just points
and not area edges or lines, you can either
change the program

{
  printf "P 2\n" ;
  printf " %f %f\n %f %f\n", $1, $2, $1, $2;
}

OR use s.in.ascii, as Ken Sibley mentioned, and store
them as sites. Storage as vector may be more efficient,
depending upon the number of points you are talking about.

holler at me offline if you need help with awk.
--Darrell



More information about the grass-user mailing list