[GRASSLIST:3484] Re: NMEA log to GRASS vector?

Alejandro Hinojosa alhinc at cicese.mx
Wed Apr 10 15:21:19 EDT 2002


James,
I handle NMEA sentences and waypoint downloads with awk scripts to import 
them to grass or whatever. For road tracking I regularly set the GPS to 
send only one NMEA sentence with an adjustable repeat rate. You can filter 
your multiple sentence messages from GPS with awk. I am inclunding a script 
to process $GPGLL NMEA sentences to convert tracks  into grass vector fomat 
from a NMEA log. The script eliminates consecutive equal coordinadtes and 
detects new line segments through abrupt changes in time or distance.

This is a segment of the log file

$GPGLL,3238.542,N,11526.983,W,152012,A
$GPGLL,3238.503,N,11526.969,W,152019,A
$GPGLL,3238.461,N,11526.952,W,152025,A
$GPGLL,3238.432,N,11526.940,W,152030,A
$GPGLL,3238.383,N,11526.923,W,152037,A
$GPGLL,3238.344,N,11526.909,W,152042,A
.....

This is the script to process it:
--------------------------Start of script------------

#!/bin/sh
# Escribe en format de grass ascii, archivos con trazos de caminos
# capturados con GPS  Scout Master.
#
#
uso="Error uso: $0  archivo_entrada "

         if [ $# -eq 0 ] ; then
                 echo $uso
                 exit 1;
         fi
#
         if [ $# -lt 1 ] ; then
                 echo $uso
                 exit 1;
         else
                 ifn=$1;
                 ofn=$1;
         fi

gawk -F, '
BEGIN {
         Verdadero=1;
         Falso=0;
         primero=Verdadero;
         xant=0.0;
         yant=0.0;
         umbral=0.001/60.0;
         tiempo_ant=0;
         }
function abs(numero)
{ if (numero < 0.0) return numero*-1
         else return numero
}
/$GPGLL/ {
                 if($2 ~ /./ && $4  ~ /./){
                 tiempo=substr($6,1,2)*3600 + substr($6,3,2)*60 + 
substr($6,5,2);
                 if(((tiempo-tiempo_ant) > 15) && primero ==  Falso){
                         printf("L %6d \n",nlineas);
                         for(i = 0; i < nlineas; i++)
                                 print lineas[i];
                         nlineas=0;
                 }
                 primero = Falso;
                 x=-1.0 *(substr($4,1,3)+substr($4,4,6)/60);
                 y=substr($2,1,2)+substr($2,3,6)/60;
#               printf("%6d %6d %3d\n",tiempo,tiempo_ant,tiempo-tiempo_ant);
                 tiempo_ant=tiempo;
                 if((abs(x-xant) > umbral) || (abs(y-yant) > umbral)){
                     lineas[nlineas++] = sprintf(" %.7f %.7f",y,x);
                     xant=x; yant=y;
                     noiguales++;
                 }
                 }
         }
END {
        printf("L %6d \n",nlineas);
         for(i = 0; i < nlineas; i++)
                  print lineas[i];
  # printf ("Umbral %.8f cercanos %d puntos escritos %d \n", umbral, 
iguales, noiguales)
}

' <$ifn >$ofn.1

gawk  '
BEGIN {
         xmax=-3000000;
         ymax=-3000000;
         xmin=3000000;
         ymin=3000000;
         }
         { if ($1 ~ "[0-9]") {
                 if($2 > xmax) xmax=$2;
                 if($2 < xmin) xmin=$2;
                 if($1 > ymax) ymax=$1;
                 if($1 < ymin) ymin=$1;
               }
         }
END     {
         printf("ORGANIZATION:    CICESE\n");
         printf("DIGIT DATE:      Camino GPS\n");
         printf("DIGIT NAME:      Mxli-Cienega Santa Clara\n");
         printf("MAP NAME:        Registrado GPS Trimble ScoutMAster \n");
         printf("MAP DATE:        13/Sept/2001\n");
         printf("MAP SCALE:       1000\n");
         printf("OTHER INFO:       \n");
         printf("ZONE:            0\n");
         printf("WEST EDGE:       %f\n",xmin);
         printf("EAST EDGE:       %f\n",xmax);
         printf("SOUTH EDGE:      %f\n",ymin);
         printf("NORTH EDGE:      %f\n",ymax);
         printf("MAP THRESH:       0\n");
         print("VERTI:");
         }
' <$ofn.1 >$ofn.2

# Pon encabezado
         cat $ofn.2 $ofn.1 > $ofn.grass
         rm $ofn.1 $ofn.2

------------------------End of script---------------------------

The file generated can be imported throgh v.in.ascii the projected to 
whatever with v.proj.

I hope this helps.

Alejandro HInojosa







At 08:40 AM 4/8/02 +1000, James Cameron wrote:
>Thanks for the reply.
>
>On Sun, Apr 07, 2002 at 04:27:05AM -0700, Al Green wrote:
> > I haven't used it, but s.in.garmin.sh exists.
>
>Yes, but it doesn't help if the GRASS location is in UTM.  It only
>works for lat/long databases.
>
> > Instead of having a laptop recording NMEA sentences, try downloading the
> > track data directly (can't speak for the log frequency). There is a
> > package called GPStrans out there (for linux) which will do this for you.
> > see http://sourceforge.net/projects/gpstrans
>
>Yes, I have gpstrans, and have patched it for the southern hemisphere
>to generate correct UTM (it was subtracting from false northing instead
>of adding).  However the GPS only records location and time, not HDOP,
>altitude, and the other stuff in NMEA.  Also, the GPS track is severely
>pruned in the default memory-saving mode.
>
> > http://www.linz.govt.nz/services/surveysystem/geodetic/snap/
>
>Thanks for that, I'll look into it.
>
> > http://bambi.otago.ac.nz/hamish/read_gps.m
>
>Same there.
>
>--
>James Cameron    mailto:quozl at us.netrek.org     http://quozl.netrek.org/

Alejandro Hinojosa Corona
Geology Department ,Earth Sciences Division
CICESE
P.O. Box 434843
San Diego Ca. 92143-4843

Phone + 52 646 174-5050 ext 26045
Fax     + 52 646 175-0557
                          175-0559
                 



More information about the grass-user mailing list