How to create solid spatial pixels from a spatial point dataset

I have a spatial point DF spo (covering an irregularly shaped area). Data is not on a regular grid due to crs conversion.

My goal is a bitmap with a predetermined resolution and the length of the region of interest (more spatial point data should be displayed on this main raster).

Problems begin when I

 rasterize(spo, raster(ncol, nrow, extent, crs), spo$param) 

I need to configure nrow and ncol so that I don't get NA moire patterns within my area of ​​interest. I cannot use the predefined (higher) resolution, since rasterize does not have interpolation capabilities.

As a solution to this, I thought that I might need some kind of spatial pixel DF spi , which covers my entire area of ​​interest (like meuse.grid in library(raster); data(meuse.grid) ) and serves as the main grid. Then I can use it to interpolate my data, for example.

 idw(param~1,spo,spi) 

and thereby get full coverage of my area of ​​interest in my chosen resolution. But how to create a SpatialPixelsDataFrame from point data?

So, in my opinion, the question boils down to the following: How to create meuse.grid from the meuse dataset?

Maybe I am using the wrong approach here, so please let me know if it is easier to achieve what I need using a different method.

0
source share
1 answer

If you have a polygon that defines the border of the region of interest to you (what you need), then this is straightforward. One approach is to use the polygrid function from geoR , which in itself is a wrapper for SpatialPoints , expand.grid and overlay

Suppose you have a polygon that defines a region of interest called ROI

In this case, I will create one of meuse.grid

  data(meuse.grid) coordinates(meuse.grid) = ~x+y x <- chull( meuse.grid@coords ) borders <- meuse.grid@coords [c(x,x[1]),] ROI <- SpatialPolygons(list(Polygons(list(Polygon(borders)), ID = 'border'))) 

In fact, to use a polygrid you only need the coordinates of the polygon, which determine the area of ​​interest.

To create a 10 m grid covering the area of ​​this ROI, you can create a polygrid call

 # get the bounding box for ROI an convert to a list bboxROI <- apply(bbox(ROI), 1, as.list) # create a sequence from min(x) to max(x) in each dimension seqs <- lapply(bboxROI, function(x) seq(x$min, x$max, by= 10)) # rename to xgrid and ygrid names(seqs) <- c('xgrid','ygrid') thegrid <- do.call(polygrid,c(seqs, borders = list( ROI@polygons [[1]]@Polygons[[1]]@coords))) 
+1
source

Source: https://habr.com/ru/post/976122/


All Articles