arctiff patch

D D Gray ddgray at armadce.demon.co.uk
Fri Sep 3 22:01:30 EDT 1999


Hi Grass Users

I'm posting this small patch in case it might be useful to someone. I
recently started importing large image files using the r.in.arctiff
utility in my current project, but found that the current script, which
is the same in GRASS4.2 and GRASS5, sometimes imports the header
information from the tiff file incorrectly. The problem is in the line
that imports the width/height dimensions, which sometimes reads the
wrong line depending on the system/image.

Also as I receive most of my images from a WinDOS system, occasionally
there are images with spaces in the names. The original script doesn't
import these properly, so this has been fixed with spaces replaced by
underscores in the imported raster file.

Hopefully these changes will elliminate these problems (I haven't tested
it on GRASS5 yet though). I know there are sometimes peoblems with the
r.in.tiff binary segfaulting, and of course these changes won't affect
that which is a separate issue.

# patch -p1 < r_in_arctiff.diff

in the same directory as the orig. file. [r.in.arctiff]


D D Gray
-------------- next part --------------
*** tmp/r.in.arctiff	Mon Aug 30 02:10:18 1999
--- r.in.arctiff	Mon Aug 30 15:01:05 1999
***************
*** 16,21 ****
  fi
  
  # First import the image, then create a new header with coordinates:
! r.in.tiff -v input=$1.tif output=$1
  
  #check the exit status:
--- 16,26 ----
  fi
  
+ # Convert spaces in input file name to underscores for name of 
+ # cell files.
+ 
+ cellfile=`echo $1 | sed 's/\ /_/g'`
+ 
  # First import the image, then create a new header with coordinates:
! r.in.tiff -v input="$1.tif" output=${cellfile}
  
  #check the exit status:
***************
*** 29,40 ****
  echo ""
  echo "Compressing raster file..."
! r.compress $1
  
  echo "Creating raster file header..."
  # get image information:
! tiffinfo $1.tif > /tmp/tiffinfo.txt
! XWIDTH="`grep Image /tmp/tiffinfo.txt |head -3 |tail -1 |cut -d' ' -f5`"
! YHEIGHT="`grep Image /tmp/tiffinfo.txt |head -3 |tail -1 |cut -d' ' -f8`"
! rm -f /tmp/tiffinfo.txt
  
  ## tfw-format example:
--- 34,47 ----
  echo ""
  echo "Compressing raster file..."
! r.compress ${cellfile}
  
  echo "Creating raster file header..."
  # get image information:
! 
! XWIDTH="`tiffinfo \"$1.tif\" | sed -n \
! 's/^\ *Image\ Width:\ \([0-9]*\)\ Image\ Length:\ [0-9]*$/\1/p'`"
! 
! YHEIGHT="`tiffinfo \"$1.tif\" | sed -n \
! 's/^\ *Image\ Width:\ [0-9]*\ Image\ Length:\ \([0-9]*\)$/\1/p'`"
  
  ## tfw-format example:
***************
*** 52,75 ****
  # in one line in $1.info:
     # .tfw - last line (north):
! cat $1.tfw |tail -1 > /tmp/$1.n
! sed -e '1,$s/\ //g' /tmp/$1.n > /tmp/$1.i
  
     # .tfw - last but one line (west):
! cat $1.tfw |tail -2 |head -1 > /tmp/$1.w
! sed -e '1,$s/\ //g' /tmp/$1.w >>/tmp/$1.i
  
     # .tfw - last but two line (n-s resol) and eliminate "-":
! cat $1.tfw |tail -3 |head -1 > /tmp/$1.rns
! sed -e '1,$s/\ //g' /tmp/$1.rns | sed -e '1,$s/\-//g' >>/tmp/$1.i
  
     # .tfw - first line (e-w resol):
! cat $1.tfw |head -1 > /tmp/$1.rew
! sed -e '1,$s/\ //g' /tmp/$1.rew >>/tmp/$1.i
  
! echo $XWIDTH >>/tmp/$1.i
! echo $YHEIGHT  >>/tmp/$1.i
  
     #create one line file for awk
! paste -s /tmp/$1.i > /tmp/$1.info
  rm -f /tmp/$1.i /tmp/$1.n /tmp/$1.w /tmp/$1.rns /tmp/$1.rew
  
--- 59,82 ----
  # in one line in $1.info:
     # .tfw - last line (north):
! cat "$1.tfw" |tail -1 > "/tmp/$1.n"
! sed -e '1,$s/\ //g' "/tmp/$1.n" > "/tmp/$1.i"
  
     # .tfw - last but one line (west):
! cat "$1.tfw" |tail -2 |head -1 > "/tmp/$1.w"
! sed -e '1,$s/\ //g' "/tmp/$1.w" >>"/tmp/$1.i"
  
     # .tfw - last but two line (n-s resol) and eliminate "-":
! cat "$1.tfw" |tail -3 |head -1 > "/tmp/$1.rns"
! sed -e '1,$s/\ //g' "/tmp/$1.rns" | sed -e '1,$s/\-//g' >>"/tmp/$1.i"
  
     # .tfw - first line (e-w resol):
! cat "$1.tfw" |head -1 > "/tmp/$1.rew"
! sed -e '1,$s/\ //g' "/tmp/$1.rew" >>"/tmp/$1.i"
  
! echo $XWIDTH >>"/tmp/$1.i"
! echo $YHEIGHT  >>"/tmp/$1.i"
  
     #create one line file for awk
! paste -s "/tmp/$1.i" > "/tmp/$1.info"
  rm -f /tmp/$1.i /tmp/$1.n /tmp/$1.w /tmp/$1.rns /tmp/$1.rew
  
***************
*** 78,82 ****
  
  # 1. proj and zone info:
! cat $LOCATION/WIND |head -2 > $LOCATION/cellhd/$1
  
  # structure of /tmp/$1.info 
--- 85,89 ----
  
  # 1. proj and zone info:
! cat $LOCATION/WIND |head -2 > "$LOCATION/cellhd/${cellfile}"
  
  # structure of /tmp/$1.info 
***************
*** 86,104 ****
  # 2. north and south info (take n-s res):
  north=`awk '{ distx = ( $1 + ($3 / 2)) }
!             { printf "%.4f\n", distx }' /tmp/$1.info`
  
  south=`awk '{ distx = ( $1 + ($3 / 2)) - $6 * $3 }
!             { printf "%.4f\n", distx }' /tmp/$1.info`
! echo "north:      $north" >> $LOCATION/cellhd/$1
! echo "south:      $south" >> $LOCATION/cellhd/$1
  
  # 3. west and east (take ew-res)
   west=`awk '{ disty = ( $2 - ($4 / 2)) }
!             { printf "%.4f\n", disty }' /tmp/$1.info`
   east=`awk '{ disty = ( $2 - ($4 / 2)) + $5 * $4}
!             { printf "%.4f\n", disty }' /tmp/$1.info`
  
! echo "east:       $east" >> $LOCATION/cellhd/$1
! echo "west:       $west" >> $LOCATION/cellhd/$1
  
  echo "Boundaries: north:$north, south:$south"
--- 93,111 ----
  # 2. north and south info (take n-s res):
  north=`awk '{ distx = ( $1 + ($3 / 2)) }
!             { printf "%.4f\n", distx }' "/tmp/$1.info"`
  
  south=`awk '{ distx = ( $1 + ($3 / 2)) - $6 * $3 }
!             { printf "%.4f\n", distx }' "/tmp/$1.info"`
! echo "north:      $north" >> "$LOCATION/cellhd/${cellfile}"
! echo "south:      $south" >> "$LOCATION/cellhd/${cellfile}"
  
  # 3. west and east (take ew-res)
   west=`awk '{ disty = ( $2 - ($4 / 2)) }
!             { printf "%.4f\n", disty }' "/tmp/$1.info"`
   east=`awk '{ disty = ( $2 - ($4 / 2)) + $5 * $4}
!             { printf "%.4f\n", disty }' "/tmp/$1.info"`
  
! echo "east:       $east" >> "$LOCATION/cellhd/${cellfile}"
! echo "west:       $west" >> "$LOCATION/cellhd/${cellfile}"
  
  echo "Boundaries: north:$north, south:$south"
***************
*** 106,125 ****
  
  # 4. cols and rows:
! echo "cols:       $XWIDTH"   >> $LOCATION/cellhd/$1
! echo "rows:       $YHEIGHT"  >> $LOCATION/cellhd/$1
  
  # 5. resolution:
! nsres=`awk '{ printf "%.4f\n", $3 }' /tmp/$1.info`
! ewres=`awk '{ printf "%.4f\n", $4 }' /tmp/$1.info`
  
  echo "N-S Resolution: $nsres"
  echo "W-E Resolution: $ewres"
! echo "e-w resol:  $ewres"  >> $LOCATION/cellhd/$1
! echo "n-s resol:  $nsres"  >> $LOCATION/cellhd/$1
  
  # 6. format (0=1 byte) and compressed (yes, due to r.compress) status
! echo "format:     0"  >> $LOCATION/cellhd/$1
! echo "compressed: 1"  >> $LOCATION/cellhd/$1
! rm /tmp/$1.info
  
  # The cell-header file is complete now.
--- 113,132 ----
  
  # 4. cols and rows:
! echo "cols:       $XWIDTH"   >> "$LOCATION/cellhd/${cellfile}"
! echo "rows:       $YHEIGHT"  >> "$LOCATION/cellhd/${cellfile}"
  
  # 5. resolution:
! nsres=`awk '{ printf "%.4f\n", $3 }' "/tmp/$1.info"`
! ewres=`awk '{ printf "%.4f\n", $4 }' "/tmp/$1.info"`
  
  echo "N-S Resolution: $nsres"
  echo "W-E Resolution: $ewres"
! echo "e-w resol:  $ewres"  >> "$LOCATION/cellhd/${cellfile}"
! echo "n-s resol:  $nsres"  >> "$LOCATION/cellhd/${cellfile}"
  
  # 6. format (0=1 byte) and compressed (yes, due to r.compress) status
! echo "format:     0"  >> "$LOCATION/cellhd/${cellfile}"
! echo "compressed: 1"  >> "$LOCATION/cellhd/${cellfile}"
! rm -f "/tmp/$1.info"
  
  # The cell-header file is complete now.


More information about the grass-user mailing list