Skip to content

writeRaster error: unknown file format

9 messages · Paulo Eduardo Cardoso, Roger Bivand, Eddie Smith +1 more

#
I'm getting an error with writeRaster with apparent no particular reason.

The procedure I'm following:

*1. *reading an original landsat OLI band (TIF) downloaded from
http://earthexplorer.usgs.gov/

band <- raster(file.path(dir.work, 'LC81810682013122LGN01_B2.tif'), package
= "raster")

band
class       : RasterLayer 
dimensions  : 7311, 7521, 54986031  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 370485, 596115, -1388715, -1169385  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=33 +datum=WGS84 +units=m +no_defs +ellps=WGS84
+towgs84=0,0,0 
data source :
D:\Dropbox\Kumbira2010\Landsat\LC81810682013122LGN01\LC81810682013122LGN01_B2.tif 
names       : LC81810682013122LGN01_B2 
values      : 0, 65535  (min, max)

*2. *crop band to a given extent 
myext <- extent(c(416985, 425295, -1241505, -1226985))
cropb <- crop(band, myext)
dataType(cropb)
[1] "INT2U # just like the original

*3. *Write IDRISI raster file
writeRaster(band2.ae, filename = file.path(tempdir(),'cropb.rst'), format =
'IDRISI', overwrite = TRUE)

Error in .setFileExtensionHeader(filename, filetype) : 
  unknown file format

Running from RStudio Version 0.98.490
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

I get the same behaviour with raster 2.2-5 package 
locale:
[1] LC_COLLATE=Portuguese_Portugal.1252  LC_CTYPE=Portuguese_Portugal.1252   
[3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C                        
[5] LC_TIME=Portuguese_Portugal.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgdal_0.8-14  raster_2.2-12 sp_1.0-14    

loaded via a namespace (and not attached):
[1] grid_3.0.2      lattice_0.20-24 tools_3.0.2 




--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/writeRaster-error-unknown-file-format-tp7585627.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
On Fri, 24 Jan 2014, pecardoso wrote:

            
Did you follow the advice on:

?writeRaster

and run:

writeFormats()

to see which drivers are available on your platform? Hint:

http://www.gdal.org/formats_list.html

shows that the Idrisi raster format is called "RST".

Also, everything is always clearer when run in an R console interactively, 
not through R Studio. R Studio assumes that you know what you are doing 
when coding/scripting, something that doesn't apply to anyone I've met, 
especially including myself.

Hope this clarifies,

Roger

  
    
#
Hello all. Thanks for your time.

Robert, True about format, but 'IDRISI' file format is also there and I've
used format = 'IDRISI' ultil recently, and it was working just fine with
exactly the same procedure.

About running scripts from RStudio and R console, I'm not skilled enough to
understand the differences.

in my system, writeFormats() returns:

name        long_name                                
[1,] "raster"    "R-raster"                               
[2,] "SAGA"      "SAGA GIS"                               
[3,] "IDRISI"    "IDRISI"
...
[36,] "RST"       "Idrisi Raster A.1" 

With older versions of raster package, the argument format='IDRISI' also
produced 'IDRISI Raster A.1' files.

Latest version in fact is not accepting format = 'IDRISI' for the
RasterLayer created from reading the 16 bis Landsat TIF file and is
returning the error:
Error in .setFileExtensionHeader(filename, filetype) : unknown file format

Changing to format = 'RST' isn't better. I get the error:
Error in .local(.Object, ...) : Unable to create dataset

The behavior is the same running this from  within RStudio and from the R
console.

Maybe with the same data it would be better, or reproducible.

Here
<https://www.dropbox.com/s/is2td4t6uwc44fq/LC81810682013122LGN01_B2.TIF> 
the link to the landast image (107Mb).

For the resulting RasterLayer
GDALinfo('...\\LC81810682013122LGN01_B2.tif')
rows        7311 
columns     7521 
bands       1 
lower left origin.x        370485 
lower left origin.y        -1388715 
res.x       30 
res.y       30 
ysign       -1 
oblique.x   0 
oblique.y   0 
driver      GTiff 
projection  +proj=utm +zone=33 +datum=WGS84 +units=m +no_defs 
file        C:\Users\Strix\Downloads\LC81810682013122LGN01_B2.tif 
apparent band summary:
  GDType hasNoDataValue NoDataValue blockSize1 blockSize2
1 UInt16          FALSE           0          1       7521
apparent band statistics:
  Bmin  Bmax Bmean Bsd
1    0 65535    NA  NA
Metadata:
AREA_OR_POINT=Point 
Warning message:
statistics not supported by this driver

Eddie, I generally do not use setwd when sharing scripts with colleagues. I
usually define paths to some shared folder. It's not working anyway. From my
sessionInfo string you will se that I'm running rgdal.

Could it be something with rgdal (and gdal) installation after package
update? For a  similar problem
<http://r-sig-geo.2731867.n2.nabble.com/problem-with-writeRaster-and-GeoTIFF-format-td7583541.html>  
users suggests re-install of rgdal, gdal and its libraries.



--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/writeRaster-error-unknown-file-format-tp7585627p7585632.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
3 days later
#
Paulo,

This has been fixed in raster 2.2-16 (development version). You can
install and try it:
install.packages("raster", repos="http://R-Forge.R-project.org")

Robert
On Fri, Jan 24, 2014 at 7:53 AM, pecardoso <pauloeducardoso at gmail.com> wrote:
#
Robert,

Thank you for your message. First thing, raster package is simply amazing.

I've installed raster v2.2-16.
I've imported the TIF from the dropbox link with

i.l8 <- raster('D:\\Dropbox\\Public\\LC81810682013122LGN01_B2.TIF',
               package = "raster")
class       : RasterLayer
dimensions  : 7311, 7521, 54986031  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 370485, 596115, -1388715, -1169385  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=33 +datum=WGS84 +units=m +no_defs
+ellps=WGS84 +towgs84=0,0,0
data source : D:\Dropbox\Public\LC81810682013122LGN01_B2.TIF
names       : LC81810682013122LGN01_B2
values      : 0, 65535  (min, max)

I'm also able to generate a RST file from the rasterLayer i.l8 with

writeRaster(band, filename = 'D:\\l8_b2.rst', format = 'IDRISI', overwrite
= TRUE)

IDRISI Taiga can read the RST file but the file format is tagged as "IDRISI
x A1" and not "IDRISI Raster A1"

I still not being able to generate the RST file with

writeRaster(band, filename = 'D:\\l8_b2.rst', format = 'RST', overwrite =
TRUE)

Error in .local(.Object, ...) : Unable to create dataset

But it works fine with writeGDAL:

writeGDAL(as(i.l8, "SpatialGridDataFrame"), fname = "D:\l8_gdal.rst",
drivername = "RST")

IDRISI Taiga read it and tag the file format as "IDRISI Raster A1", just
like the ones generated internally with import functions from IDRISI.

writeRaster with format = 'IDRISI' generetes a 230,732 MB idrisi file while
a 214,790 MB file is generated with writeGDAL and drivername = 'RST'

I can't figure out why.



Paulo Eduardo Cardoso



2014-01-27 Robert Hijmans [via R-sig-geo] <
ml-node+s2731867n7585643h37 at n2.nabble.com>
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/writeRaster-error-unknown-file-format-tp7585627p7585646.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Paulo,

Thank you.

This has been fixed now on R-Forge. The problem was with the (new)
default (that I am starting to regret) of using FLT8S (64 bit floats)
for writing to files. IDRISI does not support that; this has now been
caught.
In the current version, something like this should work (explicitly
setting the data type):

writeRaster(band, filename = 'D:\\l8_b2.rst', format = 'RST',
datatype='FLT4S', overwrite =TRUE)

Robert
On Mon, Jan 27, 2014 at 5:01 PM, pecardoso <pauloeducardoso at gmail.com> wrote:
#
Robert,

Thank you for following this.

It is now able to write the RST object with signed integer datatype:

writeRaster(i.l8, filename = 'D:\\l8_b2.rst', format = 'RST', overwrite =
TRUE, datatype = "INT2S", NAflag = -9999)

I get the same error when i try to use unsigned "INT2U" data type of i.l8
object.
[1] "INT2U"

Nonetheless, IDRISI Taiga can read the RST file and from the IDRISI file
Metadata all tags seems to be ok:

file format : Idrisi Raster A.1
file title  : 
data type   : integer
file type   : binary
columns     : 7521
rows        : 7311
ref. system : utm-33n
ref. units  : m
unit dist.  : 1

It is the first type writeRaster correctly assign the integer data type and
correctly assigning ref system (utm-33n in this particular case).

Fine.

One detail. I don't think this may influence sny further analysis using
other environments that not R but in fact, Landsat scenes are provided as
unsigned integer (8 or 16 bits).






--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/writeRaster-error-unknown-file-format-tp7585627p7585657.html
Sent from the R-sig-geo mailing list archive at Nabble.com.