Tuesday, May 13, 2014

Northeast region map

Basic code in matlab to create northeast states.

latlim = [ 35  48];
lonlim = [-85 -65];

% want states
ilatlim = [ 37  46];
ilonlim = [-80 -69];


figure
ax = usamap(latlim,lonlim);
 axis off

% axesm('MapProjection','conic')
 % The Lambert Conformal Conic Projection is often used for maps of the conterminous United States.
% Here is the map projection usamap selected:
% getm(gca,'MapProjection')

% ans =
% lambert
% Next, use shaperead to read U.S. state polygon boundaries from the usastatehi shapefile into a geostruct named states:
states = shaperead('usastatehi',...
    'UseGeoCoords', true, 'BoundingBox', [ilonlim', ilatlim']);
% Make a symbolspec to create a political map using the polcmap function:
faceColors = makesymbolspec('Polygon',...
    {'INDEX', [1 numel(states)], ...
    'FaceColor', polcmap(numel(states))});
% Display the filled polygons with geoshow:
geoshow(ax, states, 'SymbolSpec', faceColors)
% Extract the names for states within the window from the geostruct and use textm to plot them at the label points provided by the geostruct:
for k = 1:numel(states)
  labelPointIsWithinLimits =...
    37 < states(k).LabelLat &&...
    latlim(2) > states(k).LabelLat &&...
    -82.5 < states(k).LabelLon &&...
    lonlim(2) > states(k).LabelLon;
  if labelPointIsWithinLimits
    textm(states(k).LabelLat,...
    states(k).LabelLon, states(k).Name, ...
        'HorizontalAlignment', 'center', 'FontSize', 15)
  end
end
 
tightmap

No comments: