Re: [R-sig-Geo] Extract location information from grid cells for sample points [SEC=UNCLASSIFIED]

2012-10-03 Thread Jin . Li
Great! Thank you very much Robert. Jin From: Robert J. Hijmans [mailto:r.hijm...@gmail.com] Sent: Thursday, 4 October 2012 4:35 PM To: Li Jin Cc: r-sig-geo@r-project.org Subject: Re: [R-sig-Geo] Extract location information from grid cells for sample points [SEC=U

Re: [R-sig-Geo] Extract location information from grid cells for sample points [SEC=UNCLASSIFIED]

2012-10-03 Thread Robert J. Hijmans
Jin, To get the x and y coordinates for (the center of) the raster cells, you can use # get cells corresponding to the points cells <- cellFromXY(r, p) # get coordinates for these cells xy <- xyFromCell(r, cells) Robert On Wed, Oct 3, 2012 at 11:25 PM, wrote: > ** ** ** ** ** ** > > Hi Ro

Re: [R-sig-Geo] Extract location information from grid cells for sample points [SEC=UNCLASSIFIED]

2012-10-03 Thread Jin . Li
Hi Robert, Thanks for the clarification. Yes the gridcells.txt is regular spaced points at 0.0025 degree resolution. I was able to run the code, but extracted the z values instead of x and y values. Is it possible to extract them? Thanks, Jin From: Robert J. Hijm

Re: [R-sig-Geo] Extract location information from grid cells for sample points [SEC=UNCLASSIFIED]

2012-10-03 Thread Robert J. Hijmans
On Wed, Oct 3, 2012 at 9:20 PM, wrote: > ** ** ** ** ** ** > > Hi Robert, > > Thank you very much for the reply. Both datasets are in txt format. Lat > and long are in WGS84. So I might need to do something like: > > library(raster) > > p <- read.table('points.txt') > > d <- read.

Re: [R-sig-Geo] Error: NA/NaN/Inf in foreign function call (arg 7) while using Predict function with Raster

2012-10-03 Thread Robert J. Hijmans
Ani, The raster::predict function has na.rm=TRUE and removes the NA values, but not -Inf/Inf values and that indeed seems to be the problem here (see example below). I have added an option "inf.rm" to the predict function of the development version of 'raster' (version 2.0-20) you can try to insta

Re: [R-sig-Geo] Extract location information from grid cells for sample points [SEC=UNCLASSIFIED]

2012-10-03 Thread Jin . Li
Hi Robert, Thank you very much for the reply. Both datasets are in txt format. Lat and long are in WGS84. So I might need to do something like: library(raster) p <- read.table('points.txt') d <- read.table('gridcells.txt') r <- rasterFromPoints(d) values<- extract(r, p) Is anything else I should

Re: [R-sig-Geo] [raster newbie] projectRaster hangs regridding global latlong -> CONUS LCC

2012-10-03 Thread Robert J. Hijmans
Tom, I do not know why you say the output is wrong. Why you would expect that input variables would have to be "preserved" (copied to the output file)? For 'raster' there is input data and output data, the input and output files (formats, attributes) are not related in any way. You could use the

Re: [R-sig-Geo] Antw: Writing Raster values to .txt file

2012-10-03 Thread Robert J. Hijmans
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, 2

Re: [R-sig-Geo] Extract location information from grid cells for sample points [SEC=UNCLASSIFIED]

2012-10-03 Thread Robert J. Hijmans
Hi Jin, >From your description it is not entirely clear what your input data looks like. But you can something like this library(raster) p <- read.table('points.txt') r <- raster('file.asc') values<- extract(r, p) Perhaps you need to subset "p" to get the appropriate columns representing longit

[R-sig-Geo] Geographical Interpolation functions

2012-10-03 Thread Camilo Mora
Hi I am comparing different interpolation methods on climate data. I have found quite a few functions (e.g. spline and kriging) but I wonder if Nearest-neighbor interpolation and Natural neighbor function are available in an R package? Thanks, Camilo Camilo Mora, Ph.D. Department of Geog

Re: [R-sig-Geo] Extract location information from grid cells for sample points [SEC=UNCLASSIFIED]

2012-10-03 Thread Thomas Adams
Jin, I'd be willing to wager it can be done in R alone as someone is sure to point out, but since you're using R (and so, willing to go the open source route), you may be willing to take another step and use GRASS GIS ( http://grass.osgeo.org) — the wonderful thing about this is that your problem

[R-sig-Geo] Extract location information from grid cells for sample points [SEC=UNCLASSIFIED]

2012-10-03 Thread Jin . Li
Dear list, I have two datasets: one is for point samples with lat and long information at accuracy of 0.001 degrees. Another is grid cells at a resolution of 0.0025 degrees. Both datasets are in txt format. Now I need to extract the lat and long information from the grid cell dataset for the po

Re: [R-sig-Geo] projectRaster() produces an object with no values

2012-10-03 Thread rr2box42
Oh, I see. My 'from.rast' extent is given from (0,360) degrees longitude, rather than (-180, 180). I "fixed" that per this thread: https://stat.ethz.ch/pipermail/r-sig-geo/2011-March/011155.html And then the projection works fine. -- View this message in context: http://r-sig-geo.2731867.n2.

[R-sig-Geo] Antw: Writing Raster values to .txt file

2012-10-03 Thread Matteo Mattiuzzi
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

Re: [R-sig-Geo] projectRaster() produces an object with no values

2012-10-03 Thread rr2box42
I am having the same problem as the OP. I understand Robert's response, but I don't think it applies to my situation. Any ideas? Here are my rasters: > from.rast class : RasterLayer band: 2 dimensions : 96, 192, 18432 (nrow, ncol, ncell) resolution : 1.875, 1

[R-sig-Geo] Writing Raster values to .txt file

2012-10-03 Thread Tiffany Smith
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

Re: [R-sig-Geo] [raster newbie] projectRaster hangs regridding global latlong -> CONUS LCC

2012-10-03 Thread Tom Roche
summary: Robert Hijmans' advice fixed my hang, but now I'm getting very wrong output--i.e., input variables are not preserved. How to get the appropriate output schema (e.g., data variables)? details: https://stat.ethz.ch/pipermail/r-sig-geo/2012-October/016215.html >> My current [NetCDF] input

[R-sig-Geo] Error: NA/NaN/Inf in foreign function call (arg 7) while using Predict function with Raster

2012-10-03 Thread aniruddha ghosh
Dear List, I'm trying to classify a multiband raster with point shapefiles as training data. I used the following: vec<-readOGR(".","training") raster<-stack("test.tif") #it contains around 10 pixels and 240 layers outImage<-"classified.tif" #then extract the training values train<-extract(ra

Re: [R-sig-Geo] plotKML and time stamp

2012-10-03 Thread Tomislav Hengl
try: > library(plotKML) > data(HRtemp08) # format the time column: > HRtemp08$ctime <- as.POSIXct(HRtemp08$DATE, format="%Y-%m-%dT%H:%M:%SZ") ## Not run: # create a STIDF object: > library(spacetime) > sp <- SpatialPoints(HRtemp08[,c("Lon","Lat")]) > proj4string(sp) <- CRS("+proj=longlat +datum=

Re: [R-sig-Geo] plotKML tutorials for creating a times series from rasters?

2012-10-03 Thread Tomislav Hengl
On 03/10/2012 00:17, nikos ves wrote: An update : After some experiments, I have created a rasterbrick with 55 layers. ( By stitching 55 geotif's into a vrt using gdal [$gdalbuildvrt -separate -o tmp.vrt *.tif]) mBrick = brick("/path/to/vrt") Afterwards when I was trying to create the ts

Re: [R-sig-Geo] plotKML tutorials for creating a times series from rasters?

2012-10-03 Thread Tomislav Hengl
On 02/10/2012 21:21, nikos ves wrote: Hi list, I was browsing the list and I found out about plotKML. It seems a nice way to present your data, or do a visual inspection. I tried to create a timeseries visualization from an environmental index Im studying at the moment (55 geotiffs ~35 MB ea