Mapping toolbox patch color issue

5 views (last 30 days)
Petre
Petre on 17 Jul 2014
Commented: Petre on 22 Jul 2014
Hi all,
I am currently trying to display a map using the mapping toolbox. The latitude and longitude data was extracted from Geodas Coastline Extractor vector form easily loaded into the workspace. The script I wrote does what it should with the exception that when I try to patch a color into the polygon defined by the vector Matlab colors everything except the polygon with that particular color. The output figure is shown below. In other words I would like to have a white background while the landarea should be grey. The code is shown below as well. I've tried fillm, patchm and geoshow all with the same result. It should be something simple but I find myself stuck. Any help would be greatly appreciated.
My code is the following:
h1 = figure;
h = worldmap({'Europe','North America'});
axesm('MapProjection','stereo','MapLatLimit',[45 90],'FLatLimit',... [-Inf 45],'Origin',[90 -20 0]);
framem('off'); set(h,'color','w'); set(h1,'color','w'); setm(h,'Grid','on');
setm(h,'PLineLocation',2,'MLineLocation',2);
setm(h,'MLineLimit',[30 85],'MLineException',[-180 -135 -90 -45 0 45 90 135 180]); setm(h,'MeridianLabel','on','MLabelLocation',-180:10:180,'MLabelParallel',... 30,'LabelFormat','none','LabelRotation','on','FontSize',7);
setm(h,'ParallelLabel','on','PLabelLocation',[90 80 70 60 50 40 20 10 0],'PLabelMeridian',... 0,'LabelFormat','none','LabelRotation','on','FontSize',7); latlim = [50 90]; longlim = [-80 10];
[linelat,linelong] = maptriml(BirdMedium_shore(:,2),BirdMedium_shore(:,1),latlim,longlim);
%fillm(BirdMedium_shore(:,2),BirdMedium_shore(:,1), [0.66 0.66 0.66]);
%patchm(linelat,linelong,[1 1 1;0.66 0.66 0.66]);
geoshow(linelat,linelong,'DisplayType','Polygon','FaceColor',[0.66 0.66 0.66],'EdgeColor','none'); tightmap

Answers (1)

Kelly Kearney
Kelly Kearney on 17 Jul 2014
Edited: Kelly Kearney on 17 Jul 2014
Plotting patches in map axes can be a real pain. I think it's because of the way patches are trimmed at map boundaries, though I can't be quite sure on that. What I am sure of is that patched coastlines almost never get color-filled properly using either patchm, patchesm, or geoshow... specially when you throw a stereographic projection into the mix.
The only method I've found to really force these types of patches to be shaded properly is to triangulate the polygons first. It's not an ideal solution, particularly is you're using hi-res coastlines, because plotting a patch with a few hundred thousand facets can take several minutes. But it gets the job done.
% The coastline data (replace with yours)
C = gshhs(gshhsfile('c'));
lon = [C.Lon];
lat = [C.Lat];
% Setup figure and axes
h.fig = figure('color', 'w');
h.ax = axes('position', [0 0 1 1]);
h.ax = axesm('stereo', ...
'origin', [90 -20 0], ...
'frame', 'on', ...
'grid', 'on', ...
'maplatlimit', [45 90]);
set(.hax, 'visible', 'off');
% Convert polygons to triangle mesh
[lat, lon] = maptrimp(lat, lon, [45 90], [-180 180]);
[f,v] = poly2fv(lon, lat);
vlat = v(:,2);
vlon = v(:,1);
plat = vlat(f');
plon = vlon(f');
plat = [plat; nan(1,size(plat,2))];
plon = [plon; nan(1,size(plon,2))];
plat = plat(:);
plon = plon(:);
[plat, plon] = interpm(plat, plon, 1);
% Plot
h.ln = plotm(lat, lon, 'k');
h.p = patchm(plat, plon, ones(1,3)*0.66);
set(h.p, 'edgecolor', 'none');
The poly2fv command tends to create a lot of really long, thin patches, hence the need for the interpm command. For regions that I plot often, I actually use a different meshing algorithm that creates an unstructured triangular mesh (a slight modification of this)... better for plotting but much more intensive to set up.
  1 Comment
Petre
Petre on 22 Jul 2014
Thank you for the reply. I'm still having some trouble with this but hopefully I'll figure it out.

Sign in to comment.

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!