1
$\begingroup$

I need to make a GeoGraphics[] object then save it to disk, move it to another computer where I need to load in the object then add some more GeoGraphics[] primitives. Below is a simple example of what I think should work.

Warning: The code below will download an image from Google and save it to your hard drive in your $TemporaryDirectory location! If you run all the code I do remove the file.

Get an image of one of my favorite camping locations then save it out:

loc = {37.4826678, -110.6310902};
geobackdrop = 
  GeoGraphics[GeoCenter -> GeoPosition[loc], 
  GeoServer -> "http://mt0.google.com/vt/lyrs=s,h&x=`2`&y=`3`&z=`1`", 
  GeoRange -> Quantity[2, "Kilometers"], 
  AspectRatio -> 1];
file = FileNameJoin[{$TemporaryDirectory, "Moqui.wl"}];
Save[file, geobackdrop];
ClearAll[geobackdrop];

At this point, we should have a GeoGraphics[] object on disk. Now lets read it in and try to add a GeoDisk[].

 Get[file];
 Cases[{geobackdrop}, 
            GeoGraphics[a_, b___] :> 
            GeoGraphics[{
               GeoDisk[loc, Quantity[.05, "Kilometers"]], a}, b]
             ][[1]]

Where is my Disk? Is there a clean way to add items to the GeoGraphics[] object I have read off the disk?

Run this to remove the file from your hard drive:

  If[FileExistsQ[file], DeleteFile[file]]
  If[Not[FileExistsQ[file]],
     Print["The file is gone!"]]

Thank you.

$\endgroup$
  • $\begingroup$ Is Save/Get part essential for the problem? Is your cases method doing what you expect if you skip save/get? $\endgroup$ – Kuba May 17 '18 at 21:44
  • $\begingroup$ Yes the Save/Get is not essential the Cases[] and I could have asked the question without it but then I expected the question "Why not just put the GeoDisk[] in at the start?" $\endgroup$ – c186282 May 17 '18 at 22:30
  • $\begingroup$ To avoid that question add a note that you can't because you can't. It was createad earlier/took a long time/you imported it. Whatever :) $\endgroup$ – Kuba May 17 '18 at 22:35
1
$\begingroup$

The disk is there but it is hard to find because it is rather small and shaded in transparent black. It is easier to spot if you make it its boundary red:

Cases[{geobackdrop}, GeoGraphics[a_, b___] :> GeoGraphics[{
     EdgeForm[{Red, Thick}],GeoDisk[loc, Quantity[.05, "Kilometers"]], a}, b]][[1]]

enter image description here

Btw., since this is somewhat counterintuitive: In order to change the style of the interior of the disk, you may use GeoStyling:

Cases[{geobackdrop}, GeoGraphics[a_, b___] :> GeoGraphics[{
     GeoStyling[Directive[Opacity[1], Red]],
     GeoDisk[loc, Quantity[.05, "Kilometers"]], a},
    b]
  ][[1]]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you I feel rather silly but I did not look closely because I also got the warning: "Graphics is not a Graphics primitive or directive." Did you get this warning? $\endgroup$ – c186282 May 17 '18 at 23:40
  • $\begingroup$ No error. Worked like a charm. (version 11.3 on macOS). No need to feel silly. I also didn't find it in the first place. :) $\endgroup$ – Henrik Schumacher May 17 '18 at 23:43
  • $\begingroup$ Thanks. They both work for me also but I do get the warning. (Version 11.3 on Mint Linux) $\endgroup$ – c186282 May 18 '18 at 0:10
  • $\begingroup$ Well, if it works (apart from the warning), then you can tell Mathematica to be Quiet... :) $\endgroup$ – Henrik Schumacher May 18 '18 at 0:11
  • $\begingroup$ Yes, I have done that before and I'll do it here but it is not clean. $\endgroup$ – c186282 May 18 '18 at 0:14

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.