www.gusucode.com > map 案例源码 matlab代码程序 > map/CalculateContourLinesAndPolygonsForAreaNearHawaiiExample.m

    %% Calculate Contour Lines and Polygons for Area Near Hawaii
% 
%%
% Define a set of _X_ and _Y_ coordinates and create contour lines and
% contour polygons.
X = -150000:10000:150000;
Y =  0:10000:300000;
[xmesh, ymesh] = meshgrid(X/50000, (Y - 150000)/50000);
Z = 8 + peaks(xmesh, ymesh);
lat0 = dm2degrees([  21 18]);
lon0 = dm2degrees([-157 49]);
h0 = 300;
levels = 0:2:18;

[contourLines, contourPolygons] = geocontourxy(X,Y,Z,lat0,lon0,h0, ...
        'LevelList',levels,'XYRotation',120)
%%
% Display Hawaii on a map, add a marker, and then display the polygons
% returned by |geocontourxy| on the map.
figure
usamap([18.5 22.5],[-161 -154])
hawaii = shaperead('usastatehi', 'UseGeoCoords', true,...
        'Selector',{@(name) strcmpi(name,'Hawaii'), 'Name'});
geoshow(hawaii)
geoshow(lat0,lon0,'DisplayType','point','Marker','o',...
        'MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',10)
 
cmap = parula(1 + length(levels));
for k = 1:length(contourPolygons)
      lat = contourPolygons(k).Latitude;
      lon = contourPolygons(k).Longitude;
      geoshow(lat,lon,'Display','polygon', ...
             'FaceColor',cmap(k,:),'FaceAlpha',0.5,'EdgeColor','none')
end
geoshow(contourLines.Latitude,contourLines.Longitude,'Color','black')