There are two approaches: vector-based and raster-based. The former is more accurate, and the later is generally faster but much more complicated.
Vector approach
Use the fraction of area overlap between each polygon and grid cell to weight the values. Say you have a grid
(e.g. created this way), and an irregular poly
with values in val
. To determine val
on grid
:
SELECT g.gid, g.row, g.col, count(distinct p.gid) as num_poly,
sum(ST_Area(ST_Intersection(g.geom, p.geom)) / ST_Area(g.geom) * p.val) AS grid_val
FROM grid g
LEFT JOIN poly p ON ST_Intersects(g.geom, p.geom)
GROUP BY g.gid, g.row, g.col;
This query will take a while there are many tens of thousands of grid
cells (i.e. 100 × 100, or more).
Raster approach
The idea behind this method is if you rasterise values from an irregular polygon, you get the values. However, the rasterisation methods are limited, as they don't consider the area fraction of polygons within each pixel. So you will need to modify this approach by rasterising at a finer resolution than desired, then generalise the refined raster to the desired resolution. The accuracy of this method increases with a finer initial raster resolution.
I can add more details to this method, but it is much more complicated. I did this approach first with gdal_rasterize with files in a shell, then I moved the logic to GDAL/Python using gdal.RasterizeLayer.
If you mean by fishnet grid a regular spatial grid, there are several options available in R:
- Simply use a matrix.
- Use the SpatialGrid/Pixels classes from the sp package
- Use the raster format from the raster package.
A good overview of spatial packages in R is given on the CRAN Spatial Task View.
Best Answer
If you use ArcGIS and need to transfer the values of features of one layer (your study data) to another layer (fishnet grid polygons), consider using the Spatial Join geoprocessing tool.