Skip to content
Prev 9816 / 29559 Next

Reassigning coordinates?

Hello Barry and Roger,

Thank you for the suggestions.
I got the nn2() function to work and took the coordinates of the nearest 
non-NA raster cell and assigned them to the points. I forgot to mention 
that I have raster cells that are non-NA and some that are not and my 
point lay in the NA zone (just barely). In this case, I set k=6 to get 
all surrounding raster cells (because some  of the nearest cells still 
have an NA value) that selected the coordinate set from the raster cell 
whose nn distance to the next non-na cell was minimal.
It was dirty but it worked.

Thanks for the help,

Brian

# Code
# rast.coords are a subset of relevant coodinates from the center of 
relevant raster cells. 'pc.na' is the xy-matrix of the coordinates 
needing reassigning.
near <- data.frame(nn2(rast.coords, pc.nan, k=6))
na.near.cell1 <- near$nn.idx.2
reassign.coords <- xyFromCell(pc.clime, cell=na.near.cell)
# Put them where they belong and voile.
On 11/2/2010 1:21 PM, Barry Rowlingson wrote: