Tiffany,

You can also use

r <- raster()
r[] <- 1:ncell(r)
r <- brick(r,r*2)
p <- rasterToPoints(r)

write.table(p, "file2.txt")

This will add the x and y, but omit NA cells. It also allows to you to use
an expression to subset the values you want (e.g. only values > 0)

Robert


On Wed, Oct 3, 2012 at 4:05 PM, Matteo Mattiuzzi <
matteo.mattiu...@boku.ac.at> wrote:

> Hi,
> the only way I can see is to use ?xyFromCell
>
>
> r <- raster()
> r[] <- 1:ncell(r)
> r <- brick(r,r*2)
>
>
> vals <- getValues(r)
>
> coords <- xyFromCell(r,1:ncell(r))
> res <- cbind(coords,vals)
> write.table(res,"file1.txt")
>
>
>
> Matteo
>
>
> >>> Tiffany Smith  03.10.12 22.34 Uhr >>>
> Hello,
>
> I'm trying to write out the values of a RasterBrick to a .txt file. Here's
> what I have:
>
> b<-brick("file1.nc")
> vals<-getValues(b)
> write.table(vals,"file1.txt")
>
> Where 'b' is a RasterBrick with dimensions [224,464,33] which corresponds
> to [lat,lon,time]. The output, 'vals' has dimensions [103936,33] which
> correspond to [cell#,time].
>
> 'b' has actual lat & lon associated with it's extent; I would like to
> write the .txt file so that it included 'vals' and the associated lat &
> lon. Right now, the output file has columns filled with cell# (lat*lon) and
> time, I would like for there to also be columns for lat and lon.
>
> Any ideas?
>
> Thanks,
> Tiffany
>     [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to