我正在尝试光栅化简单的Point&使用Python GDAL的线几何,我无法执行它。例如我在json文件中以Lat-Lon格式得到以下3点。
[2.19326073965,49.049766213940003],[2.19289443625,49.049622431300001],[2.19271641965,49.049547116589999]
在栅格化此GeoJSON文件后创建tif文件的步骤是什么?我找到了各种文章,但无法理解并尝试了以下代码,但生成的tif文件是黑色的。
pixel_size = 1.0
NoData_value = 100
# Filename of input OGR file
vector_fn = 'point_out.geojson'
# Filename of the raster Tiff that will be created
raster_fn = 'test.tif'
# Open the data source and read in the extent
source_ds = ogr.Open(vector_fn)
source_layer = source_ds.GetLayer()
x_min, x_max, y_min, y_max = source_layer.GetExtent()
print x_min, x_max, y_min, y_max
# Create the destination data source
x_res = int((x_max - x_min) / pixel_size)
y_res = int((y_max - y_min) / pixel_size)
print x_res, y_res
target_ds = gdal.GetDriverByName('GTiff').Create(raster_fn, 1300, 1300, 1, gdal.GDT_Byte)
target_ds.SetGeoTransform([1, pixel_size, 0, 1, 0, -pixel_size])
band = target_ds.GetRasterBand(1)
band.SetNoDataValue(NoData_value)
# Rasterize
gdal.RasterizeLayer(target_ds, [1], source_layer, burn_values=[128])