Plot only trajectory segments exceeding length threshold

Given a Pandas DataFrame with millions of location records (lat and lon column) for multiple moving objects, is there an elegant way to plot only segments (connecting consecutive location records of the same moving object) that exceed a certain minimum length?

https://datashader.org/user_guide/Trajectories.html does not go into much detail and any styling I apply to the path (as described in http://holoviews.org/reference/elements/matplotlib/Path.html) gets lost during datashading.

I can achieve the desired results using GeoPandas & geoviews but it’s rather slow.

I’ve worked out a work-around: see section A-5) Gaps in trajectories in https://github.com/anitagraser/movingpandas-examples/blob/main/analysis-examples/5-exploration-protocol.ipynb but it’s quite tedious and I wonder if I’m missing anything.

1 Like

I don’t know of any solution in HoloViz tools for filtering by segment length, so I’d use GeoPandas. If that’s too slow, an optimized routine could be added to SpatialPandas, which shouldn’t be too hard. In any case, yes, styling will be lost when you datashade or rasterize, because datashade transforms the HoloViews Element it is given (e.g. hv.Paths) into hv.RGB, and rasterize transforms it into hv.Image. So you’ll need to supply options suitable for hv.Image, not hv.Paths. We’re hoping that we’ll eventually figure out ways to map such options automatically, but don’t have such a solution yet.