Geoshow colormapping error with makesymbolspec

Hello,
I have a polygon that I built. I want to use colormap to color scale it based on a value on the map. My data consists of Latitude, Longitude and PFD. My goal is to build the polygon with my lat and lon. Then colormap ith with the PFD values. My pfd values range from -160 to -151. I want to color the variation of the pfd inside the polygon. I also want to use a color bar with ticks. So far I am getting an error that I dont quite comprehend and frankly not sure how I can by pass it.
This is my code so far:
filepath = 'C:\path'
Poly_data = xlsread(filepath);
Poly_lat = Poly_data(:,1);
Poly_lon = Poly_data(:,2);
Pfd_value = Poly_data(:,3);
myfig = figure;
hold on
load coastlines
axesm('MapProjection','mercator','MapLatLimit',[-75 75],'MapLonLimit',[-180, 180])
axis off;
gridm on;
framem on;
mlabel('equator')
plabel(0);
plabel('fontweight','bold')
plotm(coastlat,coastlon)
figtitle=['Location: ','Coordination Zone'];
set(myfig,'name',figtitle);
colormap(autumn(512))
Symbols = makesymbolspec('Polygon', ...
{'Pfd',[min(Pfd_value) max(Pfd_value)],'FaceColor',colormap});
k = boundary (Poly_lat, Poly_lon);
finalplot = geoshape(Poly_lat(k),Poly_lon(k));
geoshow(finalplot,'SymbolSpec',Symbols)
colorbar
caxis([min(Pfd_value) max(Pfd_value)])
set (get(colorbar,'YLable'),'String','PFD')
I keep getting this error below. Please help
Error using attributes2properties>checkGeometryStringMatch (line 170)
Geometry value Line is inconsistent with SymbolSpec geometry Polygon.

Answers (1)

Hi, Thank you for your question, the immediate error is likely caused by geoshape(Poly_lat(k),Poly_lon(k)) creating a Line geometry, while the symbol specification expects a Polygon.
First, Specify the geometry explicitly when constructing the geoshape:
k = boundary(Poly_lat, Poly_lon);
finalplot = geoshape(Poly_lat(k), Poly_lon(k), "Geometry", "polygon");
% makesymbolspec maps an attribute of the polygon
finalplot.PFD = mean(Pfd_value(k), "omitnan");
cmap = autumn(512);
Symbols = makesymbolspec("Polygon", {"PFD", [min(Pfd_value) max(Pfd_value)], "FaceColor", cmap});
geoshow(finalplot, "SymbolSpec", Symbols)
colormap(cmap)
caxis([min(Pfd_value) max(Pfd_value)])
cb = colorbar;
cb.Label.String = "PFD";
However, makesymbolspec assigns one color per polygon feature. If Pfd_value varies at individual vertices and you want the color to vary inside the polygon, you must first interpolate or triangulate those values; a single geoshape polygon cannot display vertex-level color variation through makesymbolspec.

Categories

Products

Asked:

on 9 Feb 2021

Answered:

on 3 Sep 2026 at 14:05

Community Treasure Hunt

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

Start Hunting!