[R-sig-Geo] Byte-value tif files not properly read by readGDAL

reeves at nceas.ucsb.edu reeves at nceas.ucsb.edu
Tue Mar 16 07:10:06 CET 2010


Hello List:

I am reading an 8 bit format raster .tif image, containing 0s and 1s and
written using the Export Data utility of ArcMap GIS on a Windows 7
platform.

The image read into R does not consist of 0s and 1s, rather,  0s, 1s, and
128s.
Information from the R session (ver 2.10.1, update packages run).


R version 2.10.1 (2009-12-14)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---
trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/maptools_0.7-29.zip'
Content type 'application/zip' length 1041813 bytes (1017 Kb)
opened URL
downloaded 1017 Kb

trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/PBSmapping_2.59.zip'
Content type 'application/zip' length 6813737 bytes (6.5 Mb)
opened URL
downloaded 6.5 Mb

trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/rgdal_0.6-25.zip'
Content type 'application/zip' length 8105836 bytes (7.7 Mb)
opened URL
downloaded 7.7 Mb

trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/sp_0.9-61.zip'
Content type 'application/zip' length 706791 bytes (690 Kb)
opened URL
downloaded 690 Kb

package 'maptools' successfully unpacked and MD5 sums checked
package 'PBSmapping' successfully unpacked and MD5 sums checked
package 'rgdal' successfully unpacked and MD5 sums checked
package 'sp' successfully unpacked and MD5 sums checked

The downloaded packages are in
        D:\Documents and Settings\Rick Reeves\Local
Settings\Temp\RtmpHbLM1L\downloaded_packages
> update.packages()
foreign :
 Version 0.8-38 installed in D:/PROGRA~1/R/R-210~1.1/library
 Version 0.8-39 available at http://cran.cnr.Berkeley.edu
Update (y/N/c)?  y
lattice :
 Version 0.17-26 installed in D:/PROGRA~1/R/R-210~1.1/library
 Version 0.18-3 available at http://cran.cnr.Berkeley.edu
Update (y/N/c)?  y
MASS :
 Version 7.3-4 installed in D:/PROGRA~1/R/R-210~1.1/library
 Version 7.3-5 available at http://cran.cnr.Berkeley.edu
Update (y/N/c)?  y
Matrix :
 Version 0.999375-33 installed in D:/PROGRA~1/R/R-210~1.1/library
 Version 0.999375-37 available at http://cran.cnr.Berkeley.edu
Update (y/N/c)?  y
rpart :
 Version 3.1-45 installed in D:/PROGRA~1/R/R-210~1.1/library
 Version 3.1-46 available at http://cran.cnr.Berkeley.edu
Update (y/N/c)?  y
survival :
 Version 2.35-7 installed in D:/PROGRA~1/R/R-210~1.1/library
 Version 2.35-8 available at http://cran.cnr.Berkeley.edu
Update (y/N/c)?  y
trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/foreign_0.8-39.zip'
Content type 'application/zip' length 169133 bytes (165 Kb)
opened URL
downloaded 165 Kb

trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/lattice_0.18-3.zip'
Content type 'application/zip' length 625273 bytes (610 Kb)
opened URL
downloaded 610 Kb

trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/MASS_7.3-5.zip'
Content type 'application/zip' length 798653 bytes (779 Kb)
opened URL
downloaded 779 Kb

trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/Matrix_0.999375-37.zip'
Content type 'application/zip' length 3243307 bytes (3.1 Mb)
opened URL
downloaded 3.1 Mb

trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/rpart_3.1-46.zip'
Content type 'application/zip' length 162680 bytes (158 Kb)
opened URL
downloaded 158 Kb

trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/survival_2.35-8.zip'
Content type 'application/zip' length 2445387 bytes (2.3 Mb)
opened URL
downloaded 2.3 Mb

package 'foreign' successfully unpacked and MD5 sums checked
package 'lattice' successfully unpacked and MD5 sums checked
package 'MASS' successfully unpacked and MD5 sums checked
package 'Matrix' successfully unpacked and MD5 sums checked
package 'rpart' successfully unpacked and MD5 sums checked
package 'survival' successfully unpacked and MD5 sums checked

The downloaded packages are in
        D:\Documents and Settings\Rick Reeves\Local
