GRASS and xfig map drawing

Jacques Bouchard bouchard at onera.fr
Wed Jan 13 06:37:55 EST 1999


> as far as I am currently working with lots of vector maps:
> Does anyone know an way to export GRASS vector maps
> to "xfig"?
> ...
> So something like a module "v.out.xfig" would be helpful for
> importing GRASS vector maps directly into xfig. 
> Did anyone start writing this or is there a different way?

Here are 2 small AWK programs that could help you:

- grass2fig converts a file that has been exported from GRASS
  in ASCII vector format (with v.export / format 2) to FIG 3.2 format

- fig2grass converts a file in FIG 3.2 format to a file in
  ASCII vector format (to be imported in GRASS with v.import / format 2)

Bye

Jacques
-------------- next part --------------
#!/bin/awk -f

# Name       : grass2fig
# Version    : 0.1
# Date       : Wed Jan 13 1999
# Author     : Jacques Bouchard
# Description: convert an ASCII vector file exported from GRASS
#              to a file in FIG 3.2 format (to be drawn with xfig)
# Usage      : grass2fig inputfile > outputfile

BEGIN {
    col["L"] = 0
    col["A"] = 1
    col["a"] = 2
    dpi=1200
    printf "#FIG 3.2\nLandscape\nCenter\nMetric\nA4\n100.00\nSingle\n-2\n%d 2\n",dpi
}

/MAP SCALE:/  {scale=$NF; fact=100./scale/2.54*dpi}
/WEST EDGE:/  {west =$NF}
/NORTH EDGE:/ {north=$NF}

/:/ {printf "#GRASSINFO - %s\n",$0}

/^ *[A-Za-z]  *[0-9]+ *$/ {
    printf "2 1 0 1 %d 7 100 0 -1 0.000 0 0 -1 0 0 %d\n",col[$1],$2
}

NF == 2 && /^[ 0-9.+-]*$/ {
    x = ($2 - west) * fact
    y = (north - $1) * fact
    printf "%10d %10d\n",x,y
}
-------------- next part --------------
#!/bin/awk -f

# Name       : fig2grass
# Version    : 0.1
# Date       : Wed Jan 13 1999
# Author     : Jacques Bouchard
# Description: convert a file in FIG 3.2 format
#              to an ASCII vector file to be imported in GRASS
# Usage      : fig2grass inputfile > outputfile

BEGIN {
    col[0] = "L"
    col[1] = "A"
    col[2] = "a"
}

/MAP SCALE:/  {scale=$NF; fact=100./scale/2.54*dpi}
/WEST EDGE:/  {west =$NF}
/NORTH EDGE:/ {north=$NF}

/#GRASSINFO - / {gsub("#GRASSINFO - ",""); print $0}

NF == 16 {
    printf "%s  %s\n",col[$5],$16
}

/^[^#]/ && !/:/ && NF == 2 {
    if (dpi == 0) {
        dpi = $1 + 0
        if (dpi == 0) {
            printf "*** WRONG FIG 3.2 FORMAT ! ***\n"
            exit 1
        }
    } else {
        x =  $1 / fact + west
        y = north - $2 / fact
        printf "%10.2f %10.2f\n",y,x
    }
}


More information about the grass-user mailing list