attach a field to a shapefile and plot it

조회 수: 13 (최근 30일)
Sourangsu Chowdhury
Sourangsu Chowdhury 2018년 9월 26일
댓글: Kelly Kearney 2018년 9월 27일
I have a shapefile of India with state boundaries (34 polygons within the India shapefile).See the attached screenshot and the shapefile as .zip. I want to attach the mean rainfall data in a separate feild to each state in the shapefile and plot it in matlab, I am familiar with dealing with shapefiles in arcgis but would like to perform it in matlab as well.

채택된 답변

Kelly Kearney
Kelly Kearney 2018년 9월 26일
Do you need to actually add a new field to the shapefiles themselves? Or just add it to the read-in structure in Matlab?
If the latter, you can easily assign new fields and values to your structure
India = shaperead('~/Downloads/shp/naturalearth_india_adm1.shp', 'usegeocoords', true);
for ii = 1:numel(India)
India(ii).rain = rand(1); % add your data here
end
You can plot shapefiles colored by a property by using the (extremely clunky, IMO) symbol spec parameter to geoshow:
spec = makesymbolspec('Polygon', ...
{'Shape_Area', [-11 31], 'Facecolor', parula})
geoshow(India, 'SymbolSpec', spec);
In this example, I've used the area of each polygon as the color-mapping data, but you can adjust it as needed. The down side to this plotting method is that the colors don't correspond to the colormap at all, so you need to manually sync your color limits to match the spec if you plan to use a colorbar or plot other data on the same color scale.
If you need more control over the output, you can instead plot without the symbol spec and set the CData property of the resulting patches:
h = geoshow(India);
set(h.Children, {'CData'}, {India.Shape_Area}');
set(h.Children, 'Facecolor', 'flat');
Using this method will link the patch color to the axis color limits and colorbar. Which behavior you prefer may depend on your application.
  댓글 수: 2
Sourangsu Chowdhury
Sourangsu Chowdhury 2018년 9월 27일
편집: Sourangsu Chowdhury 2018년 9월 27일
@Kelly Kearney Thank you for the help. I would ideally need to display the output as binned colors like for india.shp_area, 0-10 should have one uniform color, 11-20 should have a different color and so on.
Kelly Kearney
Kelly Kearney 2018년 9월 27일
Take a look at Example 3 (Using a Range of Attribute Values) in the makesymbolspec documenatation.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by