我尝试将两个光栅(raster1和raster2)相乘,然后使用相乘的结果写入光栅。
我可以使用python中的rasterio包读取输入光栅,但我很难将输出光栅写入文件。
我哪里做错了?
rasterio version 1.3.8
Python 3.10.8
The meta data for the input rasters are:
raster1:
Name JRC_forest_yield_upsampled_to_1km
Path C:\Users\Input_datasets\Forest_Biomass_Map\JRC_forest_yield_upsampled_to_1km.tif
Extent 900000.0000000000000000,900000.0000000000000000 : 7400000.0000000000000000,5416000.0000000000000000
Width 6500
Height 4516
Data type Float64 - Sixty four bit floating point
GDAL Driver Description GTiff
GDAL Driver Metadata GeoTIFF
Compression LZW
CRS EPSG:3035 - ETRS89-extended / LAEA Europe
raster2:
Name eu_nuts0_for_rents_prices_rast
Path C:\Users\Throughput_datasets\eu_nuts0_for_rents_prices_rast.tif
Extent 900000.0000000000000000,900000.0000000000000000 : 7400000.0000000000000000,5416000.0000000000000000
Width 6500
Height 4516
Data type Float32 - Thirty two bit floating point
GDAL Driver Description GTiff
GDAL Driver Metadata GeoTIFF
Compression (blank in QGIS)
CRS EPSG:3035 - ETRS89-extended / LAEA Europe
字符串
错误代码:
(.venv) C:\Users\spencerd\Documents> raster_calculator.py
c:\Users\spencerd\Documents\.venv\lib\site-packages\rasterio\__init__.py:329: NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix will be returned.
dataset = writer(
型
脚本:
import rasterio
from rasterio import features
from rasterio.enums import MergeAlg
from rasterio.plot import show
from numpy import int16
# Paths to the input raster files
raster1_path = 'C:/Users/Spatial datasets/EULandClass/EU_landSystem.tif'
raster_woody_path = 'C:/Users/Spatial datasets/European countries/Input_datasets/Forest_Biomass_Map/JRC_forest_yield_upsampled_to_1km.tif'
raster2_path = 'C:/Users/Throughput_datasets/eu_nuts0_for_rents_prices_rast.tif'
# Open the input raster files and plot
rast1 = rasterio.open(raster_woody_path).read()
rast2 = rasterio.open(raster2_path).read()
result = rast1 * rast2
result
# define output file path and parameters
output_path = "C:/Users/Throughput_datasets/eu_forestry_monetary_yields_unmasked.tif"
# Write the result to a new raster file
with rasterio.open(output_path,
'w',
width=6500,
height=4516,
count=1,
crs='epsg:3050',
dtype='float32',
nodata=-0,
driver='GTiff',
transform= None) as dst:
dst.write(result)
型
从这段代码中,我想将结果光栅“result”保存到文件路径“output_path”,但我只是得到一个错误,我需要做什么不同的事情?
1条答案
按热度按时间n3ipq98p1#
最简单的方法是从一个用作源的栅格中获取所需的参数(包括宽度,高度,crs等)。
按以下方式编辑最后一段代码:
字符串