Я создал сетку, используя этот код, сетка, которую он создает поверх карты портов:
# load some spatial data. Administrative Boundary
porto <- getData('GADM', country = 'Portugal', level = 2)
porto$NAME_1
porto <- porto[porto$NAME_2 == "Porto",]
# check the CRS to know which map units are used
proj4string(porto)
# "+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(porto, cellsize = 0.003) # 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(porto)))
portoWithin <-
SpatialPixels(grid, proj4string = CRS(proj4string(porto)))
#### Converting the GRID to a Raster
ras_portoWithin <- raster(portoWithin)
plot(porto)
plot(portoWithin, add = T)
Теперь я хочу вставить SpatialPonits в сетку, чтобы я мог дискретизировать данные. В результате в каждой ячейке сетки будет видно, сколько точек есть, чтобы работать с ячейками, а не с точками.
Набор данных data - это пространственные точки, соответствующие координатам GPS:
[,1] [,2]
[1,] -8.574678 41.15195
[2,] -8.574705 41.15194
[3,] -8.574696 41.15193
[4,] -8.574660 41.15196
[5,] -8.574723 41.15193
[6,] -8.574714 41.15192