Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. x y
  2. 4001758 3138416
  3. 3990685 3088576
  4. 4002641 3078682
  5. 3946723 3153793
  6. 3975356 2974350
  7. 4001284 3137528
  8. 3946723 3153793
  9. 3946723 3153793
  10. 4000195 3103181
  11. 4000168 3103446
  12. 3969985 3104761
  13. 3905824 3107504
  14.  
  15. test_extractcropland<-extract(cropland,df_coord)
  16.  
  17. library(raster)
  18.  
  19. r <- raster(ncol=36, nrow=18)
  20. r[] <- 1:ncell(r)
  21.  
  22. xy <- cbind(-50, seq(-80, 80, by=20))
  23. extract(r, xy)
  24. ## [1] 626 554 482 410 338 266 194 122 50
  25.  
  26. extract(r, SpatialPoints(xy), sp = T)
  27. ## class : SpatialPointsDataFrame
  28. ## features : 9
  29. ## extent : -50, -50, -80, 80 (xmin, xmax, ymin, ymax)
  30. ## coord. ref. : NA
  31. ## variables : 1
  32. ## names : layer
  33. ## min values : 50
  34. ## max values : 626
  35.  
  36. xy <- data.frame(xy)
  37. names(xy) <- c('x','y')
  38. cbind(extract(r, xy, df = T),xy)
  39. ## ID layer x y
  40. ## 1 1 626 -50 -80
  41. ## 2 2 554 -50 -60
  42. ## 3 3 482 -50 -40
  43. ## 4 4 410 -50 -20
  44. ## 5 5 338 -50 0
  45. ## 6 6 266 -50 20
  46. ## 7 7 194 -50 40
  47. ## 8 8 122 -50 60
  48. ## 9 9 50 -50 80
  49.  
  50. result <- extract(r, xy, cellnumbers = T)
  51.  
  52. coordinates(r)[result[,2],]
  53. ## x y
  54. ## [1,] -45 -85
  55. ## [2,] -45 -65
  56. ## [3,] -45 -45
  57. ## [4,] -45 -25
  58. ## [5,] -45 -5
  59. ## [6,] -45 15
  60. ## [7,] -45 35
  61. ## [8,] -45 55
  62. ## [9,] -45 75
  63.  
  64. cbind(result,coordinates(r)[result[,2],])
  65. ## cells layer x y
  66. ## [1,] 626 626 -45 -85
  67. ## [2,] 554 554 -45 -65
  68. ## [3,] 482 482 -45 -45
  69. ## [4,] 410 410 -45 -25
  70. ## [5,] 338 338 -45 -5
  71. ## [6,] 266 266 -45 15
  72. ## [7,] 194 194 -45 35
  73. ## [8,] 122 122 -45 55
  74. ## [9,] 50 50 -45 75
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement