-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_remote_c_make_rasters.R
More file actions
33 lines (27 loc) · 1.1 KB
/
Copy path02_remote_c_make_rasters.R
File metadata and controls
33 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## 02_remote_c_make_rasters.R
print("this is Increasing occurrence raster making script")
sp <- sp[order(sp$species, decreasing = FALSE),]
## create occurrence rasters for each species, based on AFE irregular 50km2 occurrence grid, rasterised onto approx 1km2 regular raster
rast_list <- list()
print(Sys.time())
for (i in unique(sp$species)){
if(!file.exists(paste("occ_rasters/occ", i, ".tif", sep = ""))) {
s <- sp[sp$species == i,]
print(i)
sp2 <- SpatialPointsDataFrame(s[,c("x", "y")],
as.data.frame(s[,3]),
proj4string = temp@crs)
print("get polygons")
poly_list <- over(SpatialPolygons(grid@polygons), SpatialPoints(sp2))
gc()
print("subset grid")
poly_occ <- grid[which(!is.na(poly_list)),]
gc()
print("rasterise occurrence")
rast <- rasterize(poly_occ, temp, field = 1)
gc()
if(!file.exists(paste("occ_rasters/occ", i, ".tif", sep = ""))) {
writeRaster(rast, paste("occ_rasters/occ", i, ".tif", sep = ""))}
print("occurrence raster saved")
gc() } }
print("end")