0

I am generating a regression model using several environmental covariates. Before importing the GIS layers to GRASS I had them as ESRI raster format. I exported them to ASCII file, and from ASCII file I imported them to GRASS. I did this a couple of momths ago, I believe, because I was having trouble finding a different way of importing the layers directly from ESRI raster.

In GRASS I did several operations and corrections of my raster files. After, I used the package spgrass6 to import the raster files to R, directly. I created a SpatialGridDataFraME

In my preliminary data exploration I see a lot of nan, and I wonder whether I did any mistake exporting the files to ASCII files, or whether is these nan's are normal, since I have many empty cells in my grid (cells outside my study region, but that are within the box, or the grid defined by the region in GRASS).

I want to get rid of NA values, and so I tried:

region.pt <- as.(region, 'SpatialPointsDataFrame')

But it gave me an error:

cannot allocate vector of size 2.3 Gb

My SpatialGridDataFrame is 1.9 GB!!!

Should I clean all these nan values BEFORE importing them into GRASS, or before importing them into R?

Or is it OK to oblige the spatialGridDataFrame to become SpatialPointsDataFrame?

What will happen with nan's?

How can I get only the pixels within my study area?

closed as too broad by PolyGeo Dec 7 '17 at 5:44

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

I believe that you are making this much more difficult than it needs to be. You can, in fact, read ESRI format rasters (not filegeodatabases) using rgdal, which also means that the raster package can read ESRI rasters.

Since your raster(s) is so large it will continue to plague you when operating in memory. By using the raster package, you can keep the problem memory safe. Unless there is a very specific reason, I would not use SpatialGridDataFrame objects. You gain notable functionality in the raster package and predict your regression model directly to a file on disk using R's generic predict function.

I would also point out that sp class objects are a data structure in R and not a raster format per se. Because of this you cannot look at the size of a file on disk and expect an sp object to be the same size. Because I have absoutly no idea what "processing" was done or how they were read into R, there is no way to evaluate your question about NA's and NaN's in GRASS format rasters.

  • I had my ESRI files in a File Geodatabase. I then imported them into GRASS because I needed to calculate the mean, meadian, and the mode of all the rasters (base raster) by a zonal raster which indicated the french commune, or municipality. I was looking ways of doing that in R, but in GRASS it seems very eary with functions r.univar and r.mode. – MercedesRD Feb 10 '15 at 15:55
  • I also had to create new rasters (not a lot, but 5) with raster calculator, assigning percentage of land use to the whole commune. Since I had all the data in GRASS, I decided to used the GRASS-R interface. import them directly. I guess the question is whether I can import these rasters using spgrass6 into raster, or spatialPointDataFrame, for example. – MercedesRD Feb 10 '15 at 16:01
  • Also, I had trouble, since not all rasters has originally the same number of cells. To operate with raster (e.g., mask, clip), I needed the same extent and alignment (yes, I had it), but not the same size, or number of cells. Using spgrass6 was easier. Still, I am looking how to do it with the package raster. – MercedesRD Feb 10 '15 at 16:17
  • You can import GRASS format rasters using the raster package. I have a feeling that NaN's in the source data are being created by divide-by-zero errors in GRASS and NA's are common in rasters and not necessary to remove. They often represent the extent, where there is actually no data. If you forcibly remove NA's you will likely cause misalignment issues in your data. Besides, as I mentioned reading your GRASS rasters in as a raster stack will allow you to predict directly to a specified on-disk raster making everything memory safe. – Jeffrey Evans Feb 10 '15 at 16:21
  • Thank you, I will look for how to import GRASS format rasters with the raster package. – MercedesRD Feb 10 '15 at 16:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.