Main Content

创建和显示多边形

Polygons represent geographic objects that cover area, such as continents, islands, and lakes. They may contain holes or multiple regions. Create a polygon by listing vertices that define its boundaries without intersecting. The order of the vertices determines what parts of the polygon are filled. List external boundaries clockwise and internal boundaries counterclockwise, such that the inside of the polygon is always to the right of the boundary.

带有孔的多边形。箭头显示顶点的顺序。

简单多边形

Display a simple polygon with one region and no holes. First, list its vertices in a clockwise order. Close the polygon by repeating the first vertex at the end of the list.

x1 = [0 3 4 1 0];y1 = [0 1 3 2 0];

Display the vertices as a polygon using themapshow通过指定功能'显示类型'作为“多边形”

mapshow(x1,y1,'显示类型',,,,“多边形”

图包含一个轴对象。轴对象包含一个类型补丁的对象。

带有孔或多个区域的多边形

通过将边界分开与多个区域或孔定义多边形值。按顺时针顺序列出外部边界的顶点和逆时针顺序的内部边界的顶点。

x2 = [0 1 8 6 0 nan 1 4 2 1 nan 5 6 7 3 5];y2 = [0 6 8 2 0 nan 1 3 5 1 nan 3 5 7 6 3];

这些向量定义一个具有一个外部边界和两个内边界的多边形。边界使用值。使用该边界的顶点顺序ispolycw功能。这ispolycw当顶点按顺时针顺序排列时,功能返回1。

ispolycw(x2,y2)
ans =1x3 logical array1 0 0

显示多边形。内部边界在多边形内产生孔。

图mapshow(x2,y2,'显示类型',,,,“多边形”

图包含一个轴对象。轴对象包含一个类型补丁的对象。

现在,列出具有两个非电向区域的多边形的顶点。其中一个区域有一个洞。使用使用ispolycw

x3 = [0 1 5 6 0 nan 1 5 4 2 1 nan 7 6 8 8 7];y3 = [0 6 7 2 0 nan 1 3 6 5 1 nan 4 7 8 7 4];ispolycw(x3,y3)
ans =1x3 logical array1 0 1

显示多边形。外部边界创建了两个非电向区域,内部边界会产生一个孔。

图mapshow(x3,y3,'显示类型',,,,“多边形”

图包含一个轴对象。轴对象包含一个类型补丁的对象。

多边形使用地理坐标

In general, you can use geographic coordinates when you define polygons over small regions and call functions such asispolycw。This is true except in cases where the polygon wraps a pole or crosses the Antimeridian.

例如,使用具有地理坐标的多边形在地图上显示密歇根州。首先,阅读状态边界的顶点。

状态= shaperead('usastatehi.shp',,,,'usegeocoords',真的);密歇根州=州(22);lat = michigan.lat;lon = Michigan.lon;

Count the boundaries and verify their vertex order. To useispolycw使用地理坐标,将经度向量列为第一个参数,而纬度向量为第二个参数。1 x-6输出阵列意味着有六个边界。阵列的每个元素都是1,这意味着每个边界都是其自己区域的外部边界。

ispolycw(lon,lat)
ans =1x6 logical array1 1 1 1 1 1

使用Geoshow功能,指定'显示类型'作为“多边形”

USAMAP“密歇根州”Geoshow(Lat,Lon,'显示类型',,,,“多边形”

将多边形夹在皇家国家公园的纬度和经度极限上Maptrimp功能。在新地图上显示剪裁的多边形。

latlim = [47.8 48.2];lonlim = [-89.3 -88.4];[Latt,lont] = Maptrimp(Lat,Lon,Latlim,Lonlim);Figue Usamap(Latlim,Lonlim)Geoshow(Latt,Lont,'显示类型',,,,“多边形”

使用地理坐标的多边形填充区域

When you display a polygon on the Earth, the boundary divides the Earth into two regions. Both of these regions have finite area, so either could be the inside region of the polygon.

As a result, when you project the vertices of a polygon onto a map using theGeoshow功能,填充区域可能与您预期的不同。通过逆转顶点的顺序来更改哪个区域。

例如,在世界地图上显示一个小多边形。

lat2 = [0 10 40 30 0];lon2 = [0 20 30 10 0];图世界图('world')Geoshow(LAT2,LON2,'显示类型',,,,“多边形”

多边形的外部区域被填充。通过应用来扭转顶点的顺序翻动函数到坐标向量。然后,再次显示多边形。

lat2f =翻转(lat2);lon2f = flip(lon2); figure worldmap('world')Geoshow(lat2f,lon2f,'显示类型',,,,“多边形”

这inside region of the polygon is filled instead.

也可以看看

功能

对象