如何在Python中光栅化矢量数据(线)并沿线插值?

问题描述 投票:0回答:1

我想光栅化线向量。栅格值必须在“起始”值和“终止”值之间进行插值。

示例如下。我想栅格化 GeoDataFrame 中的线,并且栅格的值应该从 5 到 2(插值)。

import geopandas as gpd
from shapely.geometry import LineString

# example line
line = LineString([(10.00, 20.00), (20.00, 50.00)])
line_gdf = gpd.GeoDataFrame([line], geometry=[line])
line_gdf['from'] = 5
line_gdf['to'] = 2

预期结果是这样的: example raster

该线呈黑色可见。栅格应该仅具有穿过像元的线的值。这些值应从“起始值”插值到“终止值”,如示例栅格所示(标有红色轮廓的单元格)。最好是

DataArray
(
xarray
)。

python geopandas python-xarray shapely rasterizing
1个回答
0
投票

需要使用Bresenham算法: https://en.wikipedia.org/wiki/Bresenham_line_algorithm

您可以在这里找到 Python 实现: https://pypi.org/project/bresenham/

© www.soinside.com 2019 - 2024. All rights reserved.