4
$\begingroup$

I am trying to recreate John Snow's classic cholera map using KML data files sourced via this Guardian article (KML files here).

The KML files are in a zip folder and a simple Import statement generates a GeoGraphics display automatically which is nice.

pumpKML = 
  Import["/Users/joe/Documents/z school/SnowGIS_KML/pumps.kml"];
deathsKML = 
  Import["/Users/joe/Documents/z \
school/SnowGIS_KML/cholera_deaths.kml"];
{pumpKML, deathsKML}

but how can I show both deaths and pumps on the same output? I've tried variations of GeoGraphics, Overlay and Show and can't find anything in the help menu.

$\endgroup$
  • $\begingroup$ How is that you tried Show and didn't work? Probably you could share your failed code attempts. $\endgroup$ – rhermans May 25 '17 at 11:34
  • $\begingroup$ good grief, I passed it as a list and it's right there in the documentation not to. The error messages mean nothing to me and I don't have the confidence yet to think that something should work... Anyone tell me the half-life of mma users when you stop feeling like a complete idiot? $\endgroup$ – Joe May 26 '17 at 2:30
4
$\begingroup$

Solution

You need to use Show.

{deaths, pumps} = Import[
  "http://rtwilson.com/downloads/SnowGIS_KML.zip"
  , {"ZIP",
   {
    "SnowGIS_KML\\cholera_deaths.kml",
    "SnowGIS_KML\\pumps.kml"
    }
   }
  ];
Show[deaths, pumps]

Mathematica graphics

Documentation

Show[g1, g2,…] shows several graphics combined.

Mathematica graphics

Notice that for Import you can directly import several subelements, so we can download the ZIP file and get the two files of interest in one go.

{a,b}=Import[url, {"ZIP",{file1, file2}}];

Mathematica graphics Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ +1, you were faster than me :) If you want to make the problem a bit more difficult, you could do something like: conf = ConformImages[Image /@ {deathsKML, pumpKML}]; {im1, im2} = {RemoveAlphaChannel@conf[[1]], RemoveAlphaChannel@conf[[2]]}; ImageCompose[im1, ColorNegate@im2] $\endgroup$ – SuTron May 25 '17 at 11:04
  • $\begingroup$ @SuTron probably you should out that as an answer. $\endgroup$ – rhermans May 25 '17 at 17:10
  • 1
    $\begingroup$ Thank you for going the extra step and highlighting multiple element imports - i hadn't figured out what that meant from the documentation till you showed how it worked in this example. $\endgroup$ – Joe May 26 '17 at 2:32

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.