How to create a spatial point grid

library(reshape2) library(data.table) library(dplyr) library(magrittr) library(ggplot2) library(scales) library(gstat) library(DescTools) library(sp) #I want a colorado grid# data("colorado.grid") #making cordinates into spatial points dataframe# coordinates(Gold_tracer_kri) <- ~ long_orig + lat_orig #attempt at kriging but no grid# lzn.kriged <- krige(Au ~ 1, Gold_tracer_kri, colorado.grid, model=lzn.fit) lzn.kriged %>% as.data.frame %>% ggplot(aes(long_orig=long_orig, lat_orig=lat_orig)) + geom_tile(aes(fill=var1.pred)) + coord_equal() + scale_fill_gradient(low = "yellow", high="red") + scale_x_continuous(labels=comma) + scale_y_continuous(labels=comma) + theme_bw() 

load spatial domain for interpolation by

 data("meuse.grid") 

I am trying to use kriging methods in R, but I am stuck because I could not find a grid for my data. My data covers all US states in Colorado, and I would like to get a grid to transfer my data. Like meuse.grid, which is used in the following example.

Any help would be appreciated

+5
source share
1 answer

you can create a grid using sp::makegrid

 library(sp) library(rgdal) library(raster) # load some spatial data. Administrative Boundary us <- getData('GADM', country = 'US', level = 1) us$NAME_1 colorado <- us[us$NAME_1 == "Colorado",] # check the CRS to know which map units are used proj4string(colorado) # "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" # Create a grid of points within the bbox of the SpatialPolygonsDataFrame # colorado with decimal degrees as map units grid <- makegrid(colorado, cellsize = 0.1) # cellsize in map units! # grid is a data.frame. To change it to a spatial data set we have to grid <- SpatialPoints(grid, proj4string = CRS(proj4string(colorado))) plot(colorado) plot(grid, pch = ".", add = T) 

Example with Colorado

And one more example with Austria (GADM code 'AUT' ). Example with Austria

Grid points only inside the polygon:

To extract only points inside the polygon, use `[` for a subset of points based on the following location:

 grid <- grid[colorado, ] 
+7
source

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


All Articles