[R-sig-Geo] Polygon Data into Grid Structure

iucir@@k m@iii@g oii m@ii@u@i-m@@@heim@de iucir@@k m@iii@g oii m@ii@u@i-m@@@heim@de
Mon May 2 18:21:46 CEST 2022


Hello everyone,

I have the Aqueduct 3.0 Data from the WRI Institut which is in  
Multipolygon format.

To perform a regression analysis with different datasets I want to  
transform these polygons into a grid.
Basically, I want to overlay a grid over the map and assign each cell  
the value of the underlying polygon.
In a second step, I want to count how many points (different dataset)  
are inside each cell.


I have tried with the sp commands GridTopology, and SpatialPoints. I  
can produce the grid but fail to crop with my map.
Also, it is not clear to me how I can assign the underlying value of  
the polygon.

This is the code I have tried so far:
(I have copied this from doing a Course on DataCamp which I can't  
completely copy exactly because my data is different)

# -25,-49  my lower left corner (these are coordinates)
grid <- GridTopology(c(-25,-49),c(1, 1), c(72, 48))


gridpoints <- SpatialPoints(grid, proj4string = CRS(projection(aqua)))
plot(gridpoints)

cropped_gridpoints <- crop(gridpoints, aqua)
plot(cropped_gridpoints)

spgrid <- SpatialPixels(cropped_gridpoints)
plot(spgrid)


I hope someone has an idea to help me solve this.
Thanks to everyone who has any insights into this

Luca Frank



More information about the R-sig-Geo mailing list