ecohealthalliance / fasterize

High performance raster conversion for modern spatial data 🚀🌏▦
https://ecohealthalliance.github.io/fasterize/
Other
182 stars 15 forks source link

Error creating raster from sf object #35

Open FlukeAndFeather opened 4 years ago

FlukeAndFeather commented 4 years ago

I'm getting error Error in if (!is.na(projargs) && !nzchar(projargs)) projargs <- NA_character_ : missing value where TRUE/FALSE needed when running the sample code from the README

if(!dir.exists("Mammals_Terrestrial")) {
  download.file(
    "https://s3.amazonaws.com/hp3-shapefiles/Mammals_Terrestrial.zip",
    destfile = "Mammals_Terrestrial.zip") # <-- 383 MB
  unzip("Mammals_Terrestrial.zip", exdir = ".")
  unlink("Mammals_Terrestrial.zip")
}
mammal_shapes <- st_read("Mammals_Terrestrial")
mammal_raster <- raster(mammal_shapes, res = 1/6)

traceback() indicates the error is caused by CRS(attr(x[[attr(x, "sf_column")]], "crs")[["proj4string"]]). Sure enough, names(attr(mammal_shapes[[attr(mammal_shapes, "sf_column")]], "crs")) returns [1] "input" "wkt", there's no "proj4string".

Session info

> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils    
[5] datasets  methods   base     

other attached packages:
 [1] rnaturalearth_0.1.0 forcats_0.4.0      
 [3] stringr_1.4.0       dplyr_0.8.5        
 [5] purrr_0.3.4         readr_1.3.1        
 [7] tidyr_1.0.2         tibble_3.0.1       
 [9] ggplot2_3.3.0       tidyverse_1.3.0    
[11] stars_0.4-1         sf_0.9-3           
[13] abind_1.4-5         raster_3.0-12      
[15] sp_1.3-2           

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3         lubridate_1.7.4   
 [3] lattice_0.20-38    class_7.3-15      
 [5] digest_0.6.25      assertthat_0.2.1  
 [7] packrat_0.5.0      R6_2.4.1          
 [9] cellranger_1.1.0   backports_1.1.5   
[11] reprex_0.3.0       e1071_1.7-3       
[13] httr_1.4.1         pillar_1.4.3      
[15] rlang_0.4.5.9000   readxl_1.3.1      
[17] rstudioapi_0.11    labeling_0.3      
[19] rgdal_1.4-8        munsell_0.5.0     
[21] broom_0.5.4        compiler_3.6.2    
[23] modelr_0.1.5       pkgconfig_2.0.3   
[25] rgeos_0.5-3        tidyselect_1.0.0  
[27] codetools_0.2-16   fansi_0.4.1       
[29] crayon_1.3.4       dbplyr_1.4.2      
[31] withr_2.1.2        grid_3.6.2        
[33] fasterize_1.0.2    nlme_3.1-144      
[35] jsonlite_1.6.1     lwgeom_0.2-4      
[37] gtable_0.3.0       lifecycle_0.2.0   
[39] DBI_1.1.0          magrittr_1.5      
[41] units_0.6-5        scales_1.1.0      
[43] KernSmooth_2.23-16 cli_2.0.2         
[45] stringi_1.4.5      farver_2.0.3      
[47] fs_1.3.1           xml2_1.2.2        
[49] ellipsis_0.3.0     generics_0.0.2    
[51] vctrs_0.2.99.9011  tools_3.6.2       
[53] glue_1.4.0         hms_0.5.3         
[55] parallel_3.6.2     colorspace_1.4-1  
[57] classInt_0.4-2     rvest_0.3.5       
[59] haven_2.2.0    
FlukeAndFeather commented 4 years ago

According to https://www.r-spatial.org/r/2020/03/17/wkt.html#crs-objects-in-sf:

...this means that packages that hard-code for instance

x[["proj4string"]]

## NULL

now fail to get the result wanted

See raster-methods.R:22.