I have create a grid using this code, the grid it is created over the port map:
# 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)
Now I want to insert SpatialPonits in the grid, so that I can discretize the data. The result would be to see in each grid cell how many points there are, to work with cells instead of with points.
The dataSet of points are SpatialPoints which correspond to GPS coordinates:
[,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