Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to plot the world map without the countries' borders and just the coastlines (in Mathematica 8). I need to overlap a temperature contour plot on the world map.

When I plot country data with lines, it is so crowded because of the lines related to the borders. Plotting with polygons does not help, since I cannot overlap the second plot on top of it.

For example in the following command how can I add an option to exclude the borders?

    Graphics[CountryData[#, "Polygon"] & /@ CountryData["Continents"], 
             ImageSize -> 400] /. Polygon -> Line

In other words, I need something nice like this but not with polygons and only the coastlines:

    map = Graphics[{GrayLevel[0.5], AbsoluteThickness[1.6], 
   CountryData[#, {"FullPolygon", {"Equirectangular", {0, 
       180}}}]} & /@ {"Antarctica", "World"} /. Polygon -> Line, 
   Frame -> True, FrameStyle -> Directive[Thick], 
   PlotLabel -> "Precipitation", 
   FrameLabel -> {"Longitude (°E)", "Latitude (°N)"}, 
  Axes -> True, AxesStyle -> Directive[Gray], 
  LabelStyle -> Directive[Black, 18, Bold], PlotRangePadding -> None,
  ImageSize -> 600, 
  GridLinesStyle -> Directive[AbsoluteThickness[2], GrayLevel[0.25]],
  GridLines -> {Automatic, Automatic}, 
  Method -> {"GridLinesInFront" -> True}];
share|improve this question
    
It may be easier to just import the outlines from some other source. I found this but Mma won't read the SHP file from there. Maybe you can search around more. There's very detailed data here: ngdc.noaa.gov/mgg/shorelines/gshhs.html –  Szabolcs Jan 24 '13 at 19:22
    
@Szabolcs I don't know if this way would make it easier. I do not need a very detailed map, just a correct shape of the coastline would be enough. Thanks anyway –  Karami Jan 24 '13 at 19:36
1  
@Szabolcs The correct Import statement is Import["http://pubs.usgs.gov/of/2006/1187/basemaps/continents/continents.zip", "SHP"]. It works. –  Sjoerd C. de Vries Jan 24 '13 at 19:40
    
@Sjoerd Are you familiar with SHP files (I'm not)? Why do you need to import the ZIP and not the SHP? –  Szabolcs Jan 24 '13 at 19:41
    
@Szabolcs It's in the SHP page. I read up on that yesterday, because we had a question with SHP data. –  Sjoerd C. de Vries Jan 24 '13 at 19:51
add comment

4 Answers 4

Using those weird longitude values:

Graphics[{Lighter@Orange, 
  Translate[CountryData[#, "SchematicPolygon"], {180, 0}] & /@ 
   CountryData[]}, Axes -> True, Frame -> True,
 Epilog -> {Gray,
   {Style[Text["look, no borders!", {80, -20}], 10],
    Arrow[{{90, -25}, {120, -25}}]},
   {Style[Text["lots of coastline!", {330, 15}], 10],
    Arrow[{{340, 5}, {310, 5}}]}
   }]

map

I always think Antarctica looks daft spread along the bottom. But yes, it's gone missing, melted, or something, don't know why... :)

share|improve this answer
    
The reason is that Antarctica isn't a country! –  Oleksandr R. Jan 25 '13 at 14:16
1  
You need to mention Antarctica in your code otherwise it will not be plotted. About your code, sorry, I do not really understand your point.It does not answer the question,does it? –  Karami Jan 25 '13 at 14:19
    
You can downvote it! :) –  cormullion Jan 25 '13 at 14:20
    
You are welcome :) –  Karami Jan 25 '13 at 14:48
add comment

Using the method suggested in answer 2 by @rm -rf, and another post about how to define the Longitude from 0-360 (define the range of Longitude from 0-360 in the World plot from CountryData), I wrote the following code to plot the world map:

    map1 = CountryData[#, {"FullPolygon", {"Equirectangular", {0, 
    180}}}] & /@ {"Antarctica", "World"};

rm -rf

    Graphics`Mesh`MeshInit[];

    map2 = Graphics[{Gray, PolygonCombine@map1} /. Polygon -> Line, 
    Frame -> True];

<

Chris Degnen

    linepos = First[Position[map2, Line]];
    line = Extract[map2, Most[linepos]];
    newline = line /. {a_Real, b_} :> {a + 180, b};

<

    map3 = ReplacePart[map2, Most[linepos] -> newline]
share|improve this answer
add comment

You can easily do it using CountryData and there's no need to import anything. For this, we'll need an undocumented function, Graphics`Mesh`PolygonCombine, which will be used to "combine" all the countries so that there are no internal borders. Evaluating Graphics`Mesh`MeshInit[] will load the undocumented functions into your context path.

You can then create a map of the world with only the coastline as:

Graphics`Mesh`MeshInit[];
world = CountryData[#, "FullPolygon"] & /@ CountryData["Continents"] // Flatten;
Graphics[{Gray, PolygonCombine@world} /. Polygon -> Line]

share|improve this answer
1  
great,thanks. I do not understand why there are such functions but not documented. –  Karami Jan 25 '13 at 10:19
1  
@Karami see here mathematica.stackexchange.com/questions/5940/… –  Ajasja Jan 25 '13 at 15:09
2  
@Karami Indeed, the link that Ajasja provided is a very good one that lists the pros and cons of using undocumented functions. In this particular case, I don't think these functions will be removed, as they're used a lot internally for generating mesh polygons in the plotting routines. You can also just do this once and save the coast map (the line data) and simply reuse it when you need it instead of building it each time. –  rm -rf Jan 25 '13 at 15:27
add comment

One option is to use a different dataset than the one provided by CountryData.

I found this detailed shoreline dataset.

After downloading and extracting the dataset, navigate to the GSHHS_shp/c folder. This contains the lowest resolution data, then

map = Import["GSHHS_c_L1.shp"]

enter image description here

If you are lazy like me, you can just drag the SHP file into the notebook with the mouse.

This gives you a graphics object which you can then manipulate any way you like, for example

Graphics[{EdgeForm[Black], FaceForm[None], Cases[map, _Polygon, Infinity]}]

EDIT Per @Sjoerd's comment you can also use

Import["http://pubs.usgs.gov/of/2006/1187/basemaps/continents/continents.zip", "SHP"]

This is a smaller (much faster to download) dataset.

share|improve this answer
    
Thank you...useful –  Karami Jan 25 '13 at 10:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.