如何解决在没有无数据值的大叶地图上显示卫星数据
通过使用下面的代码,我试图在大叶地图上绘制/显示 .tif 文件(特定波段或 NCC 图像):
import rasterio as rio
import folium
from pyproj import Transformer
## LC08 RGB Image or particular Band Image
in_path = 'RGB.tif' or 'Band 1.tif'
dst_crs = 'EPSG:4326'
with rio.open(in_path) as src:
img = src.read()
src_crs = src.crs['init'].upper()
min_lon,min_lat,max_lon,max_lat = src.bounds
## Conversion from UTM to WGS84 CRS
bounds_orig = [[min_lat,min_lon],[max_lat,max_lon]]
bounds_fin = []
for item in bounds_orig:
#converting to lat/lon
lat = item[0]
lon = item[1]
proj = Transformer.from_crs(int(src_crs.split(":")[1]),int(dst_crs.split(":")[1]),always_xy=True)
lon_n,lat_n = proj.transform(lon,lat)
bounds_fin.append([lat_n,lon_n])
# Finding the centre latitude & longitude
centre_lon = bounds_fin[0][1] + (bounds_fin[1][1] - bounds_fin[0][1])/2
centre_lat = bounds_fin[0][0] + (bounds_fin[1][0] - bounds_fin[0][0])/2
m = folium.Map(location=[centre_lat,centre_lon],tiles='Stamen Terrain',zoom_start = 10)
# Overlay raster using add_child() function
m.add_child(folium.raster_layers.ImageOverlay(img.transpose(1,2,0),opacity=.7,bounds = bounds_fin))
# Display map
m
运行上述代码后,我得到以下输出:
如上图/输出附件所示,tiff 文件中的 nodata 值用黑色表示。
我还尝试将原始 tif 文件中表示为 0 的 nodata 值转换为 np.nan,然后绘制修改后的图像,但仍然得到与上述相同的结果。
有人可以帮助我在大叶地图上显示栅格时如何删除这些无数据值或使它们空心。
解决方法
试试以下方法:
with rio.open(geotiff_geo) as src:
boundary = src.bounds
img = src.read(1)
nodata = src.nodata
img[img==nodata] = np.nan
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。