wmpolygon
Display geographic polygon on web map
Description
wmpolygon(
displays a polygon overlay based on the
vector geographic features stored in P
)P
. The overlay contains
one polygon feature for each element of P
.
wmpolygon(
displays
the overlay in the web map specified by the web map handle, wm
,___)wm
.
wmpolygon(___,
specifies
name-value pairs that set additional display properties.Name,Value
)
returns
a handle to the overlay.h
= wmpolygon(___)
Examples
Display Coastlines as Polygon
Load coastline data from a MAT-file.
load coastlines
Display the coastlines as a polygon overlay layer.
wmpolygon(coastlat,coastlon,'OverlayName','Polygon coastlines')
Display Polygon with Inner Ring
Define coordinates of rings. For this example, the coordinates define a location centered on the Eiffel Tower.
lat0 = 48.858288; lon0 = 2.294548; outerRadius = .01; innerRadius = .005; [lat1,lon1] = scircle1(lat0,lon0,outerRadius); [lat2,lon2] = scircle1(lat0,lon0,innerRadius); lat2 = flipud(lat2); lon2 = flipud(lon2); lat = [lat1; NaN; lat2]; lon = [lon1; NaN; lon2];
Display on a web map.
webmap('worldimagery') wmpolygon(lat,lon,'EdgeColor','g','FaceColor','c','FaceAlpha',.5)
Display USA State Boundaries Using Political Colormap
Import a shapefile containing state boundary data as a geospatial table.
GT = readgeotable("usastatelo.shp");
Create a colormap from random, muted colors.
colors = polcmap(height(GT));
Display the polygons as an overlay on a web map. Make the polygons semitransparent by using the FaceAlpha
name-value argument.
webmap("worldphysicalmap") wmpolygon(GT,"FaceColor",colors,"FaceAlpha",0.5,"EdgeColor","k", ... "EdgeAlpha",0.5,"OverlayName","USA Boundary","FeatureName",GT.Name)
Display Reduced High Resolution Polygon Data on Web Map
Large data sets can sometimes be slow to display, making the web map appear to hang. This example shows how to reduce the size of a data set using reducem
before calling wmpolygon
.
First, load high-resolution vector data into the workspace.
states = shaperead('usastatehi.shp','UseGeoCoords',true); states = geoshape(states);
Then, reduce the number of points in the latitude and longitude vectors using the reducem
function.
for k = 1:length(states) [states(k).Latitude, states(k).Longitude] = reducem( ... states(k).Latitude', states(k).Longitude'); end
Display state boundaries on the web map. Note that the borders of the reduced polygons may not meet if you zoom in on them.
colors = polcmap(length(states)); webmap('worldphysicalmap') wmpolygon(states,'FaceColor',colors,'FaceAlpha',.5,'EdgeColor','k', ... 'EdgeAlpha',.5,'OverlayName','USA Boundary','FeatureName',states.Name)
Input Arguments
lat
— Latitude vertices
matrix in the range [-90, 90]
Latitude vertices, specified as matrix in the range [-90, 90].
Data Types: single
| double
lon
— Longitude vertices
matrix
Longitude of vertices, specified as a matrix.
Data Types: single
| double
P
— Geographic features
geospatial table | geoshape
vector
Geographic features, specified as one of the following:
A geospatial table containing
geopolyshape
objects. For more information about geospatial tables, see Create Geospatial Tables.A
geoshape
vector with polygon geometry.
wm
— Web map
handle to a web map
Web map, specified as a handle to a web map.1
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: wmpolygon(lat,lon,'Autofit',true)
Autofit
— Overlay visibility
true (default) | false
Overlay visibility, specified as the comma-separated pair consisting
of 'Autofit'
and the scalar logical or numeric
value true
(1
) or false
(0
).
If
true
,wmpolygon
adjusts the spatial extent of the map to ensure that all the vector overlays on the map are visible.If
false
,wmpolygon
does not adjust the spatial extent of the map when this vector layer is added to the map.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Description
— Description of feature
empty character vector (default) | character vector | cell array of character vectors | scalar structure
Description of feature, specified as the comma-separated pair
consisting of 'Description'
and a character vector,
cell array of character vectors, or a scalar structure.
If you specify a character vector, the text defines the content displayed in the description balloon, which appears when you click the feature in the web map. Description elements can be either plain text or marked up with HTML markup.
If you specify a cell array, it must be either a scalar or the same length as
P
, and specifies the description for each polygon.If the value is a structure (attribute specification),
wmpolygon
displays the attribute fields ofP
in the balloon, modified according to the specification.
Data Types: char
| struct
| cell
OverlayName
— Name of overlay layer
'Polygon Overlay N
'
, (default) | character vector
N
'Name of overlay layer, specified as the comma-separated pair consisting of
'OverlayName'
and a character vector.
wmpolygon
inserts the name in the Layer Manager
under the "Overlays" item. The Layer Manager is the tool that appears on
the right side of the web map. The default name is 'Polygon
Overlay
where
N
'N
is the number assigned to this
overlay.
Data Types: char
FeatureName
— Name of feature
'OverlayName
:
Line K
'
(default) | character vector | cell array of character vectors
OverlayName
:
Line K
'Name of feature, specified as the comma-separated pair consisting
of 'FeatureName'
and character vector or cell array
of character vectors. The name appears in the balloon when you click
the feature in the web map. The default value is '
, where OverlayName
:
Polygon K
'OverlayName
is
the name of the overlay and K
is the number
assigned to the particular polygon.
If the value is a character vector, it applies to all features.
If the value is a cell array of character vectors, it must be either a scalar or the same length as
P
.
Data Types: char
| cell
FaceColor
— Color of polygon faces
'black'
(default) | color name | RGB triplet | cell array of color names | string vector of color names | matrix of RGB triplets | 'none'
Color of polygon faces, specified as the comma-separated pair
consisting of 'FaceColor'
and one of these options.
A color name such as
'red'
or a short name such as'r'
.An RGB triplet, which is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range
[0,1]
; for example,[0.4 0.6 0.7]
.A cell array of color names such as
{'red','green','blue'}
or{'r','g','b'}
.A string vector of color names such as
["red" "green" "blue"]
or["r" "g" "b"]
.A matrix of RGB triplets, which is a three-column matrix in which each row is an RGB triplet.
The way you specify the color depends on the desired color scheme.
To apply the same face color to all polygons in
P
, specify a single color name or RGB triplet.To apply a different color to each polygon in
P
, specify a cell array of color names, a string vector of color names, or a matrix of RGB triplets. The number of colors and RGB triplets must match the length ofP
.To create polygons with no fill, specify
'none'
.
This table contains the color names and equivalent RGB triplets for some common colors.
Color Name | Short Name | RGB Triplet | Appearance |
---|---|---|---|
"red" | "r" | [1 0 0] |
|
"green" | "g" | [0 1 0] |
|
"blue" | "b" | [0 0 1] |
|
"cyan"
| "c" | [0 1 1] |
|
"magenta" | "m" | [1 0 1] |
|
"yellow" | "y" | [1 1 0] |
|
"black" | "k" | [0 0 0] |
|
"white" | "w" | [1 1 1] |
|
Data Types: char
| string
| cell
| double
FaceAlpha
— Transparency of polygon faces
1
(default) | numeric scalar or vector in the range [0, 1]
Transparency of polygon faces, specified as the comma-separated pair consisting of
'FaceAlpha'
and a numeric scalar or vector in the
range [0, 1]. The default value, 1
, means that the
polygon is fully opaque.
If the value is a scalar, it applies to all polygon faces.
If the value is a vector, it must be the same length as
P
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
EdgeColor
— Color of polygon edges
'none'
(default) | color name | RGB triplet | cell array of color names | string vector of color names | matrix of RGB triplets | 'none'
Color of polygon edges, specified as the comma-separated pair
consisting of 'EdgeColor'
and one of these options.
A color name such as
'red'
or a short name such as'r'
.An RGB triplet, which is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range
[0,1]
; for example,[0.4 0.6 0.7]
.A cell array of color names such as
{'red','green','blue'}
or{'r','g','b'}
.A string vector of color names such as
["red" "green" "blue"]
or["r" "g" "b"]
.A matrix of RGB triplets, which is a three-column matrix in which each row is an RGB triplet.
The way you specify the color depends on the desired color scheme.
To apply the same edge color to all polygons in
P
, specify a single color name or RGB triplet.To apply a different edge color to each polygon in
P
, specify a cell array of color names, a string vector of color names, or a matrix of RGB triplets. The number of colors and RGB triplets must match the length ofP
.To create polygons with no edge color, specify
'none'
.
This table contains the color names and equivalent RGB triplets for some common colors.
Color Name | Short Name | RGB Triplet | Appearance |
---|---|---|---|
"red" | "r" | [1 0 0] |
|
"green" | "g" | [0 1 0] |
|
"blue" | "b" | [0 0 1] |
|
"cyan"
| "c" | [0 1 1] |
|
"magenta" | "m" | [1 0 1] |
|
"yellow" | "y" | [1 1 0] |
|
"black" | "k" | [0 0 0] |
|
"white" | "w" | [1 1 1] |
|
Data Types: char
| string
| cell
| double
EdgeAlpha
— Transparency of polygon edges
1
(default) | numeric scalar or vector in the range [0, 1]
Transparency of polygon edges, specified the comma-separated pair consisting of
'EdgeAlpha'
and as a numeric scalar or vector in
the range [0, 1].
If the value is a scalar, it applies to all polygon faces.
If the value is a vector, it must be the same length as
P
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
LineWidth
— Width of polygon edges
1 (default) | positive numeric scalar or vector
Width of polygon edges, specified as the comma-separated pair
consisting of 'LineWidth'
and a positive numeric
scalar or vector.
If the value is a scalar, it applies to all polygon faces.
If the value is a vector, it must be the same length as
P
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Output Arguments
h
— Polygon overlay
handle to polygon overlay
Polygon overlay, returned as a handle to the polygon overlay.
Tips
When you move the cursor over the polygons you define on an image and click,
wmpolygon
displays a description balloon and disables panning. If you move the cursor off the polygon, you can still click and pan the image. You can also use the arrow keys to pan the image.
Version History
Introduced in R2016aR2021b: Display data from geospatial tables
The wmpolygon
function accepts geospatial tables as
input.
See Also
Functions
Objects
1 Alignment of boundaries and region labels are a presentation of the feature provided by the data vendors and do not imply endorsement by MathWorks®.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)