Я извлекаю данные из растра, используя функцию raster::extract
и SpatialPointsDataFrame
в качестве шаблона.
Я использую future_lapply, чтобы сделать это параллельно.Приведенный ниже репекс работает отлично и дает ожидаемые результаты на моем локальном Mac, но при экспорте его на компьютер с вдовами с большим количеством ядер происходит сбой при
Error in as(from, "Spatial") :
no method or default for coercing "sf" to "Spatial"
, кажется, что метод каким-то образом не экспортируется правильнона окнах?
library(tibble)
library(dplyr)
library(sf)
library(raster)
library(future.apply)
# make raster
ras <- raster(ncol=25, nrow=25, xmn=0, xmx=25, ymn=0, ymx=25)
ras[]=seq(1,ncell(ras),1)
crs(ras) <- "+proj=utm +zone=51 ellps=WGS84"
# make SpatialPointsDataFrame with 10 "maps" à 3 points
coords <- matrix(sample(5:20,6*10,replace = TRUE), ncol = 2, byrow = TRUE)
data <- tibble(maps = rep(paste("map", c(1:10), sep = ""), each = 3),
points = rep(paste("p", c(1:3)), 10))
spdf <- SpatialPointsDataFrame(coords = coords,
data = data,
proj4string = CRS("+proj=utm +zone=51 ellps=WGS84")) %>%
st_as_sf()
# extract data for points in each map from raster
maps <- unique(spdf$maps)
plan(multiprocess)
future_lapply(maps, function(x) {
filter(spdf, maps == x) %>%
raster::extract(x = ras, y = .)
})
plan(cluster)
работает, но, глядя на диспетчер задач, он не создает несколько процессов, а работает на одном ядре
Mac:
> session_info()
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────────
setting value
version R version 3.5.3 (2019-03-11)
os macOS Mojave 10.14
system x86_64, darwin15.6.0
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/Stockholm
date 2019-09-25
─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.5.2)
backports 1.1.4 2019-04-10 [1] CRAN (R 3.5.2)
class 7.3-15 2019-01-01 [1] CRAN (R 3.5.2)
classInt 0.3-1 2018-12-18 [1] CRAN (R 3.5.0)
cli 1.1.0 2019-03-19 [1] CRAN (R 3.5.2)
codetools 0.2-16 2018-12-24 [1] CRAN (R 3.5.2)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.0)
DBI 1.0.0 2018-05-02 [1] CRAN (R 3.5.0)
digest 0.6.19 2019-05-20 [1] CRAN (R 3.5.2)
dplyr * 0.8.0.1 2019-02-15 [1] CRAN (R 3.5.2)
e1071 1.7-1 2019-03-19 [1] CRAN (R 3.5.2)
fansi 0.4.0 2018-10-05 [1] CRAN (R 3.5.0)
future * 1.12.0 2019-03-08 [1] CRAN (R 3.5.2)
future.apply * 1.2.0 2019-03-07 [1] CRAN (R 3.5.2)
globals 0.12.4 2018-10-11 [1] CRAN (R 3.5.0)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.5.2)
lattice 0.20-38 2018-11-04 [1] CRAN (R 3.5.0)
listenv 0.7.0 2018-01-21 [1] CRAN (R 3.5.0)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.0)
pillar 1.4.1 2019-05-28 [1] CRAN (R 3.5.2)
pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.5.0)
purrr 0.3.2 2019-03-15 [1] CRAN (R 3.5.2)
R6 2.4.0 2019-02-14 [1] CRAN (R 3.5.2)
raster * 2.8-19 2019-01-30 [1] CRAN (R 3.5.2)
Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.5.2)
rgdal 1.4-3 2019-03-14 [1] CRAN (R 3.5.2)
rlang 0.3.4 2019-04-07 [1] CRAN (R 3.5.2)
rstudioapi 0.10 2019-03-19 [1] CRAN (R 3.5.2)
sessioninfo * 1.1.1 2018-11-05 [1] CRAN (R 3.5.0)
sf * 0.7-3 2019-02-21 [1] CRAN (R 3.5.2)
sp * 1.3-1 2018-06-05 [1] CRAN (R 3.5.0)
tibble * 2.1.3 2019-06-06 [1] CRAN (R 3.5.2)
tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.5.0)
units 0.6-2 2018-12-05 [1] CRAN (R 3.5.0)
utf8 1.1.4 2018-05-24 [1] CRAN (R 3.5.0)
vctrs 0.1.0 2018-11-29 [1] CRAN (R 3.5.0)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.0)
yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.0)
zeallot 0.1.0 2018-01-28 [1] CRAN (R 3.5.0)
Windows:
> session_info()
- Session info --------------------------------------------------------------------------------------------------------
setting value
version R version 3.6.0 (2019-04-26)
os Windows 10 x64
system x86_64, mingw32
ui RStudio
language (EN)
collate English_Germany.1252
ctype English_Germany.1252
tz Europe/Berlin
date 2019-09-25
- Packages ------------------------------------------------------------------------------------------------------------
package * version date lib source
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
class 7.3-15 2019-01-01 [2] CRAN (R 3.6.0)
classInt 0.3-3 2019-04-26 [1] CRAN (R 3.6.0)
cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.0)
codetools 0.2-16 2018-12-24 [2] CRAN (R 3.6.0)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)
DBI 1.0.0 2018-05-02 [1] CRAN (R 3.6.0)
digest 0.6.19 2019-05-20 [1] CRAN (R 3.6.0)
dplyr * 0.8.1 2019-05-14 [1] CRAN (R 3.6.0)
e1071 1.7-1 2019-03-19 [1] CRAN (R 3.6.0)
future * 1.13.0 2019-05-08 [1] CRAN (R 3.6.0)
future.apply * 1.2.0 2019-03-07 [1] CRAN (R 3.6.0)
globals 0.12.4 2018-10-11 [1] CRAN (R 3.6.0)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0)
KernSmooth 2.23-15 2015-06-29 [2] CRAN (R 3.6.0)
lattice 0.20-38 2018-11-04 [2] CRAN (R 3.6.0)
listenv 0.7.0 2018-01-21 [1] CRAN (R 3.6.0)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
pillar 1.4.1 2019-05-28 [1] CRAN (R 3.6.0)
pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.6.0)
purrr 0.3.2 2019-03-15 [1] CRAN (R 3.6.0)
R6 2.4.0 2019-02-14 [1] CRAN (R 3.6.0)
raster * 2.9-5 2019-05-14 [1] CRAN (R 3.6.0)
Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.6.0)
rgdal 1.4-3 2019-03-14 [1] CRAN (R 3.6.0)
rlang 0.3.4 2019-04-07 [1] CRAN (R 3.6.0)
sessioninfo * 1.1.1 2018-11-05 [1] CRAN (R 3.6.1)
sf * 0.7-4 2019-04-25 [1] CRAN (R 3.6.0)
sp * 1.3-1 2018-06-05 [1] CRAN (R 3.6.0)
tibble 2.1.1 2019-03-16 [1] CRAN (R 3.6.0)
tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.6.0)
units 0.6-3 2019-05-03 [1] CRAN (R 3.6.0)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)