Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x y
- 4001758 3138416
- 3990685 3088576
- 4002641 3078682
- 3946723 3153793
- 3975356 2974350
- 4001284 3137528
- 3946723 3153793
- 3946723 3153793
- 4000195 3103181
- 4000168 3103446
- 3969985 3104761
- 3905824 3107504
- test_extractcropland<-extract(cropland,df_coord)
- library(raster)
- r <- raster(ncol=36, nrow=18)
- r[] <- 1:ncell(r)
- xy <- cbind(-50, seq(-80, 80, by=20))
- extract(r, xy)
- ## [1] 626 554 482 410 338 266 194 122 50
- extract(r, SpatialPoints(xy), sp = T)
- ## class : SpatialPointsDataFrame
- ## features : 9
- ## extent : -50, -50, -80, 80 (xmin, xmax, ymin, ymax)
- ## coord. ref. : NA
- ## variables : 1
- ## names : layer
- ## min values : 50
- ## max values : 626
- xy <- data.frame(xy)
- names(xy) <- c('x','y')
- cbind(extract(r, xy, df = T),xy)
- ## ID layer x y
- ## 1 1 626 -50 -80
- ## 2 2 554 -50 -60
- ## 3 3 482 -50 -40
- ## 4 4 410 -50 -20
- ## 5 5 338 -50 0
- ## 6 6 266 -50 20
- ## 7 7 194 -50 40
- ## 8 8 122 -50 60
- ## 9 9 50 -50 80
- result <- extract(r, xy, cellnumbers = T)
- coordinates(r)[result[,2],]
- ## x y
- ## [1,] -45 -85
- ## [2,] -45 -65
- ## [3,] -45 -45
- ## [4,] -45 -25
- ## [5,] -45 -5
- ## [6,] -45 15
- ## [7,] -45 35
- ## [8,] -45 55
- ## [9,] -45 75
- cbind(result,coordinates(r)[result[,2],])
- ## cells layer x y
- ## [1,] 626 626 -45 -85
- ## [2,] 554 554 -45 -65
- ## [3,] 482 482 -45 -45
- ## [4,] 410 410 -45 -25
- ## [5,] 338 338 -45 -5
- ## [6,] 266 266 -45 15
- ## [7,] 194 194 -45 35
- ## [8,] 122 122 -45 55
- ## [9,] 50 50 -45 75
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement