Map scalebar always horizontal even for projections not preserving angles (Mercator vs. RGF93) #251
Replies: 6 comments
-
Hey, nice to see you're using EOmaps! the scalebar has a "rotation" argument that sets the azimuth angle in which the scalebar points As this angle is relative to the direction of latitude lines, a scalebar with As a quick suggestion i see 2 possible solutions:
|
Beta Was this translation helpful? Give feedback.
-
Hey, I had a proper look at the problem and actually found a quite nice and simple solution! In the meantime, here's a quick monkey-patch version: from eomaps import Maps
import numpy as np
def set_rotation(self, ang=0):
"""
Set the absolute rotation angle of the first segment of the scalebar.
Note
----
This method sets the "absolute rotation angle" in display units,
not the "azimuth angle" which can be set with :py:meth:`ScaleBar.set_position`.
Parameters
----------
ang : float
The rotation angle.
"""
lon, lat, _ = self.get_position()
x0, y0 = self._m._transf_lonlat_to_plot.transform(lon, lat)
x1, y1 = self._m._transf_lonlat_to_plot.transform(
*self._geod.fwd(lon, lat, -ang, self.get_scale())[:2]
)
azim = np.rad2deg(-np.arctan2(x1 - x0, y1 - y0))
self.set_position((lon, lat), azim=azim)
m = Maps(2154)
m.add_feature.preset.coastline()
scb1 = m.add_scalebar((-6, 43.45))
set_rotation(scb1, 0)
scb2 = m.add_scalebar((2.5, 46))
set_rotation(scb2, 45)
scb3 = m.add_scalebar((-7, 51))
set_rotation(scb3, 90) |
Beta Was this translation helpful? Give feedback.
-
Thank you. One last remark that I got from some of our collaborators. Currently I'm planning to do that using the x limits of the map, to specify directly the segment length, I'm obliged to have 4 segments alternating in color. |
Beta Was this translation helpful? Give feedback.
-
Hey,
🚀 Nice to hear! I very much appreciate any efforts to improve the package!
There is an example in the docs on how to fully customize scalebars: The "scale" (e.g. the length of one segment of the scalebar) is only dependent on the axes-limits if you do not specify it explicitly. For example: from eomaps import Maps
lon, lat = -2.562, 49.4653
extent = (-2.565, -2.554, 49.4642, 49.4682)
m = Maps(2154)
m.add_feature.preset.coastline()
m.set_extent(extent)
scb1 = m.add_scalebar((lon, lat))
scb2 = m.add_scalebar((lon+0.002, lat), scale=29, n=4,
scale_props=dict(colors=("r", "g")))
scb3 = m.add_scalebar((lon+0.004, lat), scale=29, n=4,
scale_props=dict(colors=("k", ".75")),
patch_props=dict(fc="none", ec="none")) |
Beta Was this translation helpful? Give feedback.
-
Hey, I've converted this to a discussion to preserve the answers for later! |
Beta Was this translation helpful? Give feedback.
-
With an update to EOmaps v8.3 you can use: eomaps import Maps
m = Maps(2154)
m.add_feature.preset.coastline()
scb = m.add_scalebar((-6, 43.45), scale=5e4)
scb.set_rotation(90) |
Beta Was this translation helpful? Give feedback.
-
I am using your library to plot maps, currently I'm using Web Mercator as a projection (Below is a map in web mercator).
Recently I was asked to use a more precise projection. For France, we use 2154. However, when I do that the Scalebar is not horizontal anymore. Is there a solution to my problem.
Thank you
Beta Was this translation helpful? Give feedback.
All reactions