[R-sig-Geo] Polygon Data into Grid Structure
Roger Bivand
Roger@B|v@nd @end|ng |rom nhh@no
Mon May 2 20:26:44 CEST 2022
On Mon, 2 May 2022, lucfrank using mail.uni-mannheim.de wrote:
> Hello everyone,
>
> I have the Aqueduct 3.0 Data from the WRI Institut which is in Multipolygon
> format.
This is not clear, neither aqueduct nor WRI mean anything to me and
possibly most others.
>
> 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.
>
So a standard intersection between a raster grid and polygons - but you
are modifying the support of the data quite brutally. If you need to
integrate data with varying support, do not treat the estimated values for
the new entities as fixed, they are estimates with error distributions.
Why not simply count the points within each polygon?
>
> 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)
Not a robust idea; build up your analysis from the support of your own
data based on robust sources.
>
> # -25,-49 my lower left corner (these are coordinates)
> grid <- GridTopology(c(-25,-49),c(1, 1), c(72, 48))
>
>
This looks rather odd, seeming to use geographical coordinates, so the
areas in the grid cells vary with latitude (as would the counts).
> gridpoints <- SpatialPoints(grid, proj4string = CRS(projection(aqua)))
> plot(gridpoints)
>
> cropped_gridpoints <- crop(gridpoints, aqua)
> plot(cropped_gridpoints)
>
crop is from terra (in older workflows raster), not sp. Perhaps using
terra for the whole exercise is advisable? Your workflow template doesn't
seem to be current, or even adequate, I'm afraid.
Roger
> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&data=05%7C01%7CRoger.Bivand%40nhh.no%7C14ec72decd7e4b5697e508da2c5804a2%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C637871053949019828%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=E5%2BzJh28dpHvmZxA0Ui9M7bL3dBFEcketbVX42AdswI%3D&reserved=0
>
--
Roger Bivand
Emeritus Professor
Department of Economics, Norwegian School of Economics,
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway.
e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
More information about the R-sig-Geo
mailing list