7
$\begingroup$

Consider this example of GeoGraphics:

$labelStyle = 
  Directive[FontFamily -> "Baskerville", 
   FontVariations -> {"CapsType" -> "SmallCaps"}, FontColor -> Orange];
Table[g = GeoGraphics[GeoZoomLevel -> 6, GeoRange -> {{40, 50}, {0, 30}}, 
  GeoGridLines -> Automatic ,
  GeoBackground -> {
    GeoStyling[{Dated["CountryBorders", year], "Border" -> Black, 
      "Ocean" -> LightBlue, "Land" -> LightYellow}],
    "VectorLabels"
    },
  ImageSize -> 400, Background -> White,
  BaseStyle -> $labelStyle (* This doesn't work *)
  ], {year, {1980, 2000}}]

enter image description here

There are a few issues with vector labels:

  1. How to style them? Other than the obvious: MapAt[Style[#, $labelStyle]&, g, Position[g,_Text,\[Infinity]]].
  2. How to make them work properly with Dated?
  3. How to add the labels for names of seas in the water?
  4. How to add degree labels to the GeoGridLines?
$\endgroup$

1 Answer 1

4
+25
$\begingroup$

Here is a brute force approach about the style.

$labelStyle = 
  Directive[FontFamily -> "Baskerville", 
   FontVariations -> {"CapsType" -> "SmallCaps"}, FontColor -> Orange];
Table[GeoGraphics[GeoZoomLevel -> 6, GeoRange -> {{40, 50}, {0, 30}}, 
   GeoGridLines -> Automatic, 
   GeoBackground -> {GeoStyling[{Dated["CountryBorders", year], 
       "Border" -> Black, "Ocean" -> LightBlue, 
       "Land" -> LightYellow}], "VectorLabels"}, ImageSize -> 400, 
   Background -> White], {year, {1980, 2000}}] /. 
 Text[a_, b__] -> Text[a, b, BaseStyle -> $labelStyle]

enter image description here

If we know the list of GeoGridLines, we can add degrees labels at these positions in Epilog. If GeoGridLines is Automatic, we could run it twice and use the first run to get the position of the grid lines with AbsoluteOptions. This is what I have done below. The position of the row (longitudes) and column (latitudes) of numbers is selected manually, but each number is placed on the correct line. We can also label the Mediterranean Sea in Epilog.

$labelStyle = 
  Directive[FontFamily -> "Baskerville", 
   FontVariations -> {"CapsType" -> "SmallCaps"}, FontColor -> Orange];
Table[gg = 
    GeoGraphics[GeoZoomLevel -> 6, GeoRange -> {{40, 50}, {0, 30}}, 
     GeoGridLines -> Automatic,
     GeoBackground -> {GeoStyling[{Dated["CountryBorders", year], 
         "Border" -> Black, "Ocean" -> LightBlue, 
         "Land" -> LightYellow}], "VectorLabels"}, ImageSize -> 400, 
     Background -> White], {year, {1980, 2000}}] /. 
  Text[a_, b__] -> Text[a, b, BaseStyle -> $labelStyle];
Table[GeoGraphics[GeoZoomLevel -> 6, GeoRange -> {{40, 50}, {0, 30}}, 
   GeoGridLines -> Automatic,
   Epilog -> {ggl = AbsoluteOptions[gg, GeoGridLines]; 
     Text[# "\[Degree]", GeoPosition[{#, 2.5}], BaseStyle -> Gray] & /@
       ggl[[1]][[2]][[1]],
     Text[# "\[Degree]", GeoPosition[{50, #}], BaseStyle -> Gray] & /@
       ggl[[1]][[2]][[2]],
Text["Mediterranean\nSea", GeoPosition[{41, 6}], BaseStyle -> Blue]
     },
   GeoBackground -> {GeoStyling[{Dated["CountryBorders", year], 
       "Border" -> Black, "Ocean" -> LightBlue, 
       "Land" -> LightYellow}], "VectorLabels"}, ImageSize -> 400, 
   Background -> White], {year, {1980, 2000}}] /. 
 Text[a_, b__] -> Text[a, b, BaseStyle -> $labelStyle]

enter image description here

$\endgroup$
2
  • $\begingroup$ Nice! Can you make the gridline labels avoid overlapping with the lines? Also any idea on how or if we can get the appropriate country labels for the given Dated, e.g. yugoslavia? $\endgroup$
    – user5601
    Jul 7, 2022 at 15:27
  • $\begingroup$ You can move the labels wherever you want. For example, in the first Text in Epilog, changing GeoPosition[{#, 2.5}] to GeoPosition[{#+0.2, 2.5}] will move the latitude labels just above the grid lines. For Yugoslavia, it appears that the names of the included republics are given instead. The more recent map breaks down this area with various country borders. Note that a larger image size will reveal more labels. $\endgroup$ Jul 7, 2022 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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