[R-sig-Geo] writeRaster issue

Verbesselt, Jan jan.verbesselt at wur.nl
Wed Apr 23 10:04:36 CEST 2014


I did a quick test here and it runs fine here (via the terminal/Rstudio).
One thing that might help is to do:
update.packages(checkBuilt=TRUE)
Hope this helps,
Jan

> library(raster)
Loading required package: sp
> library(rgdal)
rgdal: version: 0.8-16, (SVN revision 498)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.9.2, released 2012/10/08
Path to GDAL shared files:
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/rgdal/gdal
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
Path to PROJ.4 shared files:
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/rgdal/proj
> load("~/Downloads/rasterLayer.RData")
> plot(varTmpRaster)
> tf <- writeRaster(varTmpRaster, "~/Desktop/testGeoTif", format = "GTiff",
+  overwrite = TRUE)
> plot(tf)
> all.equal(varTmpRaster, tf)
[1] TRUE
> length(tf)
[1] 1036800
> length(tf[is.na(tf)])
[1] 919682
> ncell(varTmpRaster)
[1] 1036800
> length(tf[is.na(tf)])
[1] 919682
> sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] rgdal_0.8-16  raster_2.2-31 sp_1.0-15     devtools_1.5

loaded via a namespace (and not attached):
 [1] digest_0.6.4    evaluate_0.5.3  grid_3.0.3      httr_0.3
lattice_0.20-29
 [6] memoise_0.1     parallel_3.0.3  RCurl_1.95-4.1  stringr_0.6.2
tools_3.0.3    
[11] whisker_0.3-2




On 23/04/14 08:31, "Andrew Vitale" <vitale232 at gmail.com> wrote:

>It runs on my system.  I would still suggest updating to R 3.1.0 and
>making
>sure raster and rgdal are the latest versions.  I'm also running it in the
>terminal, not through something like R Studio.
>
>That's really all I can offer.  Good luck!
>
>-Andrew
>
>
>
>library(raster)
>library(rgdal)
>
>load("~/Downloads/rasterLayer.RData")
>plot(varTmpRaster)
>
>tf <- writeRaster(varTmpRaster, "~/Desktop/testGeoTif", format = "GTiff",
>overwrite = TRUE)
>plot(tf)
>
>
>all.equal(varTmpRaster, tf)
>
>length(tf)
>length(tf[is.na(tf)])
>
>ncell(varTmpRaster)
>length(tf[is.na(tf)])
>
>sessionInfo()
>
>
># > all.equal(varTmpRaster, tf)
># [1] TRUE
># >
>#   > length(tf)
># [1] 1036800
># > length(tf[is.na(tf)])
># [1] 919682
># >
>#   > ncell(varTmpRaster)
># [1] 1036800
># > length(tf[is.na(tf)])
># [1] 919682
># >
>#   > sessionInfo()
># R version 3.1.0 (2014-04-10)
># Platform: x86_64-pc-linux-gnu (64-bit)
>#
># locale:
>#   [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
># [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
># [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
># [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
># [9] LC_ADDRESS=C               LC_TELEPHONE=C
># [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>#
># attached base packages:
>#   [1] stats     graphics  grDevices utils     datasets  methods   base
>
>#
># other attached packages:
>#   [1] rgdal_0.8-16  raster_2.2-31 sp_1.0-15
>#
># loaded via a namespace (and not attached):
>#   [1] grid_3.1.0      lattice_0.20-29 tcltk_3.1.0     tools_3.1.0
>
>
>
>On Tue, Apr 22, 2014 at 10:39 PM, Guillermo E. Ponce-Campos <
>geponce at gmail.com> wrote:
>
>> Thanks Andrew...
>> Here is the raster layer object I can save as geoTif on Windows XP and
>> 7 but not in Centos...
>>
>> https://www.dropbox.com/s/t8rqkvwqnam3imm/rasterLayer.RData
>>
>> As you can see, in the Centos box I have a newer version for the rgdal
>> and raster packages.
>>
>> Thanks,
>> Guillermo
>>
>>
>> On Tue, Apr 22, 2014 at 9:07 PM, Andrew Vitale <vitale232 at gmail.com>
>> wrote:
>> > Hey Guillermo,
>> >
>> > All I can add is that I'm unable to reproduce this on my Lubutu 14.04
>> > laptop.
>> >
>> > Perhaps you should try updating R and your packages?
>> >
>> >
>> > ## The following code plots as expected:
>> >
>> > setwd("~/Desktop")
>> > library(raster)
>> >
>> > r <- raster()
>> > r[] <- 1:ncell(r) * 0.001
>> > plot(r)
>> >
>> > r2 <- writeRaster(r, "testGeoTif", format="GTiff", overwrite=TRUE)
>> > plot(r2)
>> >
>> > r3 <- raster("testGeoTif.tif")
>> > plot(r3)
>> >
>> >
>> >> sessionInfo()
>> > R version 3.1.0 (2014-04-10)
>> > Platform: i686-pc-linux-gnu (32-bit)
>> >
>> > locale:
>> >  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
>> >  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
>> >  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
>> >  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
>> >  [9] LC_ADDRESS=C               LC_TELEPHONE=C
>> > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>> >
>> > attached base packages:
>> > [1] stats     graphics  grDevices utils     datasets  methods   base
>> >
>> > other attached packages:
>> > [1] rgdal_0.8-16  raster_2.2-31 sp_1.0-15
>> >
>> > loaded via a namespace (and not attached):
>> > [1] grid_3.1.0      lattice_0.20-29
>> >
>> >
>> >
>> > On Tue, Apr 22, 2014 at 11:09 AM, Guillermo E. Ponce-Campos
>> > <geponce at gmail.com> wrote:
>> >>
>> >> Hi:
>> >>
>> >> Is there any known issue on using writeRaster under Windows vs Linux?
>> >>
>> >> I have been trying to write a rasterlayer as a geotif in a Linux
>> >> (centos) machine with no success...
>> >>
>> >> I have this raster layer:
>> >>
>> >> > varTmpRaster
>> >> class       : RasterLayer
>> >> dimensions  : 720, 1440, 1036800  (nrow, ncol, ncell)
>> >> resolution  : 0.25, 0.25  (x, y)
>> >> extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
>> >> coord. ref. : +init=epsg:4326 +proj=longlat +ellps=WGS84 +datum=WGS84
>> >> +no_defs +towgs84=0,0,0
>> >> data source : in memory
>> >> names       : layer
>> >> values      : 0, 0.9132664  (min, max)
>> >>
>> >> >plot(varTmpRaster)
>> >> It shows everything right...
>> >>
>> >> When I run the writeRaster the resulting file only have NA's:
>> >>
>> >> >tf <- writeRaster(varTmpRaster, "testGeoTif", format="GTiff",
>> >> > overwrite=TRUE)
>> >> >plot(tf)
>> >> Just blank plot...
>> >>
>> >> >length(tf)
>> >> [1]1036800
>> >> >length(tf[is.na[tf])
>> >> [1] 1036800
>> >>
>> >>
>> >> If I run the exact same instructions on R for Windows7 and everything
>> >> goes fine, both plots, the one from varTmpRaster and the tf show
>> >> exactly the same map...
>> >>
>> >> Here are the characteristics from both machines...
>> >>
>> >> Linux-Centos:
>> >> ---------------
>> >> R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
>> >> rgdal: version: 0.8-16, (SVN revision 498)
>> >> Geospatial Data Abstraction Library extensions to R successfully
>>loaded
>> >> Loaded GDAL runtime: GDAL 1.10.1, released 2013/08/26
>> >> Path to GDAL shared files: /usr/local/share/gdal
>> >> Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
>> >> Path to PROJ.4 shared files: /opt/source/proj-4.8.0/nad
>> >>
>> >> Windows 7:
>> >> ----------------
>> >> R version 3.0.1 (2013-05-16) -- "Good Sport"
>> >> Loading required package: sp
>> >> rgdal: version: 0.8-11, (SVN revision 479M)
>> >> Geospatial Data Abstraction Library extensions to R successfully
>>loaded
>> >> Loaded GDAL runtime: GDAL 1.9.2, released 2012/10/08
>> >> Path to GDAL shared files: C:/Program
>>Files/R/R-3.0.1/library/rgdal/gdal
>> >> GDAL does not use iconv for recoding strings.
>> >> Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009, [PJ_VERSION:
>>470]
>> >> Path to PROJ.4 shared files: C:/Program
>> Files/R/R-3.0.1/library/rgdal/proj
>> >>
>> >> Does anyone has seen a thread commenting on an issue like this
>>before ?
>> >>
>> >> I have tried the NAvalue() and also using the datatype FLT8S and
>>FLT4S
>> >> as part of the parameters of the writeRaster but no luck.
>> >>
>> >>
>> >> Thanks,
>> >> Guillermo
>> >>
>> >> _______________________________________________
>> >> R-sig-Geo mailing list
>> >> R-sig-Geo at r-project.org
>> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>> >
>> >
>> >
>> >
>> > --
>> > Andrew P. Vitale
>> > Masters Student
>> > Department of Geography
>> > University of Nevada, Reno
>> > vitale232 at gmail.com
>>
>>
>>
>> --
>> Guillermo E. Ponce-Campos
>> PGP Key ID: 0x57EDC060
>> Ph. (520) 261-8486
>>
>
>
>
>-- 
>*Andrew P. Vitale*
>Masters Student
>Department of Geography
>University of Nevada, Reno
>vitale232 at gmail.com
>
>	[[alternative HTML version deleted]]
>
>_______________________________________________
>R-sig-Geo mailing list
>R-sig-Geo at r-project.org
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list