Hello again, Now that I've managed to use readGDAL successfully, I'd really like to write some img files using writeGDAL, and I'm having some er, interesting problems that I can't quite understand. Pardon the length of the message.
For the most part, writeGDAL successfully writes an IMG file that I can successfully read into ArcGIS, with projection and all. But sometimes (from an identical writeGDAL command) the file comes up with no projection and data values of all zeros. Checking this in R using GDALinfo or readGDAL reveals the same thing - proj4string is NA and all values are zero. BUT, if I use readGDAL again on the same file, it works, and, additionally, I can then successfully read it into ArcGIS. I wonder if there is a buffer issue where the writeGDAL command doesn't quite finish it's business until I nudge it with some other GDAL commands. If I close R before I get the file to read in properly, then no amount of readGDAL will get it to come in with projection and data values. I think one solution is to figure out the lower level commands like GDAL.open and GDAL.close so I can close handles explicitly, but it would be nice to use writeGDAL. Any ideas? Here is a sample of the code that produced the problem. > library(rgdal) Loading required package: sp Geospatial Data Abstraction Library extensions to R successfully loaded > test <- readGDAL('swe20070220.img') swe20070220.img has GDAL driver HFA and has 360 rows and 720 columns Closing GDAL dataset handle 0x0209ef78... destroyed ... done. > summary(test) Object of class SpatialGridDataFrame Coordinates: min max x -180 180 y -90 90 Is projected: FALSE proj4string : [+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0] Number of points: 2 Grid attributes: cellcentre.offset cellsize cells.dim x -179.75 0.5 720 y -89.75 0.5 360 Data attributes: band1 Min. : 0.00 1st Qu.: 14.00 Median : 57.00 Mean : 63.02 3rd Qu.: 98.00 Max. : 480.00 NA's :225758.00 > writeGDAL(test, 'swe20070220_TEST.img', driver = 'HFA') > test2 <- readGDAL('swe20070220_TEST.img') swe20070220_TEST.img has GDAL driver HFA and has 360 rows and 720 columns Closing GDAL dataset handle 0x0218f760... destroyed ... done. Closing GDAL dataset handle 0x020b72f8... destroyed ... done. Closing GDAL dataset handle 0x0209f068... destroyed ... done. > summary(test2) Object of class SpatialGridDataFrame Coordinates: min max x 0 720 y 0 360 Is projected: NA proj4string : [NA] Number of points: 2 Grid attributes: cellcentre.offset cellsize cells.dim x 0.5 1 720 y 0.5 1 360 Data attributes: band1 Min. :0 1st Qu.:0 Median :0 Mean :0 3rd Qu.:0 Max. :0 > image(test2) Closing GDAL dataset handle (nil)... done. > rm(test2) > test2 <- readGDAL('swe20070220_TEST.img') swe20070220_TEST.img has GDAL driver HFA and has 360 rows and 720 columns Closing GDAL dataset handle 0x02187368... destroyed ... done. > summary(test2) Object of class SpatialGridDataFrame Coordinates: min max x -180 180 y -90 90 Is projected: FALSE proj4string : [+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0] Number of points: 2 Grid attributes: cellcentre.offset cellsize cells.dim x -179.75 0.5 720 y -89.75 0.5 360 Data attributes: band1 Min. : 0.00 1st Qu.: 14.00 Median : 57.00 Mean : 63.02 3rd Qu.: 98.00 Max. : 480.00 NA's :225758.00 > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 5.0 year 2007 month 04 day 23 svn rev 41293 language R version.string R version 2.5.0 (2007-04-23) Many thanks in advance -- ********************************** Matthew Landis Research Analyst Isciences, LLC 61 Main St., Suite 200 Burlington VT 05401 USA _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo