[R-sig-Geo] How to extract the index (i, j) row and column from a raster?

Forrest Stevens forrest at ufl.edu
Wed Jun 19 17:36:41 CEST 2013

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:

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.


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

More information about the R-sig-Geo mailing list