This example shows how to display vector maps as lines or patches (filled-in polygons). Mapping Toolbox functions let you display patch vector data that uses NaNs to separate closed regions.
Use the who
command to examine the contents of the conus
(conterminous U.S.) MAT-file and then load it into the workspace. Vector map data for lines or polygons can be represented by simple coordinate arrays, geostructs, or mapstructs. The variables uslat
and uslon
together describe three polygons (separated by NaNs) the largest of which represent the outline of the conterminous United States. The two smaller polygons represent Long Island, NY, and Martha's vineyard, an island off Massachusetts. The variables gtlakelat
and gtlakelon
describe three polygons (separated by NaNs) for the Great Lakes. The variables statelat
and statelon
contain line-segment data (separated by NaNs) for the borders between states, which is not formatted for patch display.
who -file conus.mat
Your variables are: description gtlakelon statelat uslat gtlakelat source statelon uslon
load conus
Verify that line and polygon data contains NaNs (hence multiple objects).
find(isnan(gtlakelon))
ans = 3×1
881
1056
1227
Read the worldrivers
shapefile for the region that covers the conterminous United States.
uslatlim = [min(uslat) max(uslat)]
uslatlim = 1×2
25.1200 49.3800
uslonlim = [min(uslon) max(uslon)]
uslonlim = 1×2
-124.7200 -66.9700
rivers = shaperead('worldrivers', 'UseGeoCoords', true, ... 'BoundingBox', [uslonlim', uslatlim'])
rivers=23×1 struct array with fields:
Geometry
BoundingBox
Lon
Lat
Name
Note that the Geometry
field specifies whether the data is stored as a Point
, MultiPoint
, Line
, or Polygon
.
rivers(1).Geometry
ans = 'Line'
Set up a map axes 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 axes object 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
.
figure axesm('MapProjection', 'eqaconic', 'MapParallels', [], ... 'MapLatLimit', uslatlim + [-2 2], ... 'MapLonLimit', uslonlim + [-2 2]) axis off; framem; gridm; mlabel; plabel
Plot a patch to display the area occupied by the conterminous United States. Use the geoshow
function with DisplayType
set to 'polygon'
. 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 U.S. state boundaries follow major rivers, display the rivers last to avoid obscuring them.
geoshow(uslat,uslon, 'DisplayType','polygon','FaceColor',... [1 .5 .3], 'EdgeColor','none')
Plot the Great Lakes on top of the land area, using geoshow
.
geoshow(gtlakelat,gtlakelon, 'DisplayType','polygon',... 'FaceColor','cyan', 'EdgeColor','none')
Plot the line segment data showing state boundaries, using geoshow
with DisplayType
set to 'line'
.
geoshow(statelat,statelon,'DisplayType','line','Color','k')
Use geoshow
to plot the river network. Note that you can omit DisplayType
geoshow(rivers, 'Color', 'blue')