Curious How EOMaps Calculates Compass Rotation #231
-
I'm working on a personal package for adding a north arrow to matplotlib maps I am making, using a similar methodology to EOMaps (namely, drawing a polygon and adding it to an OffsetBox). One thing I haven't cracked yet is rotating the north arrow based on the input CRS of the data, which it does look like EOMaps can do. Particularly, it seems like the def _get_transform(self, pos):
lon, lat = self._m._transf_plot_to_lonlat.transform(*pos)
x, y = self._m._transf_lonlat_to_plot.transform([lon, lon], [lat, lat + 0.01])
try:
ang = -np.arctan2(x[1] - x[0], y[1] - y[0])
except Exception:
_log.error("EOmaps: Unable to add a compass at the desired location.")
return
... And then it adds that angle as a rotation to the Affine2D transformation that happens later. However, I'm not fully understanding the code here. It looks like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey,
OK, and now to your questions 🙂: First, Concerning the method for determining the rotation, the idea is the following:
... and since a picture is usually worth more than long explanations... I mean something like this: |
Beta Was this translation helpful? Give feedback.
Hey,
since you have lots of questions... let me ask you one myself:
OK, and now to your questions 🙂:
First,
as_geodetic
is coming from the cartopy CRS (which uses pyproj under the hood): hereConcerning the method for determining the rotation, the idea is the following: