An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20130619/9cd22c9a/attachment.pl>
How to extract the index (i, j) row and column from a raster?
4 messages · Alex, Lionel, Rafael Wüest +1 more
The easiest way is to use the function 'values' which return the values of a raster row by row: r<-raster(nrows=10,ncols=10) r[]<-rnorm(100) data<-data.frame(X=rep(1:10,each=10),Y=rep(1:10,10),Z=values(r)) head(data) Cheers, Lionel
On 19/06/2013 12:42, Alex wrote:
Please, I would like to create a file with the following information from a raster: - The position (i, j) of each cell, and the value represented in pixel. Composing a matrix X, Y, Z. At the end, I have the intention to turn this array into a polygon shapefile. Is there any function for this in R? I thank you, Alex Santos [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Well, if the ultimate aim is to build a polygon from a raster, I suggest you look at library(raster) ?rasterToPolygons Rafael
On 19.06.2013, at 13:00, Lionel Hertzog <s6lihert at uni-bonn.de> wrote:
The easiest way is to use the function 'values' which return the values of a raster row by row: r<-raster(nrows=10,ncols=10) r[]<-rnorm(100) data<-data.frame(X=rep(1:10,each=10),Y=rep(1:10,10),Z=values(r)) head(data) Cheers, Lionel On 19/06/2013 12:42, Alex wrote:
Please, I would like to create a file with the following information from a raster: - The position (i, j) of each cell, and the value represented in pixel. Composing a matrix X, Y, Z. At the end, I have the intention to turn this array into a polygon shapefile. Is there any function for this in R? I thank you, Alex Santos [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
-- Rafael W?est Swiss Federal Research Institute WSL Z?rcherstrasse 111 8903 Birmensdorf Switzerland +41 44 7392126 rafael.wueest at wsl.ch http://www.wsl.ch/info/mitarbeitende/wueest/index_EN
I think the first part of what you're looking for is in the raster package. You can load your raster file using the raster() function (instead of creating one from scratch as in the example below). Then use the rasterToPoints() function to convert to a matrix object: require(raster) r <- raster(nrow=10, ncol=10, xmn=0, xmx=10, ymn=0, ymx=10, crs=NA) r[] <- runif(ncell(r)) r[r<0.5] <- NA xyz <- rasterToPoints(r)
From there it's relatively trivial to extract a subset of points and
convert to polygons via a variety of paths. But if it's just a subset of values you're looking to convert you might look at the rasterToPolygons() function as well, it may do what you need. Sincerely, Forrest
On Wed, Jun 19, 2013 at 6:42 AM, Alex <alxcart at gmail.com> wrote:
Please, I would like to create a file with the following information from a
raster:
- The position (i, j) of each cell, and the value represented in pixel.
Composing a matrix X, Y, Z.
At the end, I have the intention to turn this array into a polygon
shapefile.
Is there any function for this in R?
I thank you,
Alex Santos
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Forrest R. Stevens Ph.D. Candidate, QSE3 IGERT Fellow Department of Geography Land Use and Environmental Change Institute University of Florida www.clas.ufl.edu/users/forrest