5
$\begingroup$

I have a problem rotating some text in GeoGraphics. Whenever I rotate the text I am also getting a shift in the latitude.

  • OS: Linux x86 (64-bit)

  • FullVersionNumber: 12.1.1

As a minimum working example (taken from the documentation and simply adding a text) is the following:

GeoGraphics[{Entity["Country", "UnitedKingdom"], GeoMarker[Entity["City", {"London","GreaterLondon", "UnitedKingdom"}]], Style[Text["Something",GeoPosition[{59.88295193293852, -4.916961348517941}]], {15}]}]

which works as expected.

However, if I use Rotate the resulting rotated text is shifted in the latitude :

GeoGraphics[{Entity["Country", "UnitedKingdom"], GeoMarker[Entity["City", {"London","GreaterLondon", "UnitedKingdom"}]], Rotate[Style[Text["Something",GeoPosition[{59.88295193293852, -4.916961348517941}]], {15}],Pi/2]}]

The following code produces somehow the desired outcome, but I have to shift the latitude exactly by 15 Degrees:

GeoGraphics[{Entity["Country", "UnitedKingdom"], GeoMarker[Entity["City", {"London","GreaterLondon", "UnitedKingdom"}]], Rotate[Style[Text["Something",GeoPosition[{74.88295193293852, -4.916961348517941}]], {15}],Pi/2]}]

Any ideas, what is happening? Is this the expected behaviour?

Thanks, Dimitris

$\endgroup$
1
  • $\begingroup$ Thanks for your answers! There is still an open point from me. Is this the expected behaviour? @Zviovich, "order of functions do matter", that 's true but not for the case of Rotate and Graphics. Please have a look on the following: Graphics[Rotate[Text[Style["something",18],{12,12}],Pi/4], Axes -> True] Graphics[Text[Rotate[Style["something", 18], Pi/4], {12, 12}], Axes -> True] Graphics[Text[Style[Rotate["something", Pi/4], 18], {12, 12}], Axes -> True] These inputs give the same result. Why is this not the case also for GeoGraphics? Why does the order matter for GeoGraphics? $\endgroup$
    – demm
    Jan 5 at 21:22
6
$\begingroup$

Rotate and style the string before using Text to set the position on the map.

GeoGraphics[{Entity["Country", "UnitedKingdom"],
  GeoMarker[Entity["City", {"London","GreaterLondon", "UnitedKingdom"}]],
  Text[Rotate[Style["Something", 15], Pi/2],
    GeoPosition[{59.88295193293852, -4.916961348517941}]]}]

rotated text

$\endgroup$
6
$\begingroup$

You can use the fourth argument of Text to rotate the label instead of using Rotate:

GeoGraphics[{Entity["Country", "UnitedKingdom"], 
  GeoMarker[Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}]], 
  Style[Text["Something", GeoPosition[{59.88295193293852, -4.916961348517941}], 
    {Center, Center}, {0, 1}], 
  15, Bold, Red]}]

enter image description here

Replace {0,1} with Through[{Cos, Sin}[Pi/4]] to get

enter image description here

ListAnimate[Table[
  GeoGraphics[{Entity["Country", "UnitedKingdom"], 
    GeoMarker[Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}]], 
    Style[Text["Something", 
     GeoPosition[{59.88295193293852, -4.916961348517941}], 
     {Center, Center}, t], 15, Bold, Red]}],
  {t, CirclePoints[{1, 0}, 36]}], 
  DisplayAllSteps -> True]

enter image description here

$\endgroup$
5
$\begingroup$

Order of functions do matter. Set up the text first with Style, then rotate and finally place in the map. Added a point in the map to ensure that the text is placed where you wanted.

Manipulate[
 With[{txtPoint = 
    GeoPosition[{59.88295193293852, -4.916961348517941}]}, 
  GeoGraphics[{GeoMarker[
     Entity["City", {"London", "GreaterLondon", "UnitedKingdom"}]], 
    Point[GeoPosition@txtPoint], 
    Text[Rotate[Style["Something", 12], angle], 
     GeoPosition[txtPoint]]}, GeoRange -> "Country"]], {angle, 0, Pi}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.