[R-sig-Geo] Converting raster to a matrix
Ben Tupper
btupper at bigelow.org
Tue Jan 24 15:19:36 CET 2017
Hi,
It doesn't seem to be noted in the documentation for raster::raster(), but when you create a RasterLayer from a RasterLayer, as in your
> rast <- raster(image)
step, the values are stripped from the resulting RasterLayer. Why don't you eliminate that step and retrieve the matrix from your first RasterLayer?
> mat <- as.matrix(image)
> str(mat)
int [1:68, 1:65] NA NA NA NA NA NA NA NA NA NA ...
Ben
> On Jan 24, 2017, at 3:23 AM, John Wasige <johnwasige at gmail.com> wrote:
>
> Dear all,
> Greetings!
>
> I want to convert a big raster (see attached) a matrix, however, I get the error below from the script. Anybody with an Idea on what is going wrong in my script?
>
> ###Errors at the following point in the script
>
> > mat <- as.matrix(rast)
> Error in .local(x, ...) : 'x' has no values
>
> #####script
>
>
> library(raster)
> library(rgdal)
>
> setwd('D:/Mobile_testdata')
> image <- raster('D:/Mobile_testdata/SOSug_mean2qgis.tif')
>
> rast <- raster(image)
> mat <- as.matrix(rast)
>
> Thanks for your help
>
> Rgds John
>
> <SOSug_mean2qgis.tif.aux.xml><SOSug_mean2qgis.tfw><SOSug_mean2qgis.tif><SOSug_mean2qgis.tif.vat.cpg><SOSug_mean2qgis.tif.vat.dbf>_______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list