MATLAB: Does GEOSHOW produce an error in Mapping Toolbox 2.7.1 (R2008b) and later but not in previous versions

MATLAB

I have a problem with GEOSHOW. My code works in Mapping Toolbox versions R14SP3 through R2008a but errors out in R2008b and later. Here is the error:
??? Error using ==> trimPolygonToQuadrangle>mergeEndToEndPairs at 221
Inconsistent polygon topology: Encountered a chain of more than two connecting pairs.
Error in ==> trimPolygonToQuadrangle>trimLongitudes at 111
[lon, lat] = mergeEndToEndPairs(lon, lat, lonlim, tolSnap);
Error in ==> trimPolygonToQuadrangle at 45
[lat, lon] = trimLongitudes(lat, lon, lonlim, tolSnap);
Error in ==> applyProjection>applyForward at 62
[lat, lon] = trimPolygonToQuadrangle( ...
Error in ==> doApplyProj at 31
[x, y, savepts] = mproj.applyForward(mproj, mstruct, in1, in2, objectType);
Error in ==> applyProjection at 14
outputs = doApplyProj(mproj, varargin{:});
Error in ==> lambert at 30
varargout = applyProjection(mproj, varargin{:});
Error in ==> geovec at 21
[x, y] = feval(projName, mstruct, lat, lon, objectType, 'forward');
Error in ==> geostructshow>@(s,varargin)geovec(mstruct,s.Lat,s.Lon,objectType,fcn,varargin{:}) at 143
h = symbolizeMapVectors(S, symspec, @(s, varargin) ...
Error in ==> symbolizeMapVectors>plotMapFeature at 128
h = plotfcn(s, props{:});
Error in ==> symbolizeMapVectors at 116
hg = plotMapFeature(S(k), hg, props, plotfcn);
Error in ==> geostructshow at 143
h = symbolizeMapVectors(S, symspec, @(s, varargin) ...
Error in ==> geoshow at 256
h = showFcn(varargin{:});
Error in ==> snake_shp_bug at 21
geoshow(ax,snake,'EdgeColor','r','FaceColor','n');
Here is the relevant part of my code:
snake = shaperead(...
'integrate.shp',...
'UseGeoCoords', true, 'BoundingBox',[lonlim', latlim']);
geoshow(ax,snake,'EdgeColor','r','FaceColor','n');

Best Answer

In MATLAB 7.7 (R2008b), trimming became cleaner and more robust in many ways but also somewhat more sensitive to polygons with invalid topology. For example, a single polygon should not wrap on itself. That is probably what is happening here. In general the solution would be to do some data clean-up up front and it is not always clear how to do this.
For this particular situation change the GEOSHOW call to the following:
geoshow(ax, [snake.Lat], [snake.Lon], 'Color', 'r');
Your code is calling GEOSHOW with a polygon input but with 'FaceColor' set to 'none'. Since the FaceColor is not needed, you can treat the data as lines and they will trim as expected.