繁体   English   中英

Copernicus Dem xarray select 具有多维坐标的最近纬度/经度

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM