Linear buffer when extracting from a raster file in R -


this might 1 gis.stackexchange - i'm working raster data, , attempting extract values. problem i'm running coordinates not overlap raster data (i have coordinates on coastline, , pixels wee bit offshore). can use buffer, but, results inappropriate, buffer radius might, say, cause extract cross headland, getting data pixels have no relationship gps coordinates i'm interested in.

rather, i'd create way buffer directly east or west (or in cases north/south) - extract value in first pixel on straight line coordinates have.

consider following:

library(raster) set.seed(pi) # example data r <- raster(ncol=36, nrow=18, crs='+proj=utm +zone=14 +datum=wgs84') r[] <- 1:ncell(r) r[sample(length(r), 250)] <- na  xy <- cbind(x=-50, y=-15)  plot(r) plot(spatialpoints(xy), add=t, pch=19) segments(-180, -15, 180, -15, lty=2) 

which generates

map

if extract buffer of say, 50 meters...

extract(r, xy, buffer=50) [[1]]  [1] 227 228 229 230  na 232  na  na 264 265  na 267 268 269 297 298 299  na  na  na 303  na 305 306 [25]  na 334 335 336 337 338 339  na 341 342  na  na 371  na  na  na  na 376 377  na 405 406 407  na [49]  na 410 411 412 413 414  na 442 443 444  na  na 447  na  na 450  na 479  na 481 482  na 484  na [73]  na 516 517 518  na 520 

(which, really, should still me na, buffer in meters...now i'm doubly confused - although not germane question)

how, then, extract first value west or east along dotted line, rather use circular buffer?

here approach

library(raster) set.seed(pi) r <- raster(ncol=36, nrow=18, crs='+proj=utm +zone=14 +datum=wgs84') r[] <- 1:ncell(r) r[sample(length(r), 250)] <- na xy <- cbind(x=-50, y=-15)  row <- rowfromy(r, xy[,2]) col <- colfromx(r, xy[,1])  left <- rev(na.omit(r[row, 1:col]))[1] right <- na.omit(r[row, col:ncol(r)])[1]  left ##[1] 371 right ##[1] 376 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -