[R-sig-Geo] rgdal, multiband CCITT compression

Oliver Soong osoong+r at gmail.com
Fri Nov 5 01:40:27 CET 2010


Sorry, the word "expected" was a bad choice.  The output is what I
get.  I'm highlighting two tables that should be the same, but aren't.
 I appreciate you taking the time to poke around with me.

*** Correct Stats: img_1bit_2band
 band1 band2
0  3086  8353
1  6914  1647
Compression: CCITTRLE from img_1bit_2band_CCITTRLE.tif
 band1 band2
0  6131  8783
1  3869  1217




On Thu, Nov 4, 2010 at 5:14 PM, Michael Sumner <mdsumner at gmail.com> wrote:
> Ok, thanks. I can try later today with Manifold System, which may be. I'm
> not sure of other non-GDAL tools to double check TIFFs with. (ArcGIS 10 uses
> GDAL but I don't know to what extent).
>
> Is the output above what you expect, or what you get? That's what I get.
> Sorry to be dim, but I don't see where you've specified what's actually
> wrong (and I haven't explored enough to see if that's easy to determine from
> the code).
>
> That's a cunning use of formals() to change defaults for a function - a bit
> radical for my taste, but I like it.
>
> Cheers, Mike.
>
> On Fri, Nov 5, 2010 at 11:00 AM, Oliver Soong <osoong+r at gmail.com> wrote:
>>
>> Here's an example:
>>
>>
>>
>>
>> require(rgdal)
>> formals(paste)$sep <- ""
>>
>> SP27GTIF <- readGDAL(
>>  system.file("pictures/SP27GTIF.TIF", package = "rgdal")[1],
>>  output.dim=c(100,100)
>> )
>> img_1bit_1band <- SP27GTIF
>> img_1bit_1band at data$band1 <- as.integer(SP27GTIF at data$band1 > 85)
>> img_1bit_2band <- SP27GTIF
>> img_1bit_2band at data <- data.frame(
>>  band1 = img_1bit_1band at data$band1,
>>  band2 = as.integer(SP27GTIF at data$band1 > 170)
>> )
>>
>> for(img in c("img_1bit_1band", "img_1bit_2band")) {
>>  cat(paste("*** Correct Stats: ", img, "\n"))
>>  print(sapply(get(img)@data, table))
>>  for(compress in c("NONE", "DEFLATE", "LZW", "CCITTRLE",
>>                    "CCITTFAX3", "CCITTFAX4")) {
>>    file <- paste(img, "_", compress, ".tif")
>>    writeGDAL(get(img), file, type = "Byte",
>>      options = c("NBITS=1", paste("COMPRESS=", compress)))
>>    cat(paste("Compression: ", compress, " from ", file, "\n"))
>>    reread <- readGDAL(file, silent = TRUE)
>>    print(sapply(reread at data, table))
>>  }
>>  cat("\n")
>> }
>>
>>
>>
>>
>>
>> The expected output is:
>>
>> *** Correct Stats: img_1bit_1band
>>  band1
>> 0  3086
>> 1  6914
>> Compression: NONE from img_1bit_1band_NONE.tif
>>  band1
>> 0  3086
>> 1  6914
>> Compression: DEFLATE from img_1bit_1band_DEFLATE.tif
>>  band1
>> 0  3086
>> 1  6914
>> Compression: LZW from img_1bit_1band_LZW.tif
>>  band1
>> 0  3086
>> 1  6914
>> Compression: CCITTRLE from img_1bit_1band_CCITTRLE.tif
>>  band1
>> 0  3086
>> 1  6914
>> Compression: CCITTFAX3 from img_1bit_1band_CCITTFAX3.tif
>>  band1
>> 0  3086
>> 1  6914
>> Compression: CCITTFAX4 from img_1bit_1band_CCITTFAX4.tif
>>  band1
>> 0  3086
>> 1  6914
>>
>> *** Correct Stats: img_1bit_2band
>>  band1 band2
>> 0  3086  8353
>> 1  6914  1647
>> Compression: NONE from img_1bit_2band_NONE.tif
>>  band1 band2
>> 0  3086  8353
>> 1  6914  1647
>> Compression: DEFLATE from img_1bit_2band_DEFLATE.tif
>>  band1 band2
>> 0  3086  8353
>> 1  6914  1647
>> Compression: LZW from img_1bit_2band_LZW.tif
>>  band1 band2
>> 0  3086  8353
>> 1  6914  1647
>> Compression: CCITTRLE from img_1bit_2band_CCITTRLE.tif
>>  band1 band2
>> 0  6131  8783
>> 1  3869  1217
>> Compression: CCITTFAX3 from img_1bit_2band_CCITTFAX3.tif
>>  band1 band2
>> 0  6131  8783
>> 1  3869  1217
>> Compression: CCITTFAX4 from img_1bit_2band_CCITTFAX4.tif
>>  band1 band2
>> 0  6131  8783
>> 1  3869  1217
>>
>>
>>
>> Everything looks fine except CCITT compression with 2 bands.
>>
>> I wasn't able to dig up Windows GDAL 1.7.1 binaries, and the 1.7.0
>> binaries from FW_Tools seem to give similar behavior, although it's a
>> little hard to check because neither ArcGIS nor ENVI seems to like any
>> of the multi-band files.
>
>
>
> --
> Michael Sumner
> Institute for Marine and Antarctic Studies, University of Tasmania
> Hobart, Australia
> e-mail: mdsumner at gmail.com
>



-- 
Oliver Soong
Donald Bren School of Environmental Science & Management
University of California, Santa Barbara
Santa Barbara, CA 93106-5131
805-893-7044 (office)
610-291-9706 (cell)



More information about the R-sig-Geo mailing list