Settings\Temp\RtmpHbLM1L\downloaded_packages
> require(rgdal)
Loading required package: rgdal
Loading required package: sp
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.7.1, released 2010/02/08
Path to GDAL shared files: D:/PROGRA~1/R/R-210~1.1/library/rgdal/gdal
Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009
Path to PROJ.4 shared files: D:/PROGRA~1/R/R-210~1.1/library/rgdal/proj
> setwd("F:/Projects/NCEAS/Balch")
> CheatgrassMapInfo = GDALinfo("BrteNVModisWGS8Bit.tif")
> CheatgrassMapInfo
rows        1681
columns     1748
bands       1
origin.x        -120.1789
origin.y        37.95729
res.x       0.002427655
res.y       0.002427655
oblique.x   0
oblique.y   0
driver      GTiff
projection  +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
file        BrteNVModisWGS8Bit.tif
apparent band summary:
  GDType Bmin Bmax
1   Byte -128  127
Metadata:
TIFFTAG_SOFTWARE=IMAGINE TIFF Support
Copyright 1991 - 1999 by ERDAS, Inc. All Rights Reserved
@(#)$RCSfile: etif.c $ $Revision: 1.10.1.9.1.9.2.11 $ $Date: 2004/09/15
18:42:01EDT $
TIFFTAG_XRESOLUTION=1
TIFFTAG_YRESOLUTION=1
TIFFTAG_RESOLUTIONUNIT=1 (unitless)
AREA_OR_POINT=Area
> CheatgrassMapIn = readGDAL("BrteNVModisWGS8Bit.tif")
BrteNVModisWGS8Bit.tif has GDAL driver GTiff
and has 1681 rows and 1748 columns
> summary(CheatgrassMapIn at data$band1)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
  0.000   0.000   0.000   5.248   1.000 128.000
> summary(ToUnsigned(CheatgrassMapIn at data$band1))
Error: could not find function "ToUnsigned"
Error in summary(ToUnsigned(CheatgrassMapIn at data$band1)) :
  error in evaluating the argument 'object' in selecting a method for
function 'summary'
> summary(ToUnSigned(CheatgrassMapIn at data$band1))
Error: could not find function "ToUnSigned"
Error in summary(ToUnSigned(CheatgrassMapIn at data$band1)) :
  error in evaluating the argument 'object' in selecting a method for
function 'summary'
> summary(toUnSigned(CheatgrassMapIn at data$band1))
Error in toUnSigned(CheatgrassMapIn at data$band1) : already unsigned
Error in summary(toUnSigned(CheatgrassMapIn at data$band1)) :
  error in evaluating the argument 'object' in selecting a method for
function 'summary'
> summary(toUnSigned(CheatgrassMapIn at data$band1,8))
Error in toUnSigned(CheatgrassMapIn at data$band1, 8) : already unsigned
Error in summary(toUnSigned(CheatgrassMapIn at data$band1, 8)) :
  error in evaluating the argument 'object' in selecting a method for
function 'summary'
> str(CheatgrassMapIn)
Formal class 'SpatialGridDataFrame' [package "sp"] with 6 slots
  ..@ data       :'data.frame': 2938388 obs. of  1 variable:
  .. ..$ band1: int [1:2938388] 128 128 128 128 128 128 128 128 128 128 ...
  ..@ grid       :Formal class 'GridTopology' [package "sp"] with 3 slots
  .. .. ..@ cellcentre.offset: Named num [1:2] -120.2 38
  .. .. .. ..- attr(*, "names")= chr [1:2] "x" "y"
  .. .. ..@ cellsize         : num [1:2] 0.00243 0.00243
  .. .. ..@ cells.dim        : int [1:2] 1748 1681
  ..@ grid.index : int(0)
  ..@ coords     : num [1:2, 1:2] -120.2 -115.9 38 42
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:2] "x" "y"
  ..@ bbox       : num [1:2, 1:2] -120.2 38 -115.9 42
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "x" "y"
  .. .. ..$ : chr [1:2] "min" "max"
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
  .. .. ..@ projargs: chr " +proj=longlat +ellps=WGS84 +datum=WGS84
+no_defs +towgs84=0,0,0"
> summary(toUnSigned(CheatgrassMapIn$band1,8))
Error in toUnSigned(CheatgrassMapIn$band1, 8) : already unsigned
Error in summary(toUnSigned(CheatgrassMapIn$band1, 8)) :
  error in evaluating the argument 'object' in selecting a method for
function 'summary'
> unique(CheatgrassMapIn$band1)
[1] 128   0   1
> table(CheatgrassMapIn$band1)

      0       1     128
2142594  680644  115150
> summary(CheatgrassMapIn$band1)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
  0.000   0.000   0.000   5.248   1.000 128.000

Again, the values in CheatgrassMapIn$band1 should be 0 or 1, somehow the
value 128 has appeared. There is a conflict between output of GDALinfo and
the summary(CheatgrassMapIn$band1) statement.

I do not see a parameter for readGDAL for specifying word size or sign
treatment. Can anyone offer advice/insight?

Rick Reeves
NCEAS



More information about the R-sig-Geo mailing list