Skip to content
Advertisement

Extract values from xarray dataset using geopandas multilinestring

I have a few hundred geopandas multilinestrings that trace along an object of interest (one line each week over a few years tracing the Gulf Stream) and I want to use those lines to extract values from a few other xarray datasets to know sea surface temperature, chlorophyll-a, and other variables along this path each week.

I’m unsure though how exactly to use these geopandas lines to extract values from the xarray datasets. I have thought about breaking them into points and grabbing the dataset values at each point but that seems a bit cumbersome. Is there any straightforward way to do this operation?

Advertisement

Answer

Breaking the lines into points and then extracting the point is quite straightforward actually!

JavaScript
JavaScript

The main thing is to decide on which point you’d like to sample, or how many points, etc.

Note that the geometry objects in the geodataframe also have an interpolation method, if you’d like draw values at specific points along the trajectory:

https://shapely.readthedocs.io/en/stable/manual.html#object.interpolate

In such a case, .apply can come in handy:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement