3
$\begingroup$

I am using the GeoGraphics function to create a "Hammer" projection of the sky to plot astronomical data. Since every data set has to be mapped using the Hammer projection algorithm individually I am trying to create a template image which I will then overlay the data sets onto. A snippet of the code is below:

    Master = Graphics @@ 
    GeoGraphics[{}, GeoRange -> {All, {-180, 180}}, 
    PlotRangePadding -> [email protected], 
    GeoGridLinesStyle -> Directive[Green, Dashed], 
    GeoProjection -> "Hammer", GeoGridLines -> Automatic, 
    GeoBackground -> Black, Axes -> True, ImagePadding -> 1, 
    ImageSize -> 800, 
    Ticks -> {Table[{N[i Degree], 
    Row[{i + 180, " \[Degree]"}]}, {i, -180, 180, 30}], 
    Table[{N[i Degree], Row[{i, " \[Degree]"}]}, {i, -90, 90, 15}]}, 
    AxesStyle -> White, TicksStyle -> 15];

    points2 = {{61.258333`, 
    50.66875`}, {-58.914583`, -43.44125000000003`}, {79.108333`, 
    143.166667`}, {41.7275`, 
    11.38798`}, {38.32`, -23.38583299999999`}, {-78.946139`, 
    54.731667`}, {-66.98`, 85.412083`}};

    HammerLong1 = (2 Sqrt[2] Cos[10.66875] Sin[41.258333/2])/
    Sqrt[1 + Cos[10.66875] Cos[41.258333/2]]*180/\[Pi]

    HammerLat1 = (Sqrt[2] Sin[10.66875])/
    Sqrt[1 + Cos[10.66875] Cos[41.258333/2]]*180/\[Pi]

    plot3 = Graphics @@ 
    GeoGraphics[{AbsolutePointSize@7, Blue, Point@GeoPosition@points2, 
    AbsolutePointSize@14, Green, 
    Point@GeoPosition@Thread[{HammerLong1, HammerLat1}]}, 
    GeoRange -> {All, {-180, 180}}, PlotRangePadding -> [email protected], 
    GeoGridLinesStyle -> Directive[Green, Dashed], 
    GeoProjection -> "Hammer", GeoBackground -> None];

    id = ImageDimensions[Master];
    Manipulate[Graphics[{Black, Rectangle[{0, 0}, id], 
    Switch[chart, "   Plot 1   ", Inset[Master, Center, Center, id], 
    "   Plot 2   ",Inset[plot3, Center, Center, id]]}, 
    PlotRange -> {{0, First[id]}, {0, Last[id]}}, 
    ImageSize -> id], {{chart, "   Plot 1   ", 
    "Displayed: "}, {"   Plot 1   ", "   Plot 2   "}}, 
    ControlType -> RadioButtonBar, SaveDefinitions -> True, 
    AppearanceElements -> "ResetButton"]

As the code is currently written only one radio button can be selected at a time, which doesn't allow me to overlay multiple data sets over the background image.

The solution using Switch was the first success out of many failed efforts to use Manipulate with the pre-computed graphics images, but I have a feeling that it is not the best option. Any and all help would be appreciated!

$\endgroup$
2
  • $\begingroup$ HammerLong1, HammerLat1 to go :) $\endgroup$
    – Kuba
    Jan 26, 2018 at 19:36
  • $\begingroup$ Ugh. Apologies. If you can't tell, I'm new to this :( $\endgroup$
    – Ed McClain
    Jan 26, 2018 at 19:45

1 Answer 1

2
$\begingroup$

Does it work for you?

Manipulate[
 Graphics[
  {Dynamic[{First@Master, First@plot3}[[charts]]]}
  , Sequence @@ Rest@Master, Background -> Black
  ],
 {{charts, {1}}, {1 -> "Plot 1", 2 -> "Plot 2"}}, 
 ControlType -> TogglerBar, SaveDefinitions -> True, 
 AppearanceElements -> "ResetButton"]

I use First to strip Graphics and only manage primitives sets inside the main Graphics.

$\endgroup$
4
  • $\begingroup$ Wow! This does work wonderfully, thank you! I'm not quite sure I understand the full motivation of the solution though. The documentation on First doesn't illuminate the usage here. $\endgroup$
    – Ed McClain
    Jan 26, 2018 at 19:59
  • $\begingroup$ @EdMcClain the first element of Graphics is a list of primitives and the rest are options. $\endgroup$
    – Kuba
    Jan 26, 2018 at 20:13
  • $\begingroup$ Thank you so much! $\endgroup$
    – Ed McClain
    Jan 26, 2018 at 21:01
  • $\begingroup$ @EdMcClain worth to notice that it does not matter much here but it is an useful idiom in general. I found my old topic with a little bit more explanation: mathematica.stackexchange.com/a/148412/5478 $\endgroup$
    – Kuba
    Jan 26, 2018 at 21:02

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.