python - 用 shapefile 屏蔽 nc 文件并将其保存为 nc 格式
问题描述
所以我有 netCDF 文件,想用形状文件掩盖它。我在下面的代码可以完成这项工作,但结果是 GTiff 格式。关于如何修改代码以将其保存为 netCDF 格式的任何建议?
import fiona
import rasterio
import rasterio.mask
import netCDF4 as nc
import numpy as np
from rasterio.plot import show
with fiona.open('/shape_file/scandinavia_shp.shp', "r") as shapefile:
shapes = [feature["geometry"] for feature in shapefile]
with rasterio.open('/input/data1.nc') as src:
out_image, out_transform = rasterio.mask.mask(src, shapes, crop=True)
out_meta = src.meta
out_meta.update({"driver": "GTiff",
"height": out_image.shape[1],
"width": out_image.shape[2],
"transform": out_transform})
with rasterio.open('/output/data2.tiff', "w", **out_meta) as dest:
dest.write(out_image)
解决方案
推荐阅读
- django - 如何使用 for 循环在 html django 模板中增加值(按下按钮)?
- ansible - Ansible playbook select list by extra var
- jquery - Jquery 菜单将徽标不透明度切换为零
- laravel - Laravel Vue分页没有获取第二页
- javascript - 在将其添加到 DOM 之前,是否可以在 javascript 中保存对克隆的 html 模板元素的引用?
- javascript - 映射对象数组
- pgadmin-4 - 在 pgadmin4 中导出连接
- angular - 使用打字稿为角度应用程序创建模拟数据对象
- java - 在 Kafka 消费者配置中设置 max.poll.interval.ms 大于 request.timeout.ms 有什么负面影响
- haskell - 'DoSomething String' 的非法实例声明