【发布时间】:2020-11-18 18:12:10
【问题描述】:
我正在尝试从 tif 文件中获取点的高程。我只想要使用纬度和经度搜索时提供的值。如何只获取DataArray的array(451.13458, dtype=float32)中的451.13458。
xarr = xr.open_rasterio('/content/DEMs/dem1.tif')
# Slice one of the bands
img = xarr[0, :, :]
#Use the .sel() method to retrieve the value of the nearest cell close to your POI
val = img.sel(x=lon1, y=lat1, method="nearest")
print("This is val: ", val)
>>This is val: <xarray.DataArray ()>
array(451.13458, dtype=float32)
Coordinates:
band int64 1
y float64 -32.32
x float64 18.82
Attributes:
transform: (6.615572650436456e-07, 0.0, 18.81609000062383, 0.0, -6.6...
crs: +init=epsg:4326
res: (6.615572650436456e-07, 6.615572650436456e-07)
is_tiled: 0
nodatavals: (-32767.0,)
scales: (1.0,)
offsets: (0.0,)
units: ('metre',)
AREA_OR_POINT: Area
【问题讨论】:
标签: python pandas numpy python-xarray