Main Content

Display Vector Data as Lines and Patches

This example shows how to display vector data on axesm-based maps using lines or patches (filled polygons). axesm-based maps enable you to display geographic data using a map projection.

Load data containing the latitude and longitude coordinates for these polygon and line shapes. The data separates individual polygons and lines using NaN values.

  • uslat and uslon — Three polygons representing the conterminous United States, Long Island, and Martha's Vineyard.

  • gtlakelat and gtlakelon — Three polygons representing the Great Lakes.

  • statelat and statelon — Lines representing the borders between states.

load conus

Use the coordinate data to create polygon and line shapes. Combine the shapes into a geospatial table.

us = geopolyshape(uslat,uslon);
gtlake = geopolyshape(gtlakelat,gtlakelon);
states = geolineshape(statelat,statelon);
conusGT = table([us; gtlake; states],VariableNames="Shape")
conusGT=3×1 table


Read a river network into a geospatial table containing line shapes. Clip the line shapes to a region that covers the conterminous United States.

riversGT = readgeotable("worldrivers.shp");

uslatlim = [min(uslat) max(uslat)];
uslonlim = [min(uslon) max(uslon)];
clipped = geoclip(riversGT.Shape,uslatlim,uslonlim);
riversGT.Shape = clipped;

Set up an axesm-based map to display the state coordinates, turning on the map frame, map grid, and the meridian and parallel labels. As conic projections are appropriate for mapping the entire United States, create a map using an Albers equal-area conic projection ( "eqaconic" ). Specifying map limits that contain the region of interest automatically centers the projection on an appropriate longitude. The frame encloses just the mapping area, not the entire globe. As a general rule, you should specify map limits that extend slightly outside your area of interest (worldmap and usamap do this for you). Conic projections need two standard parallels (latitudes at which scale distortion is zero). A good rule is to set the standard parallels at one-sixth of the way from both latitude extremes. Or, to use default latitudes for the standard parallels, simply provide an empty matrix in the call to axesm .

axesm("MapProjection","eqaconic","MapParallels",[], ...
      "MapLatLimit",uslatlim + [-2 2], ...
      "MapLonLimit",uslonlim + [-2 2])
axis off 

Display the area occupied by the conterminous United States as a patch. Note that the order in which add layers to a map can affect visibility because some layers can hide other layers. For example, because some US state boundaries follow major rivers, display the rivers last to avoid obscuring them.

geoshow(conusGT(1,:),"FaceColor",[1 0.5 0.3],"EdgeColor","none")

Display the Great Lakes on top of the land area.

geoshow(conusGT(2,:),"FaceColor","cyan", "EdgeColor","none")

Display the line shapes containing state boundaries.


Display the river network.



  • To plot data that is already in projected coordinates, use a regular axes object and the mapshow function.

  • Starting in R2022a, you can create a similar plot by using geographic axes and the geoplot function. Geographic axes enable you to specify basemaps, change the geographic limits, and interactively pan and zoom. The geoplot function accepts shapes with coordinates in any supported projected or geographic coordinate reference system (CRS) and displays the data into a Web Mercator map projection.

geoplot(conusGT(1,:),"FaceColor",[1 0.5 0.3],"EdgeColor","none")
hold on
geobasemap topographic

Figure contains an axes object. The axes object contains 4 objects of type polygon, line.

See Also



Related Topics