如何栅格化每像素具有多个点的熊猫数据帧?



我正在使用栅格将点的geopandas数据帧转换为geotif栅格。 为此,我正在使用此python代码:

with rasterio.open("somepath/rasterized.tif", 'w+', **meta) as out:
out.nodata = 0
out_arr = out.read(1)
# this is where we create a generator of geom, value pairs to use in rasterizing
shapes = ((geom, value * 2) for geom, value in zip(gdf.geometry, gdf["PositionConfidence"]))
burned = features.rasterize(shapes=shapes, fill=0, out=out_arr, transform=out.transform)
out.write_band(1, burned)
out.write_band(2, burned)
out.write_band(3, burned)
out_arr1 = out.read(1)

该代码不仅将固定值写入栅格,还写入基于要转换的点的值。

问题是每个栅格像素有很多点。使用上述方法,仅将单个点值刻录到像素。 我正在寻找的是将每个像素的所有点值的平均值刻录到给定的像素。

感谢您的帮助

我找到了一些想法来做到这一点:

首先,我们将所有点按像素排序到字典中。然后,我们计算该像素中所有点所需的值,在本例中为某个值的平均值。现在,我们将此值分配给具有像素坐标的新点,并使用该值代替旧点。

最新更新