Elpezmuerto
Elpezmuerto

Reputation: 5591

Handle warning of "Array is wrong shape or size" when plotting a geopolyshape and setting the ColorData field in MATLAB

MATLAB is throwing a warning and not plotting a geopolyshape when setting the ColorData field; however the shape is plotted when ColorData isn't set. The example code below demonstrates the issue. I am using MATLAB2024b.

Note the latitude and longitude correspond to a H3 resolution 8 hexagon. I don't think the issue is because it's an H3 cell because other H3 cells plot fine with ColorData but I'm sharing for completeness.

So how can I plot this geopolyshape while setting ColorData?

MATLAB Warning:

Warning: Error creating or updating TriangleStrip
 Error in value of property ColorData
 Array is wrong shape or size

Example code

lat = [41.9480823417544; ...
    41.9232620388895; ...
    41.9297343644414; ...
    41.9610354203583; ...
    41.9858827546380; ...
    41.9794019931882; ...
    41.9480823417544];

lon = [-71.5797574810054; ...
    -71.5494225035612; ...
    -71.5033771429879; ...
    -71.4876121649763; ...
    -71.5179362450247; ...
    -71.5640362454369; ...
    -71.5797574810054];


% Create geopolyshape
shape = geopolyshape(lat, lon);

figure;
tiledlayout('flow');
nexttile;
geoplot(shape,'FaceColor','b');
title('works')

nexttile;
geoplot(shape,'FaceColor','flat');
title('works')

nexttile;
geoplot(shape,'FaceColor','flat','ColorData',1);
title('fails and throws warning')

nexttile;
geoplot(shape,'ColorData',5);
title('fails and throws warning')

MATLAB output

Upvotes: 1

Views: 22

Answers (0)

Related Questions