[R-sig-Geo] Overwrite flag in writeRAST6 is not working...

Roger Bivand Roger.Bivand at nhh.no
Fri Oct 23 15:24:21 CEST 2009


On Fri, 23 Oct 2009, Jaime R. Garcia Marquez wrote:

> Dear list,
>
> I am running R within a GRASS session. I am trying to convert a 
> SpatialGridDataFrame to a raster GRASS format using the writeRAST6 function. 
> Because the script is inside a for loop I am using the overwrite flag to 
> create always a temporal Grass raster file, but it does not work.  Here is 
> the code:

Does not work for you with which version of GRASS, R, spgrass6, XML?

In spearfish:

library(spgrass6)
f <- readRAST6("elevation.dem", useGDAL=TRUE, plugin=FALSE)
writeRAST6(x=f, vname="temp", zcol=1, flags="overwrite")
writeRAST6(x=f, vname="temp", zcol=1, flags="overwrite")
writeRAST6(x=f, vname="temp", zcol=1, flags="overwrite")
writeRAST6(x=f, vname="temp", zcol=1, overwrite=TRUE)
writeRAST6(x=f, vname="temp", zcol=1, overwrite=TRUE)

all work, but

writeRAST6(x=f, vname="temp", zcol=1, flags="o")

doesn't, because the -o flag means something different (override 
projection),

for me with:

> execGRASS("g.version")
GRASS 6.4.0RC5 (2009)
> sessionInfo()
R version 2.9.2 (2009-08-24)
x86_64-unknown-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

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

other attached packages:
[1] spgrass6_0.6-9 XML_2.6-0      rgdal_0.6-19   sp_0.9-45

loaded via a namespace (and not attached):
[1] grid_2.9.2      lattice_0.17-26

Roger

>
>
>> class(f)
> [1] "SpatialGridDataFrame"
> attr(,"package")
> [1] "sp"
>
> I would like to create a Grass raster file "temp" which is already there from 
> the first run of the loop
>
>> system("g.list rast")
> ----------------------------------------------
> raster files available in mapset jaime:
> glc200_all glc_mode   r_grid     rich_amp   rich_bat   rich_svm   rsr_amp
> rsr_bat    rsr_veg    soil_all   soil_mode  temp       wwf_ecos   wwf_mode
>
>
> ----------------------------------------------
>
>> writeRAST6(x=f, vname="temp", zcol=colum[i],flags="overwrite")
> Error: option <output>: <temp> exists.
> Warning message:
> In is.na(pt[, "keydesc_count"]) :
> is.na() applied to non-(list or vector) of type 'NULL'
>
>
>> writeRAST6(x=f, vname="temp", zcol=colum[i],flags="o")
> Error: option <output>: <temp> exists.
> Warning message:
> In is.na(pt[, "keydesc_count"]) :
> is.na() applied to non-(list or vector) of type 'NULL'
>
>
>> writeRAST6(x=f, vname="temp", zcol=colum[i], overwrite=TRUE)
> Error: option <output>: <temp> exists.
> Warning message:
> In is.na(pt[, "keydesc_count"]) :
> is.na() applied to non-(list or vector) of type 'NULL'
>
> What I can do is to write at the beginning of the for loop a line to delete 
> the file "temp" (system(g.remove rast=temp)) but the overwrite possibility is 
> more elegant....
>
> I'd appreciate any help.
>
> Jaime
>
> I am using GRASS 6.2.3
>
>> sessionInfo()
> R version 2.9.2 (2009-08-24)
> x86_64-pc-linux-gnu
>
> locale:
> LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] RColorBrewer_1.0-2 spdep_0.4-36       Matrix_0.999375-30 lattice_0.17-26
> [5] spam_0.15-4        boot_1.2-40        tripack_1.3-3      ncf_1.1-3
> [9] spgrass6_0.6-8     XML_2.6-0          classInt_0.1-11    maptools_0.7-25
> [13] foreign_0.8-38     e1071_1.5-19       class_7.2-48       rgdal_0.6-17
> [17] sp_0.9-43
>
> loaded via a namespace (and not attached):
> [1] grid_2.9.2  tools_2.9.2
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list