SciTools / cartopy

Cartopy - a cartographic python library with matplotlib support
https://scitools.org.uk/cartopy/docs/latest
BSD 3-Clause "New" or "Revised" License
1.43k stars 364 forks source link

matplotlib FeatureArtist should define containment check #679

Open BrenBarn opened 9 years ago

BrenBarn commented 9 years ago

The FeatureArtist does not define the matplotlib API contains method (or _contains --- I'm not actually sure which one you're supposed to override in this case). This means that you can't use matplotlib pick events to interactively select a map feature, because the features have no way to tell whether a mouse event occurred inside them.

This StackOverflow question is about the same issue. The answer by no less than @pelson says:

Sadly, it looks like the FeatureArtist isn't a subclass of PathCollection, as it technically should be, but it simply inherits from Artist. This means that, as you've already spotted, the containment test isn't defined on the artist, and in truth, it isn't particularly easy to work around in its current state.

The answer there points the way towards an implementation of a containment check (although it would have to be generalized to convert to the appropriate CRS).

One way or another, this should be added. Being able to use matplotlib pick events is really import for making interactive maps with matplotlib.

pelson commented 9 years ago

Thanks for raising @BrenBarn - I'd definitely be interested in helping this happen. Did you take a look at having a go at this? Conceptually, it sounds pretty reasonable, and I'd love to see a new example in the gallery which had this capability.