Reputation: 29
I have the problem that I have multiple data arrays (or merged together --> one big xarray dataset) and a shapefile with points. These points have inter alia columns with "geometry (=lat & lon)" and "Date". I would like to extract the values of the array/dataset at the lat, lon and time value- points the shapefile has. My goal is to have an array (or a dataset - even better) where the extracted values of the lat, lon and time of the shapefile are stored.
Now the problem is: the shapefile is 2D and the arrays are 3D.
I would be very happy for some thoughts and help! Thanks in advance!
Upvotes: 0
Views: 354
Reputation: 4603
Building off the top answer to this question and assuming your points and dataset are in the same projection, you could do something like
import geopandas
pts = geopandas.read_file(<your shp>)
lons = pts.geometry.x.to_list()
lats = pts.geometry.y.to_list()
values_at_pts = your_xarray_dataset.sel(lon=lons, lat=lats, method="nearest")
Upvotes: 1