簡體   English   中英

如何在 XArray 的 DataArray 中獲取值

[英]How to get values in the DataArray of XArray

我正在嘗試從 tif 文件中獲取點的高程。 我只想要在使用經緯度搜索時提供的值。 如何只在 DataArray 的數組(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

我能夠解決它。

val.data = 451.13458

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM