我正在使用rasterio将点的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)代码不仅将固定值写入栅格,还将基于要转换的点的值写入栅格。
问题是每个光栅像素有很多点。使用上面的方法,只有一个点值被烧录到像素上。我正在寻找的是每个像素的所有点值的平均值烧录到给定的像素。
谢谢你的帮忙
发布于 2020-06-22 17:06:33
我找到了一些想法去做:
首先,我们将所有的点按像素排序到字典中。然后我们计算所需的值,在本例中是该像素中所有点的平均值。现在我们用像素的坐标将这个值赋给一个新的点,并使用它来代替旧的点。
https://stackoverflow.com/questions/62472750
复制相似问题