spgrass problem importing category 999 when plugin is FALSE

5 messages Options
Embed this post
Permalink
Jarosław Jasiewicz

spgrass problem importing category 999 when plugin is FALSE

Reply Threaded More More options
Print post
Permalink
Hi

I during batch processing of couple of maps I found strange behaviour of
readRAST6 when I import cell map with value 999.
Instead of 999 Na is imported (?? _

It is for me completely strange, so I test it with folowing:

echo "test_map=999"|r.mapclac
R
library(spgrass6)
testNoPlugin=readRAST6("test_map",plugin=FALSE)

summary(testNoPlugin@data)

     test      Min.   :    NA 1st Qu.:    NA Median :    NA Mean   :  
NaN 3rd Qu.:    NA Max.   :    NA NA's   :156740

testPlugin=readRAST6("test_map",plugin=TRUE)

summary(testPlugin@data)

     test   Min.   :999 1st Qu.:999 Median :999 Mean   :999 3rd Qu.:999
Max.   :999


It is very strange for me but I tested it on several maps. I think
someone could try to reproduce this.

Jarek


BTW:

R version 2.8.1 (2008-12-22)


library(spgrass6)
Loading required package: sp
Loading required package: rgdal
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.5.3, released 2008/09/09
GDAL_DATA: /usr/local/lib/R/site-library/rgdal/gdal
Loaded PROJ.4 runtime: Rel. 4.6.1, 21 August 2008
PROJ_LIB: /usr/local/lib/R/site-library/rgdal/proj
GRASS GIS interface loaded with GRASS version: 6.5.svn
and location: Rzeki

Package: spgrass6
Version: 0.5-16
Date: 2008-11-13
Built: R 2.8.1; ; 2009-01-02 14:02:31; unix




_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Markus Neteler

Re: spgrass problem importing category 999 when plugin is FALSE

Reply Threaded More More options
Print post
Permalink
Here my tests which look ok:

GRASS 6.5.svn (portugal):> echo "test_map=999"|r.mapcalc
 100%
GRASS 6.5.svn (portugal):> R

R version 2.8.1 (2008-12-22)
...
> library(spgrass6)
Loading required package: sp
Loading required package: rgdal
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.6.0, released 2008/11/26
Path to GDAL shared files: /usr/local/share/gdal
Loaded PROJ.4 runtime: Rel. 4.6.1, 21 August 2008
Path to PROJ.4 shared files: (autodetected)
GRASS GIS interface loaded with GRASS version: 6.5.svn
and location: portugal
> testNoPlugin=readRAST6("test_map",plugin=FALSE)
/home/neteler/grassdata/portugal/PERMANENT/.tmp/localhost/test_map has
GDAL driver GTiff
and has 1 rows and 1 columns
>
> summary(testNoPlugin@data)
    test_map
 Min.   :999
 1st Qu.:999
 Median :999
 Mean   :999
 3rd Qu.:999
 Max.   :999
>
> testPlugin=readRAST6("test_map",plugin=TRUE)
/home/neteler/grassdata/portugal/PERMANENT/cellhd/test_map has GDAL driver GRASS
and has 1 rows and 1 columns
> summary(testNoPlugin@data)
    test_map
 Min.   :999
 1st Qu.:999
 Median :999
 Mean   :999
 3rd Qu.:999
 Max.   :999

Markus


2009/4/3 Jarek Jasiewicz <[hidden email]>:

> Hi
>
> I during batch processing of couple of maps I found strange behaviour of
> readRAST6 when I import cell map with value 999.
> Instead of 999 Na is imported (?? _
>
> It is for me completely strange, so I test it with folowing:
>
> echo "test_map=999"|r.mapclac
> R
> library(spgrass6)
> testNoPlugin=readRAST6("test_map",plugin=FALSE)
>
> summary(testNoPlugin@data)
>
>    test      Min.   :    NA 1st Qu.:    NA Median :    NA Mean   :   NaN 3rd
> Qu.:    NA Max.   :    NA NA's   :156740
>
> testPlugin=readRAST6("test_map",plugin=TRUE)
>
> summary(testPlugin@data)
>
>    test   Min.   :999 1st Qu.:999 Median :999 Mean   :999 3rd Qu.:999 Max.
> :999
>
> It is very strange for me but I tested it on several maps. I think someone
> could try to reproduce this.
>
> Jarek
>
>
> BTW:
>
> R version 2.8.1 (2008-12-22)
>
>
> library(spgrass6)
> Loading required package: sp
> Loading required package: rgdal
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 1.5.3, released 2008/09/09
> GDAL_DATA: /usr/local/lib/R/site-library/rgdal/gdal
> Loaded PROJ.4 runtime: Rel. 4.6.1, 21 August 2008
> PROJ_LIB: /usr/local/lib/R/site-library/rgdal/proj
> GRASS GIS interface loaded with GRASS version: 6.5.svn
> and location: Rzeki
>
> Package: spgrass6
> Version: 0.5-16
> Date: 2008-11-13
> Built: R 2.8.1; ; 2009-01-02 14:02:31; unix
>
>
>
>
> _______________________________________________
> grass-stats mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/grass-stats
>
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand

Re: spgrass problem importing category 999 when plugin is FALSE

Reply Threaded More More options
Print post
Permalink
In reply to this post by Jarosław Jasiewicz
On Fri, 3 Apr 2009, Jarek Jasiewicz wrote:

> Hi
>
> I during batch processing of couple of maps I found strange behaviour of
> readRAST6 when I import cell map with value 999.
> Instead of 999 Na is imported (?? _
>
> It is for me completely strange, so I test it with folowing:

OK. This is a consequence of trying to guess the NODATA value to pass to
r.out.gdal, and I don't see it in 0.5-19 (my local slightly changed from
CRAN latest 0.5-18). For certain range values retrieved from r.info,
NODATA is assigned the value 999 (R/bin_link.R, about line 113). Please
try 0.5-18, I suspect that the condition was changed. Alternatively, set
NODATA to a suitable value outside the range of the data. Note that I
don't have a 6.5 GRASS, and if r.info output has changed format, the
parsing will be wrong, and
(!is.numeric(lres$min) || !is.finite(as.double(lres$min)) will be
triggered, setting NODATA to 999.

What does r.info test_map look like in 6.5? In 6.3 it is:

> system("r.info test_map")

+----------------------------------------------------------------------------+
| Layer:    test_map                       Date: Fri Apr  3 08:41:58 2009    |
| Mapset:   rsb                            Login of Creator: rsb             |
| Location: spearfish60                                                      |
| DataBase: /home/rsb/topics/grassdata                                       |
| Title:     ( test_map )                                                    |
| Timestamp: none                                                            |
|----------------------------------------------------------------------------|
|                                                                            |
|   Type of Map:  raster               Number of Categories: 999             |
|   Data Type:    CELL                                                       |
|   Rows:         143                                                        |
|   Columns:      190                                                        |
|   Total Cells:  27170                                                      |
|        Projection: UTM (zone 13)                                           |
|            N:    4928010    S:    4913700   Res: 100.06993007              |
|            E:     609000    W:     589980   Res: 100.10526316              |
|   Range of data:    min = 999  max = 999                                   |
|                                                                            |
|   Data Description:                                                        |
|    generated by r.mapcalc                                                  |
|                                                                            |
|   Comments:                                                                |
|    999                                                                     |
|                                                                            |
+----------------------------------------------------------------------------+

I guess that there is a smarter way of getting the raster min/max too,
isn't there?

Hope this helps,

Roger

>
> echo "test_map=999"|r.mapclac
> R
> library(spgrass6)
> testNoPlugin=readRAST6("test_map",plugin=FALSE)
>
> summary(testNoPlugin@data)
>
>    test      Min.   :    NA 1st Qu.:    NA Median :    NA Mean   :   NaN 3rd
> Qu.:    NA Max.   :    NA NA's   :156740
>
> testPlugin=readRAST6("test_map",plugin=TRUE)
>
> summary(testPlugin@data)
>
>    test   Min.   :999 1st Qu.:999 Median :999 Mean   :999 3rd Qu.:999 Max.
> :999
>
> It is very strange for me but I tested it on several maps. I think someone
> could try to reproduce this.
>
> Jarek
>
>
> BTW:
>
> R version 2.8.1 (2008-12-22)
>
>
> library(spgrass6)
> Loading required package: sp
> Loading required package: rgdal
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 1.5.3, released 2008/09/09
> GDAL_DATA: /usr/local/lib/R/site-library/rgdal/gdal
> Loaded PROJ.4 runtime: Rel. 4.6.1, 21 August 2008
> PROJ_LIB: /usr/local/lib/R/site-library/rgdal/proj
> GRASS GIS interface loaded with GRASS version: 6.5.svn
> and location: Rzeki
>
> Package: spgrass6
> Version: 0.5-16
> Date: 2008-11-13
> Built: R 2.8.1; ; 2009-01-02 14:02:31; unix
>
>
>
>
> _______________________________________________
> grass-stats mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/grass-stats
>

--
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: [hidden email]

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway
Markus Neteler

Re: spgrass problem importing category 999 when plugin is FALSE

Reply Threaded More More options
Print post
Permalink
On Fri, Apr 3, 2009 at 9:07 AM, Roger Bivand <[hidden email]> wrote:

> On Fri, 3 Apr 2009, Jarek Jasiewicz wrote:
>
>> Hi
>>
>> I during batch processing of couple of maps I found strange behaviour of
>> readRAST6 when I import cell map with value 999.
>> Instead of 999 Na is imported (?? _
>>
>> It is for me completely strange, so I test it with folowing:
>
> OK. This is a consequence of trying to guess the NODATA value to pass to
> r.out.gdal,

The C version of r.out.gdal has a nodata parameter.

> and I don't see it in 0.5-19 (my local slightly changed from
> CRAN latest 0.5-18). For certain range values retrieved from r.info, NODATA
> is assigned the value 999 (R/bin_link.R, about line 113). Please try 0.5-18,
> I suspect that the condition was changed. Alternatively, set NODATA to a
> suitable value outside the range of the data. Note that I don't have a 6.5
> GRASS, and if r.info output has changed format, the parsing will be wrong,

It didn't change the format to my knowledge. BUT:
To get the range, use
r.info -r test_map
min=999
max=999

The parsing of plain r.info will fail in non-English locales (or enforce C
locale).

...
> I guess that there is a smarter way of getting the raster min/max too, isn't
> there?

Yes, please always use the script output flags which are not subject to locale
and way easier to parse. If missing in a module, we are happy to add it.
It also exists in GRASS 6.3:
http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_6_3/raster/r.info/main.c#L74

Best
Markus
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand

Re: spgrass problem importing category 999 when plugin is FALSE

Reply Threaded More More options
Print post
Permalink
On Fri, 3 Apr 2009, Markus Neteler wrote:

> On Fri, Apr 3, 2009 at 9:07 AM, Roger Bivand <[hidden email]> wrote:
>> On Fri, 3 Apr 2009, Jarek Jasiewicz wrote:
>>
>>> Hi
>>>
>>> I during batch processing of couple of maps I found strange behaviour of
>>> readRAST6 when I import cell map with value 999.
>>> Instead of 999 Na is imported (?? _
>>>
>>> It is for me completely strange, so I test it with folowing:
>>
>> OK. This is a consequence of trying to guess the NODATA value to pass to
>> r.out.gdal,
>
> The C version of r.out.gdal has a nodata parameter.

Yes, this is what is used, NODATA is the argument name in readRAST6.

>
>> and I don't see it in 0.5-19 (my local slightly changed from
>> CRAN latest 0.5-18). For certain range values retrieved from r.info, NODATA
>> is assigned the value 999 (R/bin_link.R, about line 113). Please try 0.5-18,
>> I suspect that the condition was changed. Alternatively, set NODATA to a
>> suitable value outside the range of the data. Note that I don't have a 6.5
>> GRASS, and if r.info output has changed format, the parsing will be wrong,
>
> It didn't change the format to my knowledge. BUT:
> To get the range, use
> r.info -r test_map
> min=999
> max=999
>
> The parsing of plain r.info will fail in non-English locales (or enforce C
> locale).

I use r.info -r test_map in the function, but was replying without
checking properly, sorry.

I guess it's an spgrass6 version issue.

Best wishes,

Roger

>
> ...
>> I guess that there is a smarter way of getting the raster min/max too, isn't
>> there?
>
> Yes, please always use the script output flags which are not subject to locale
> and way easier to parse. If missing in a module, we are happy to add it.
> It also exists in GRASS 6.3:
> http://trac.osgeo.org/grass/browser/grass/branches/releasebranch_6_3/raster/r.info/main.c#L74
>
> Best
> Markus
>

--
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: [hidden email]

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway