Rasterio的光栅化函数生成一个空白的imag

2024-09-24 22:27:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用rasterio rasterize function光栅化一个shapefile(带有属性)。为此,我编写了以下代码:

new_dataset = rasterio.open('example.tif', 'w', driver='GTiff',
                            height = arr.shape[0], width = arr.shape[1],
                            count=1,
                            dtype=rasterio.float64,
                            crs=31370,transform=transform)

shapeee = fiona.open(shapefile)
geom_fiona = [shapes['geometry'] for shapes in shapeee]
attrib_fiona = [shapes['properties']['OBJECTID'] for shapes in shapeee]
tuples = []

for i in range(0,len(geom_fiona)-1,1):
    tuples.append([geom_fiona[i],attrib_fiona[i]])

burned = features.rasterize(tuples, out_shape = new_dataset.shape, default_value = -99, dtype = rasterio.float64, fill=-99)

print(np.max(burned))

注意,几何体是有效的,因为我用features.is_valid_geom(geom_fiona[0])测试它,它返回true。你知道吗

print(np.max(burned))的输出返回-99,这意味着光栅化失败。你知道吗

我发现this question和我的问题是同一个问题,答案似乎是一个有不同预测的问题。我用菲奥娜的“META”方法打印了关于CsFeFLE和光栅的“CRS”的信息,我得到了相同的结果:^ {< CD4}}为光栅和^ {CD5}},所以问题似乎是另一回事……你知道吗

你知道吗?你知道吗


Tags: innewfor光栅datasetshapefileshapefiona