【问题标题】:How to get values in the DataArray of XArray如何获取 XArray 的 DataArray 中的值
【发布时间】: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


    【解决方案1】:

    我能够解决它。

    val.data = 451.13458
    

    【讨论】:

      猜你喜欢
      • 2021-07-20
      • 2021-02-02
      • 2017-10-10
      • 1970-01-01
      • 2019-01-18
      • 2019-04-02
      • 2018-12-18
      • 2020-07-15
      • 2019-06-28
      相关资源
      最近更新 更多