[R-sig-Geo] Fwd: Problem with writing Raster into grass using gdal

Roger Bivand Roger.Bivand at nhh.no
Fri Aug 5 14:26:28 CEST 2011


On Fri, 5 Aug 2011, Rainer M Krug wrote:

> Hi
>
> you might have seen my other post, and the problem seems to be solved now -
> problems with the gdel installation.
>
> Concerning the error in writeRAST6: I would suggest to contact Roger Bivand
> so that can be fixed.

Committed to SVN on R-Forge, project rspatial, module spgrass6, thanks!

Roger

>
> Thanks a lot,
>
> Rainer
>
> On Fri, Aug 5, 2011 at 12:48 PM, ahmadou dicko <dicko.ahmadou at gmail.com>wrote:
>
>> I send this message yesterday, from NABBLE but i guess the server was
>> down...
>>
>> ---------- Forwarded message ----------
>> From: <r-sig-geo-owner at r-project.org>
>> Date: 2011/8/4
>> Subject: Re: Problem with writing Raster into grass using gdal
>> To: dicko.ahmadou at gmail.com
>>
>>
>> You are not allowed to post to this mailing list, and your message has
>> been automatically rejected.  If you think that your messages are
>> being rejected in error, contact the mailing list owner at
>> r-sig-geo-owner at r-project.org.
>>
>>
>>
>> ---------- Message transf?r? ----------
>> From: dicko ahmadou <dicko.ahmadou at gmail.com>
>> To: r-sig-geo at r-project.org
>> Date: Thu, 4 Aug 2011 12:30:32 -0700 (PDT)
>> Subject: Re: Problem with writing Raster into grass using gdal
>> Hi Rainer
>>
>> May be there's a problem with your data or with the GDAL binaries in your
>> installation.
>>
>> Did you have the same problem using for example a raster from the spearfish
>> location ?
>>
>> I have set all the GRASS variable permanently in my .bash_profile.
>> So i can run the following in  emacs (ESS)
>>
>> require(spgrass6)
>> execGRASS("g.mapset", parameters = list(gisdbase =
>> "/home/dickoa/GIS/GRASS/grassdata", location = "spearfish60", mapset =
>> "user1"))
>>
>> G <- gmeta6()
>> str(G)
>>
>> List of 24
>>  $ GISDBASE     : chr "/home/dickoa/GIS/GRASS/grassdata"
>>  $ LOCATION_NAME: chr "spearfish60"
>>  $ MAPSET       : chr "user1"
>>  $ GRASS_GUI    : chr "wxpython"
>>  $ MONITOR      : chr "cairo7"
>>  $ n            : num 4928000
>>  $ s            : num 4914000
>>  $ w            : num 590000
>>  $ e            : num 609000
>>  $ t            : num 1
>>  $ b            : num 0
>>  $ nsres        : num 100
>>  $ nsres3       : num 100
>>  $ ewres        : num 100
>>  $ ewres3       : num 100
>>  $ tbres        : num 1
>>  $ rows         : int 140
>>  $ rows3        : int 140
>>  $ cols         : int 190
>>  $ cols3        : int 190
>>  $ depths       : int 1
>>  $ cells        : chr "26600"
>>  $ cells3       : chr "26600"
>>  $ proj4        : chr "+proj=utm +zone=13 +a=6378206.4 +rf=294.9786982
>> +no_defs +nadgrids=/usr/local/grass-6.4.2svn/etc/nad/conus +to_meter=1.0"
>>  - attr(*, "class")= chr "gmeta6"
>>
>>
>> # the raster soils
>> soil <- readRAST6("soils", plugin = TRUE)
>>
>> #spplot(soil["soils"])
>>
>> # works
>> writeRAST6(soil, "soil2", useGDAL = TRUE)
>>
>>
>> execGRASS("r.info", flags = "r", parameters = list(map = "soil2"))
>> min=1
>> max=54
>>
>> soil$soils <- 2*soil$soils
>>
>> writeRAST6(soil, "soil2", useGDAL = TRUE, overwrite = TRUE)
>> WARNING: Raster map <soil2> already exists and will be overwritten
>> Projection of input dataset and current location appear to match
>>
>> execGRASS("r.info", flags = "r", parameters = list(map = "soil2"))
>> min=2
>> max=108
>>
>> # another attemp without GDAL
>> soil$soils <- soil$soils/4
>>
>> # Failed
>> writeRAST6(soil, "soil2", useGDAL = FALSE, overwrite = TRUE)
>> ERROR: option <output>: <soil2> exists
>>
>> There's a small bug in writeRAST6 which can be easyly fixed :
>>
>> just have to change in the writeRAST6 function this part :
>>
>> execGRASS("r.in.bin", flags = res$flags, parameters = list(input =
>> gtmpfl11,
>>           output = vname, bytes = as.integer(res$bytes), north =
>> as.numeric(res$north)
>>
>> by
>>
>> execGRASS("r.in.bin", flags = flags, parameters = list(input = gtmpfl11,
>>           output = vname, bytes = as.integer(res$bytes), north =
>> as.numeric(res$north)
>>
>>
>>
>> mywriteRAST6  <- function (x, vname, zcol = 1, NODATA = NULL, ignore.stderr
>> = FALSE,
>>   useGDAL = TRUE, overwrite = FALSE, flags = NULL, drivername = "GTiff")
>> {
>>   pid <- as.integer(round(runif(1, 1, 1000)))
>>   gtmpfl1 <- dirname(execGRASS("g.tempfile", parameters = list(pid = pid),
>>       intern = TRUE, ignore.stderr = ignore.stderr))
>>   rtmpfl1 <- ifelse(.Platform$OS.type == "windows" &&
>> (Sys.getenv("OSTYPE") ==
>>       "cygwin"), system(paste("cygpath -w", gtmpfl1, sep = " "),
>>       intern = TRUE), gtmpfl1)
>>   fid <- paste("X", pid, sep = "")
>>   gtmpfl11 <- paste(gtmpfl1, fid, sep = .Platform$file.sep)
>>   rtmpfl11 <- paste(rtmpfl1, fid, sep = .Platform$file.sep)
>>   if (!is.numeric(x at data[[zcol]]))
>>       stop("only numeric columns may be exported")
>>   if (overwrite && !("overwrite" %in% flags))
>>       flags <- c(flags, "overwrite")
>>   Gver <- execGRASS("g.version", intern = TRUE, ignore.stderr =
>> ignore.stderr)
>>   G63 <- !(Gver < "GRASS 6.3")
>>   if (useGDAL && G63) {
>>       gdalD <- gdalDrivers()$name
>>       gdalDGRASS <- execGRASS("r.out.gdal", flags = "l", intern = TRUE,
>>           ignore.stderr = TRUE)
>>       if (!(drivername %in% gdalD))
>>           stop(paste("Requested driver", drivername, "not available in
>> rgdal"))
>>       if (length(grep(drivername, gdalDGRASS)) == 0)
>>           stop(paste("Requested driver", drivername, "not available in
>> GRASS"))
>>       if (is.factor(x at data[[zcol]]))
>>           x at data[[zcol]] <- as.numeric(x at data[[zcol]])
>>       if (!is.numeric(x at data[[zcol]]))
>>           stop("only numeric values may be exported")
>>       if (is.null(NODATA)) {
>>           NODATA <- floor(min(x at data[[zcol]], na.rm = TRUE)) -
>>               1
>>       }
>>       else {
>>           if (!is.finite(NODATA) || !is.numeric(NODATA))
>>               stop("invalid NODATA value")
>>           if (NODATA != round(NODATA))
>>               warning("NODATA rounded to integer")
>>           NODATA <- round(NODATA)
>>       }
>>       sm <- storage.mode(x[[zcol]])
>>       type <- ifelse(sm == "integer", "Int32", "Float32")
>>       res <- writeGDAL(x[zcol], fname = rtmpfl11, type = type,
>>           drivername = drivername, mvFlag = NODATA)
>>       execGRASS("r.in.gdal", flags = flags, parameters = list(input =
>> gtmpfl11,
>>           output = vname), ignore.stderr = ignore.stderr)
>>       DS <- GDAL.open(rtmpfl11, read.only = FALSE)
>>       deleteDataset(DS)
>>   }
>>   else {
>>       res <- writeBinGrid(x, rtmpfl11, attr = zcol, na.value = NODATA)
>>       flags <- c(res$flag, flags)
>>       *execGRASS("r.in.bin", flags = flags, parameters = list(input =
>> gtmpfl11,
>>           output = vname, bytes = as.integer(res$bytes), north =
>> as.numeric(res$north)*,
>>           south = as.numeric(res$south), east = as.numeric(res$east),
>>           west = as.numeric(res$west), rows = as.integer(res$rows),
>>           cols = as.integer(res$cols), anull = as.numeric(res$anull)),
>>           ignore.stderr = ignore.stderr)
>>       unlink(paste(rtmpfl1, list.files(rtmpfl1, pattern = fid),
>>           sep = .Platform$file.sep))
>>   }
>>   invisible(res)
>> }
>>
>>
>>
>> writeRAST6(soil, "soil2", useGDAL = FALSE, overwrite = TRUE)
>>
>> execGRASS("r.info", flags = "r", parameters = list(map = "soil2"))
>> min=0.5
>> max=27
>>
>>
>> my session info is :
>> sessionInfo()
>> R version 2.13.1 (2011-07-08)
>> Platform: x86_64-pc-linux-gnu (64-bit)
>>
>> locale:
>>  [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C
>>  [3] LC_TIME=fr_FR.UTF-8        LC_COLLATE=fr_FR.UTF-8
>>  [5] LC_MONETARY=C              LC_MESSAGES=fr_FR.UTF-8
>>  [7] LC_PAPER=fr_FR.UTF-8       LC_NAME=C
>>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
>> [11] LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C
>>
>> attached base packages:
>> [1] grid      stats     graphics  grDevices utils     datasets
>> [7] methods   base
>>
>> other attached packages:
>>  [1] spgrass6_0.6-28 XML_3.4-0       rgdal_0.7-1
>>  [4] sp_0.9-84       stringr_0.5     ggplot2_0.8.9
>>  [7] proto_0.3-9.2   reshape_0.8.4   plyr_1.6
>> [10] MASS_7.3-14
>>
>> loaded via a namespace (and not attached):
>> [1] lattice_0.19-31 tools_2.13.1
>>
>> --
>> View this message in context:
>>
>> http://r-sig-geo.2731867.n2.nabble.com/Problem-with-writing-Raster-into-grass-using-gdal-tp6649314p6653995.html
>> Sent from the R-sig-geo mailing list archive at Nabble.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
>>
>>
>
>
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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