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
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"]
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
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]
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]
RegionPlot[world] /. Polygon->Line
? $\endgroup$PolygonCombine@
from your code, I get [this]( i.sstatic.net/PY6Ff.png) - what do you want that is different from that? $\endgroup$?*`*PolygonCombine
$\endgroup$BoundaryMeshRegion
out of it and go from there. I started withDiscretizeGraphics@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$PolygonCombine
, but rather with the representation of the polygons. If you have version 10.4, try replacing the definition ofworld
above withworld = << "https://www.dropbox.com/s/nl5w33qr9ppfedi/world.txt?dl=1";
and see if that fixes the problem. $\endgroup$