[GRASS-dev] Re: Problem when loading GRASS 6 raster with large integer values into R via r.out.bin

Rainer M Krug r.m.krug at gmail.com
Tue Sep 23 07:38:18 EDT 2008


On Tue, Sep 23, 2008 at 1:11 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
> On Tue, 23 Sep 2008, Rainer M Krug wrote:
>
>> OK - I finally got around to testing it.
>>
>> I installed spgrass6 as well as rgdal from source, as spgrass6 needed
>> a newer version of rgdal then available in CRAN  (Error: package
>> 'rgdal' 0.5-25 was found, but >= 0.5.26 is required by 'spgrass6').
>
> Hi,
>
> I had to modify rgdal to get writeRAST6() to use writeGDAL() - there was a
> bug in otherwise unused code to setting the NODATA value in rgdal. Could you
> try this out too? Should I try to trap the verbose messages?

It is working for me, although when I am using useGDAL=FALSE, it is
converted from integer to double (see below).

In R:

> x <- readRAST6("ros_2016.max",useGDAL=TRUE )
> writeRAST6(x,"xuseGDALFALSE",useGDAL=FALSE )
 100%
> writeRAST6(x,"xuseGDALTRUE",useGDAL=TRUE )
WARNING: Datum <unknown> not recognised by GRASS and no parameters found.
Projection of input dataset and current location appear to match
 100%
r.in.gdal complete.
>

In GRASS:

GRASS 6.3.0 (grass):~/Documents/Projects/AlienSpread/R > r.info -r
map=xuseGDALTRUE
min=0
max=36852
[Raster MASK present]
GRASS 6.3.0 (grass):~/Documents/Projects/AlienSpread/R > r.info -r
map=xuseGDALFALSE
min=0.000000
max=36852.000000
[Raster MASK present]
GRASS 6.3.0 (grass):~/Documents/Projects/AlienSpread/R >


Concerning trapping of the verbose messages, I think it would be a
good idea to do the following:

1) add a parameter verbose=TRUE in readRAST6 and writeRAST6 to enable
or disable it
2) if possible, raise an R error, if GRASS returns ERROR

This is one approach which I would be interested to use as well when
calling GRASS commands from R.
What is the
ERROR 6:  SetColorTable() only supported for Byte or UInt16 bands in
TIFF format.
mean? Is it relevant for R?

Thanks

Rainer


>
> Best wishes,
>
> Roger
>
>>
>> It is working, when using useGDAL=TRUE. See output below:
>>
>> In GRASS:
>> GRASS 6.3.0 (grass):~/Documents/Projects/AlienSpread/R > r.info -r
>> map=ros_2016.max
>> min=0
>> max=36852
>> [Raster MASK present]
>> GRASS 6.3.0 (grass):~/Documents/Projects/AlienSpread/R >
>>
>> In R:
>>
>>> x <- readRAST6("ros_2016.max",useGDAL=FALSE )
>>
>> Creating BIL support files...
>> Header File =
>>
>> /home/rkrug/Documents/Projects/AlienSpread/R/../grass/simulation/.tmp/ecolmod/ros_2016.max.hdr
>> World File =
>>
>> /home/rkrug/Documents/Projects/AlienSpread/R/../grass/simulation/.tmp/ecolmod/ros_2016.max.wld
>> Exporting raster as integer values (bytes=2)
>> Using the current region settings...
>> north=6247000.000000
>> south=6195000.000000
>> east=270200.000000
>> west=251000.000000
>> r=520
>> c=192
>> 100%
>>>
>>> range(x[[1]], na.rm=TRUE)
>>
>> [1] -31916  30755
>>>
>>> x <- readRAST6("ros_2016.max",useGDAL=TRUE )
>>
>> ERROR 6: SetColorTable() only supported for Byte or UInt16 bands in TIFF
>> format.
>> WARNING: Input raster map constains cells with NULL-value (no-data). The
>>        value 999 was used to represent no-data values in the input
>>        map.You can specify nodata value by nodata parameter.
>>
>> /home/rkrug/Documents/Projects/AlienSpread/R/../grass/simulation/.tmp/ecolmod/ros_2016.max
>> has GDAL driver GTiff
>> and has 520 rows and 192 columns
>>>
>>> range(x[[1]], na.rm=TRUE)
>>
>> [1]     0 36852
>>>
>>
>> I would suggest that you proceed as suggested below.
>>
>> Thanks
>>
>> Rainer
>>
>>
>>
>>
>> On Thu, Sep 18, 2008 at 11:01 PM, Roger Bivand <Roger.Bivand at nhh.no>
>> wrote:
>>>
>>> Roger Bivand <Roger.Bivand <at> nhh.no> writes:
>>>
>>>>
>>>> Markus Neteler <neteler <at> osgeo.org> writes:
>>>>
>>>>>
>>>>> On Wed, Sep 17, 2008 at 10:49 AM, Roger Bivand <Roger.Bivand <at>
>>>>> nhh.no> wrote:
>>>>>>
>>>>>> Markus Neteler <neteler <at> osgeo.org> writes:
>>>>>>
>>>>> means:
>>>>> - the GDAL plugin is no option here since it does not respect current
>>>>>  region settings
>>>>> - r.out.gdal is good since it does the job (AFAIK). Written in C
>>>
>>>> I can revisit this in relation to using r.out.gdal for GRASS >= 6.3
>>>> instead of r.out.bin - in which case I can make r.out.gdal use 32
>>>> bits for integers and 64 bits for float/doubles.
>>>
>>> Committed on R-spatial sourceforge CVS, new flag useGDAL=FALSE for now
>>> default, uses Int32 for CELL, so maybe could be tried to see if it works
>>> better than r.out.bin.
>>>
>>> If it does, I'll change writeRAST6() too, change the default to TRUE, and
>>> release.
>>>
>>> Roger
>>>
>>>>
>>>> Roger
>>>>
>>>>> Perhaps you mean r.out.gdal.sh?
>>>>>
>>>>> Best
>>>>> Markus
>>>>>
>>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> grass-dev mailing list
>>> grass-dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/grass-dev
>>>
>>
>>
>>
>>
>
> --
> 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
>
>



-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Faculty of Science
Natural Sciences Building
Private Bag X1
University of Stellenbosch
Matieland 7602
South Africa


More information about the grass-dev mailing list