[英]Copernicus Dem xarray select nearest lat/lon with multi-dimension coordinates
這個問題是相關的,但不知何故我仍然需要一些幫助才能讓它工作。 xarray select 具有多維坐標的最近緯度/經度
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
文檔提到“哥白尼 DEM 實例在地理坐標中可用;水平參考基准是 1984 年世界大地測量系統(WGS84-G1150;EPSG 4326)”,但我不知道如何使用此信息。
實際上經度和緯度是1/3600度的均勻空間。 我們可以看到:
xds.x.values
array([-113. , -112.99972222, -112.99944444, ..., -112.00083333,
-112.00055556, -112.00027778])
(xds.x.values + 113)*3600
array([0.000e+00, 1.000e+00, 2.000e+00, ..., 3.597e+03, 3.598e+03,
3.599e+03])
因此,我們可以在哥白尼 DEM 索引中快速找到最近的點,如下所示:
i = round((-112.23425 + 113) * 3600)
j = round((36.3566 - 36) * 3600)
lon_nearest = xds.x.values[i]
lat_nearest = xds.y.values[j]
xds.loc[dict(x=lon_nearest, y=lat_nearest)].values
array([2553.148], dtype=float32)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.