我想达到以下结果:
正如您所看到的,我想修补整个地图,不包括源自位置A和位置B的small circles联合所形成的区域。
位置A和B具有以下坐标(以度为单位):
% Coordinates.
A = [43.6350000000000, 1.36777777777778];
B = [52.7019444444445, -8.92472222222222];
我使用scircle1
函数获取小圆圈的坐标。两个小圆的半径都是654海里:
% Small circles from center, range, and azimuth.
RangeNM = 654;
[latcA, loncA] = scircle1(A(1), A(2), RangeNM, [], earthRadius('nm'));
[latcB, loncB] = scircle1(B(1), B(2), RangeNM, [], earthRadius('nm'));
补丁的内部轮廓是由两个小圆圈的union的坐标形成的周长。我使用polybool
函数获取坐标:
% Set operations on polygonal regions.
[latU, lonU] = polybool('union', latcA, loncA, latcB, loncB);
补丁的外部轮廓是由地图的纬度和经度限制形成的周界。我使用getm
获取地图的MapLatLimit
和MapLonLimit
属性。从上图可以看出,LatLim = [30, 70]
(30°N到70°N)和LonLim = [-30, 20]
(30°W到20°E):
% Get Map Latitude and Longitude limit.
LatLim = getm(gca, 'MapLatLimit');
LonLim = getm(gca, 'MapLonLimit');
最后,我尝试使用patchm
函数创建补丁,这相当于映射的补丁函数。这是我遇到问题的地方。我尝试了三种不同的方法,但没有一种是成功的:
% APPROACH 1
lat = {[LatLim(1) LatLim(2) LatLim(2) LatLim(1) LatLim(1)], latU};
lon = {[LonLim(1) LonLim(1) LonLim(2) LonLim(2) LonLim(1)], lonU};
% Compute face and vertex matrices.
[f, v] = poly2fv(lat, lon);
patchm('Faces', f, 'Vertices', v, 'FaceColor', [.5 .5 .5], 'FaceAlpha', 0.4); %Doesn't work
% APPROACH 2
lat = {[LatLim(1) LatLim(2) LatLim(2) LatLim(1) LatLim(1)], latU};
lon = {[LonLim(1) LonLim(1) LonLim(2) LonLim(2) LonLim(1)], lonU};
% Compute face and vertex matrices.
[f, v] = poly2fv(lat, lon);
patchm(v(:,1), v(:,2), 'FaceColor', [.5 .5 .5], 'FaceAlpha', 0.4); % Doesn't work
% APPROACH 3
lat = [latU', LatLim(1), LatLim(2), LatLim(2), LatLim(1), LatLim(1)];
lon = [lonU', LonLim(1), LonLim(1), LonLim(2), LonLim(2), LonLim(1)];
patchm(lat, lon, 'FaceColor', [.5 .5 .5], 'FaceAlpha', 0.4); % Doesn't work
我非常感谢你的帮助。
我在poly2fv
函数的文档页面中找到了一个非常好的带孔的补丁示例。但是,该示例使用标准patch
函数和笛卡尔坐标(x,y)。请注意,使用了patch('Faces', f, 'Vertices', v,...
。我试图使用patchm
函数和地理坐标(lat,lon)复制同一个例子。
注意:此代码需要Mapping Toolbox。
% Read vector features and attributes from shapefile.
landareas = shaperead('landareas.shp', 'UseGeoCoords', true);
% Define map axes and set map properties.
axesm ('lambert',...
'MapLonLimit', [-30 20],...
'MapLatLimit', [30 70],...
'MapParallels', [38.00555556 71.01111111],...
'Frame', 'on',...
'FLineWidth', 1,...
'Grid', 'on',...
'GLineStyle', '-',...
'GLineWidth', 0.1,...
'GColor', [.7 .7 .7]);
% Display map latitude and longitude data.
geoshow(landareas, 'FaceColor', [1 1 .5], 'EdgeColor', [.3 .3 .3]);
% Toggle and control display of graticule lines.
gridm('MLineLocation', 5,...
'MLabelLocation', 5,...
'PLineLocation', 5,...
'PLabelLocation', 5);
% Toggle and control display of meridian labels.
mlabel on;
% Toggle and control display of parallel labels.
plabel on;
axis off;
% Coordinates.
A = [43.6350000000000, 1.36777777777778];
B = [52.7019444444445, -8.92472222222222];
% Plot A.
plotm(A(1), A(2), '.r');
textm(A(1), A(2)+1, 'A');
% Plot B.
plotm(B(1), B(2), '.r');
textm(B(1), B(2)+1, 'B');
% Small circles from center, range, and azimuth.
RangeNM = 654;
[latcA, loncA] = scircle1(A(1), A(2), RangeNM, [], earthRadius('nm'));
[latcB, loncB] = scircle1(B(1), B(2), RangeNM, [], earthRadius('nm'));
% Set operations on polygonal regions.
[latU, lonU] = polybool('union', latcA, loncA, latcB, loncB);
% Get Map Latitude and Longitude limit.
LatLim = getm(gca, 'MapLatLimit');
LonLim = getm(gca, 'MapLonLimit');
% APPROACH 1
lat = {[LatLim(1) LatLim(2) LatLim(2) LatLim(1) LatLim(1)], latU};
lon = {[LonLim(1) LonLim(1) LonLim(2) LonLim(2) LonLim(1)], lonU};
% Compute face and vertex matrices.
[f, v] = poly2fv(lat, lon);
patchm('Faces', f, 'Vertices', v, 'FaceColor', [.5 .5 .5], 'FaceAlpha', 0.4); % Doesn't work
% APPROACH 2
lat = {[LatLim(1) LatLim(2) LatLim(2) LatLim(1) LatLim(1)], latU};
lon = {[LonLim(1) LonLim(1) LonLim(2) LonLim(2) LonLim(1)], lonU};
% Compute face and vertex matrices.
[f, v] = poly2fv(lat, lon);
patchm(v(:,1), v(:,2), 'FaceColor', [.5 .5 .5], 'FaceAlpha', 0.4); % Doesn't work
% APPROACH 3
lat = [latU', LatLim(1), LatLim(2), LatLim(2), LatLim(1), LatLim(1)];
lon = [lonU', LonLim(1), LonLim(1), LonLim(2), LonLim(2), LonLim(1)];
patchm(lat, lon, 'FaceColor', [.5 .5 .5], 'FaceAlpha', 0.4); % Doesn't work
答案 0 :(得分:1)
似乎patchm
忽略了漏洞。解决方法是将周围的多边形分成两部分,以便区域的并集与两者重叠。然后从北部和南部补丁中减去该区域,绘制两个部分,并添加一个很好的边缘:
% Find a point where we can split the polygon
split_lat = median(latU);
% generate northern patch
p_up_lt = [split_lat LatLim([2 2]) split_lat];
p_up_lg = LonLim([1 1 2 2]);
[lonAup, latAup] = polybool('-', p_up_lg, p_up_lt, lonU, latU);
% and plot it, with invisible edge
p_up = patchm(latAup, lonAup, 'FaceColor', [.5 .5 .5], 'FaceAlpha', 0.4, 'EdgeColor', 'none');
% generate and plot southern patch
p_dn_lt = [LatLim(1) split_lat split_lat LatLim(1)];
p_dn_lg = LonLim([1 1 2 2]);
[lonAdn, latAdn] = polybool('-', p_dn_lg, p_dn_lt, lonU, latU);
p_dn = patchm(latAdn, lonAdn, 'FaceColor', [.5 .5 .5], 'FaceAlpha', 0.4, 'EdgeColor', 'none');
% plot edge for the union
p_e = patchm(latU, lonU, 'FaceColor', 'none', 'FaceAlpha', 0.4);