mercredi 3 mars 2021

how to randomly show a high number of points in an area in R

I am trying to collect random sample points from an area (polygons) to later cross-check information from these points in a raster. However, sometimes I need a high number of points. When I try to run my code, R returns an error.

I used this code, which worked great for small numbers.

#create a set of random point samples

library(raster)
library(sp)
r_sample <- spsample(my_shp, n= 212183, type='random') 

#cross and extract raster information based on previously generated points
 
extrc <- raster::extract(my_raster, r_sample, small=T, na.rm=F) #extrair as quantidades de pixels 

error

> r_sample <- spsample(controle, n= 212183 , type='random')
> Error: Unable to allocate vector of size 1.9 Gb



Aucun commentaire:

Enregistrer un commentaire