Problem getting polygons for NY state?

1 回表示 (過去 30 日間)
Amato
Amato 2014 年 5 月 28 日
コメント済み: Amato 2014 年 5 月 29 日
I have an image of a CONUS map I made via geoshow:
ax = usamap('conus');
states = shaperead('usastatelo', 'UseGeoCoords', true,'Selector',...
{@(name) ~any(strcmp(name,{'Alaska','Hawaii'})), 'Name'});
faceColors = makesymbolspec('Polygon',{'INDEX', [1 numel(states)],...
'FaceColor',repmat([114 132 153]/255,numel(states),1)});
gs = geoshow(ax, states, 'DisplayType', 'polygon','SymbolSpec', faceColors);
I am replacing the colors of individual states and exporting these states' vector boundaries so I can make each a "clickable" region on a website (via an image-map). This works fine for almost all the states. For example,
gs = geoshow(ax,'Utah')
x=get(get(gs,'Children'),'Xdata');
y=get(get(gs,'Children'),'Ydata');
If I do plot(x,y) I get a nice image of the outline of Utah. However, for some reason this isn't working for New York. Here x and y are 2-dimension arrays, size = (3,298), and the points are not in a logical order; they criss-cross the state and do not make a nice outline.
Anyone here know why NY state is different, and how to reorder the x and y arrays to make a nice polygon?
Thanks!!!
  1 件のコメント
Sara
Sara 2014 年 5 月 28 日
Can you attach the data?

サインインしてコメントする。

採用された回答

Sara
Sara 2014 年 5 月 29 日
The second part of the code didn't work for me, so I replaced it with this and I get a nice contour:
k = struct2cell(states);
names = k(5,:);
index = find(strcmp(names,'New York')==1);
x = states(index).Lon;
y = states(index).Lat;
figure
plot(x,y)
  1 件のコメント
Amato
Amato 2014 年 5 月 29 日
I knew there must have been an easier way! Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by