<div dir="ltr"><div><div><div>I think I discovered the problem. This was a mistake on my side:<br></div>The summary() function in R applied on a raster does subsample the<br></div>data in case of very large raster maps. However, this seems to<br>cause that summary information about NA gets lost and no NA are<br>mentioned in the summary output although there are NA included<br>in the raster map.<br><br></div>Here an example output of a map with lots of NA's which are ignored<br>by summary(rastermap):<br><br>> summary(streams[[1]])<br>        Elbe_distance_from_mouth<br>Min.                      0.0000<br>1st Qu.                 488.7067<br>Median                  789.8560<br>3rd Qu.                1025.4501<br>Max.                   1876.6429<br>NA's                      0.0000<br>Warning message:<br>In .local(object, ...) :<br>  summary is an estimate based on a sample of 1e+05 cells (10.7% of all cells)<br><br>> length(bioclim[[1]][<a href="http://is.na">is.na</a>(bioclim[[1]])])<br>[1] 12688<br><div><br><br></div><div>So there was actually no problem, just some confusion concerning the information about<br>NA in the summary.<br><br>Best regards,<br>Johannes<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 4, 2014 at 6:26 PM, Robert J. Hijmans <span dir="ltr"><<a href="mailto:r.hijmans@gmail.com" target="_blank">r.hijmans@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Johannes,<br>
<br>
raster uses GDAL to access GTiff data. So it seems that there is no,<br>
or at least GDAL does not see, a no data value in the file.<br>
I would suggest running GDALinfo to troubleshoot. Can you email me a<br>
small example file?<br>
<br>
By the way, the spgrass6 route has a shortcoming: it may not work with<br>
very large files as it attempts to load all values into RAM.<br>
<br>
Robert<br>
<br>
On Thu, Sep 4, 2014 at 6:47 AM, Johannes Radinger<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:johannesradinger@gmail.com">johannesradinger@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Sep 4, 2014 at 3:38 PM, Nuno Sá <<a href="mailto:nunocesardesa@gmail.com">nunocesardesa@gmail.com</a>> wrote:<br>
>><br>
>> Hello!<br>
>><br>
>> Did you try this one?<br>
>><br>
>> r.out.gdal etc nodata='NA'<br>
><br>
><br>
> As mentioned in the manual of r.out.gdal, the no data parameter takes only<br>
> float values<br>
> and no strings like 'NA'. Without stating as specific value in GRASS, this<br>
> nodata-value is<br>
> automatically set to e.g. 65535 for DCELL rasters if I remember correctly<br>
> and to 255<br>
> for BYTE rasters. However, this seems not to be recognized when imported<br>
> into R with<br>
> the package 'raster'.<br>
><br>
> /Johannes<br>
><br>
>><br>
>><br>
>><br>
>><br>
>> On 4 September 2014 14:27, Johannes Radinger <<a href="mailto:johannesradinger@gmail.com">johannesradinger@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> Hi all,<br>
>>><br>
>>> of course it is possible to load the raster maps directly via spgrass6.<br>
>>> However, we use this work<br>
>>> flow also to exchange some of the maps between different users (e.g. via<br>
>>> email) and to permanently<br>
>>> store single files (geotiffs that contain the proj information within the<br>
>>> file). So, I agree that using spgrass6 would be much more efficient, but<br>
>>> I'll stick to exporting to geotiffs and so I need to solve the issues with<br>
>>> NA's.<br>
>>><br>
>>> /Johannes<br>
>>><br>
>>><br>
>>> On Thu, Sep 4, 2014 at 2:31 PM, Thomas Adams <<a href="mailto:tea3rd@gmail.com">tea3rd@gmail.com</a>> wrote:<br>
>>>><br>
>>>> Johannes,<br>
>>>><br>
>>>> If you want to read your file into R, there is no need to export your<br>
>>>> map from GRASS to do this. Simply install and use the R contributed package<br>
>>>> 'spgrass6' (spgrass6 has R dependencies that need to be installed first); it<br>
>>>> works wonderfully:<br>
>>>><br>
>>>> Within GRASS, at the GRASS terminal prompt...<br>
>>>><br>
>>>> > library(spgrass6)<br>
>>>> Loading required package: sp<br>
>>>> Loading required package: XML<br>
>>>> GRASS GIS interface loaded with GRASS version: GRASS 7.0.0beta3 (2014)<br>
>>>> and location: ohrfc_mpe<br>
>>>> > dat<-readRAST6("xmrg0101200306z")<br>
>>>> > image(dat)<br>
>>>><br>
>>>> This is far more efficient.<br>
>>>><br>
>>>> Tom<br>
>>>><br>
>>>><br>
>>>> On Thu, Sep 4, 2014 at 5:32 AM, Johannes Radinger<br>
>>>> <<a href="mailto:johannesradinger@gmail.com">johannesradinger@gmail.com</a>> wrote:<br>
>>>>><br>
>>>>> Hi,<br>
>>>>><br>
>>>>> I want to export a raster map (FCELL) from GRASS70 to the geotiff<br>
>>>>> format using r.out.gdal and to import it later on in R. The map contains<br>
>>>>> many no data values.<br>
>>>>><br>
>>>>> Here some details about the raster:<br>
>>>>> Type of Map:  raster               Number of Categories: 0<br>
>>>>> Data Type:    FCELL<br>
>>>>> Rows:         750<br>
>>>>> Columns:      750<br>
>>>>> Total Cells:  562500<br>
>>>>> total null and non-null cells: 15105636<br>
>>>>> total null cells: 15105047<br>
>>>>><br>
>>>>> So when I export the map, r.out.gdal reports: "Input raster map<br>
>>>>> contains cells with NULL-value (no-data). The value -nan will be used to<br>
>>>>> represent no-data values in the input map. You can specify a nodata value<br>
>>>>> with the nodata option."<br>
>>>>><br>
>>>>> When I subsequently try to import the geotiff into R (using the package<br>
>>>>> 'Raster') the nodata values are not recognised as NA's:<br>
>>>>><br>
>>>>> a <- raster("*.tif")<br>
>>>>> summary(a)<br>
>>>>> Min.     <a href="tel:0.5294496" value="+495294496">0.5294496</a><br>
>>>>> 1st Qu.  <a href="tel:0.7171210" value="+497171210">0.7171210</a><br>
>>>>> Median   <a href="tel:0.7871540" value="+497871540">0.7871540</a><br>
>>>>> 3rd Qu.  1.1581826<br>
>>>>> Max.     1.5494517<br>
>>>>> NA's     0.0000000<br>
>>>>><br>
>>>>> So I am wondering if I need to set any specific parameter during the<br>
>>>>> export (r.out.gdal) or import (raster()).<br>
>>>>><br>
>>>>> As I am not only exporting FCELL (Float32) raster but also multiple<br>
>>>>> (N=500) other rasters to R I would be interested in a solution also for<br>
>>>>> DCELL (Float64). Of course I can export all of as Float64 as the file size<br>
>>>>> should not be a problem.<br>
>>>>><br>
>>>>> Any suggestions or experiences of handling NA's during raster exchange<br>
>>>>> between GRASS and R?<br>
>>>>><br>
>>>>> /Johannes<br>
>>>>><br>
>>>>> _______________________________________________<br>
>>>>> grass-user mailing list<br>
>>>>> <a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>
>>>>> <a href="http://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-user</a><br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> grass-user mailing list<br>
>>> <a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br>
>>> <a href="http://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-user</a><br>
>><br>
>><br>
>><br>
>><br>
>> --<br>
>><br>
>> Nuno César de Sá<br>
>> <a href="tel:%2B351%2091%20961%2090%2037" value="+351919619037">+351 91 961 90 37</a><br>
>><br>
><br>
</div></div></blockquote></div><br></div>