【发布时间】:2022-01-27 04:08:54
【问题描述】:
这个问题是相关的,但不知何故,我仍然需要一些帮助才能让它工作。 xarray select nearest lat/lon with multi-dimension coordinates
import rioxarray
import numpy as np
import geopandas as gpd
import cartopy.crs as ccrs
# download and read elevation data (about 40MB)
xds = rioxarray.open_rasterio("https://elevationeuwest.blob.core.windows.net/copernicus-dem/COP30_hh/Copernicus_DSM_COG_10_N36_00_W113_00_DEM.tif")
# now I wish to find the elevation at the following coordinates:
this_lon = -112.23425
this_lat = 36.3566
# I can get elevation nearby by rounding the coordinates:
xds.loc[dict(x=-112.2, y=36.4)].values
# array([2708.229], dtype=float32)
# but since the data has a 30 meters grid, I should be able
# to be more precise than rounding the coordinates
# If I use the exact coordinates I get an error since they are
# not in the indexes:
xds.loc[dict(x=-112.23425, y=36.3566)].values
# KeyError: -112.23425
我曾尝试使用 cartopy,但失败了:
data_crs = ccrs.LambertConformal(central_longitude=-100)
x, y = data_crs.transform_point(-112.23425, 36.3566, src_crs=ccrs.PlateCarree())
xds.sel(x=x, y=y)
# KeyError: -1090022.066606806
documentation 提到“哥白尼 DEM 实例在地理坐标中可用;水平参考基准是 1984 年世界大地测量系统 (WGS84-G1150; EPSG 4326)”,但我不知道如何使用此信息.
-
您可以将 WGS84 视为简单的纬度/经度 - 它是代表地球的参考椭球体的特定定义,但对于大多数用途来说,这就是您在使用经纬度数据时要寻找的内容。另外,看看
nearest
和tolerance
的参数 xarray.Dataset.sel