2
$\begingroup$

I was using with Mathematica 10 for plotting different kinds of maps the function PolygonCombine. It seems that this fucntion has disappeared with the version 10.4? Here is a classical example for the use of this function:

Graphics`Mesh`MeshInit[];

world = CountryData[#, "FullPolygon"] & /@ 
    CountryData["Continents"] // Flatten;

worldplot = 
 Graphics[{FaceForm[White], EdgeForm[Black], PolygonCombine@world} /. 
   Polygon -> Line, Frame -> True, 
  FrameLabel -> {"Longitude", "Latitude"}, ImageSize -> Full]

How I could do the same thing now by replacing the function PolygonCombine without changing all my programs? Thank you.


Thank you for your help. But now I have detected another problem: I cannot remove Antartica continents like I was doing previously?

See the following example:

Graphics`Mesh`MeshInit[];

world = CountryData[#,"FullPolygon"] & /@ 
    Cases[CountryData["Continents"], Except["Antarctica"]] // Flatten;

worldplot = 
 Graphics[{FaceForm[White], EdgeForm[Black], 
    Polygon[GeoPosition[#]] & @@ (PolygonCombine[
       Polygon @@@ world[[All, 1]]])} /. Polygon -> Line, 
  Frame -> True, FrameLabel -> {"Longitude", "Latitude"}, 
  ImageSize -> Full]

Thanks a lot.

$\endgroup$
10
  • $\begingroup$ RegionPlot[world] /. Polygon->Line ? $\endgroup$
    – SquareOne
    Commented Mar 24, 2016 at 10:49
  • $\begingroup$ What exactly should it do? If I just remove the PolygonCombine@ from your code, I get [this]( i.sstatic.net/PY6Ff.png) - what do you want that is different from that? $\endgroup$
    – Jason B.
    Commented Mar 24, 2016 at 10:49
  • 1
    $\begingroup$ To help you find where it is now: ?*`*PolygonCombine $\endgroup$ Commented Mar 24, 2016 at 10:53
  • 1
    $\begingroup$ @SquareOne - Yeah, I actually just installed version 9 so I could check that out. I was going to see if you could create a BoundaryMeshRegion out of it and go from there. I started with DiscretizeGraphics@Graphics@world - and then my computer started thinking so hard it was unresponsive and I had to restart. So, um, don't try that $\endgroup$
    – Jason B.
    Commented Mar 24, 2016 at 11:10
  • 1
    $\begingroup$ @SquareOne - I don't have version 10.4, but in 10.3 the OP's code above does not work, but I don't think it has to do with PolygonCombine, but rather with the representation of the polygons. If you have version 10.4, try replacing the definition of world above with world = << "https://www.dropbox.com/s/nl5w33qr9ppfedi/world.txt?dl=1"; and see if that fixes the problem. $\endgroup$
    – Jason B.
    Commented Mar 24, 2016 at 11:39

1 Answer 1

4
$\begingroup$

So when I tried the code from the OP in version 10.3, I get the error message

Graphics`PolygonUtils`PolygonCombine is not a Graphics primitive or directive.

while in version 9 it returns this image

enter image description here

So it is natural to assume that the undocumented function is the culprit, and WRI just removed it without saying anything, which is their prerogative. But I think the issue is with the GeoPosition polygons instead.

Let's look at the representation of the polygons in version 10.3,

CountryData["Germany", "FullPolygon"]

enter image description here

and compare it to the same thing in version 9,

CountryData["Germany", "FullPolygon"]
(* Polygon[{{{7.24916, 53.3298}, {6.99916, 53.359}, ...
            .... {8.59249, 54.5073}}}] *)

So now there is some sort of internal gray box between us and the polygon coordinates, and it seems to be confusing the PolygonCombine function. (Thanks to SquareOne for making this easier) You can convert it to a normal Polygon via

Polygon @@ First@CountryData["Germany", "FullPolygon"]
(* Polygon[{{{53.3298, 7.24916}, {53.359, 6.99916},
            ......{54.5073, 8.59249}}}] *)

But the x and y coordinates have been reversed. For some reason, GeoPosition seems to tell Polygon to swap the coordinates. For this I'll Map Reverse to the second-deepest level of the polygon.

Polygon @@ First@CountryData["Germany", "FullPolygon"] // 
  Map[Reverse, #, {-2}] & // Graphics

enter image description here

Of course you get the exact same output if you use CountryData["Germany", "FullPolygon"], but it is not a normal polygon. Just try Cases[CountryData["Germany", "FullPolygon"] // Graphics, Polygon[_]] to see this.

It's pretty easy to apply this to the world list, just adding one line to the code in the OP

Graphics`Mesh`MeshInit[];

world = CountryData[#, "FullPolygon"] & /@ CountryData["Continents"] //
    Flatten;
world = Map[Reverse, #, {-2}] &@*Polygon @@@ world[[All, 1]];

worldplot = 
 Graphics[{FaceForm[White], EdgeForm[Black], PolygonCombine@world} /. 
   Polygon -> Line, Frame -> True, 
  FrameLabel -> {"Longitude", "Latitude"}, ImageSize -> 600]

enter image description here

SquareOne pointed out that you could skip the Map step and use the fact that GeoPosition inverts the coordinates to your advantage by replacing PolygonCombine@world with Polygon[GeoPosition[#]] & @@ (PolygonCombine[ Polygon @@@ world[[All, 1]]]) This does result in a slightly shorter code (by 6 bytes :-P), but I prefer the Map method for clarity and because it seems to run faster without the extra step of reusing GeoPosition.

To get the map without Antarctica (who needs it!!), we use this

world = CountryData[#, "FullPolygon"] & /@ 
    Cases[CountryData["Continents"], 
     Except[EntityClass["Country", "Antarctica"]]] // Flatten;

world = Map[Reverse, #, {-2}] &@*Polygon @@@ world[[All, 1]];

worldplot = 
 Graphics[{FaceForm[White], EdgeForm[Black], PolygonCombine@world} /. 
   Polygon -> Line, Frame -> True, 
  FrameLabel -> {"Longitude", "Latitude"}, ImageSize -> 600]

enter image description here

$\endgroup$
6
  • $\begingroup$ It wasn't removed. I gave a hint in the comments on how to find its current context. $\endgroup$ Commented Mar 24, 2016 at 12:26
  • $\begingroup$ Right, but it can actually still be found via the older context as well (er, almost). It's odd, but by loading Graphics`Mesh`MeshInit[]; you can call it directly, or you can call it via Graphics`PolygonUtils`PolygonCombine which is what you get when you do your search $\endgroup$
    – Jason B.
    Commented Mar 24, 2016 at 12:32
  • $\begingroup$ But oddly enough, you can't call it like you used to, with Graphics`Mesh`PolygonCombine $\endgroup$
    – Jason B.
    Commented Mar 24, 2016 at 12:33
  • $\begingroup$ But this is beside the point, since the real issue at hand is "What have they done with geographical polygons and why did they do it?" $\endgroup$
    – Jason B.
    Commented Mar 24, 2016 at 12:34
  • $\begingroup$ @JasonB What a mess ... It means that when Polygon is applied to GeoPosition it knows that it has to reverse the coordinates ... Anyway, I think I have something shorter : in th OP's code just replace PolygonCombine[world] with Polygon[GeoPosition[#]] & @@ (PolygonCombine[ Polygon @@@ world[[All, 1]]]) $\endgroup$
    – SquareOne
    Commented Mar 24, 2016 at 13:35

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.