To usa counties and state mape and shade with different color

3 views (last 30 days)
Dipak Dulal
Dipak Dulal on 29 Nov 2021
Commented: Dipak Dulal on 29 Nov 2021
Hi,
I am working on a project and basically, I'm trying to import a map of US with counties in deffernet states marked on it. my purpose is to add data about each county, specifically about the concentration of spread of Covid cases.US. Then, I want to give each county a certain shade of color based on the concentration.
Does Matlab have a feature which can detect the counties on a map? if so, can each element (county) store data and be assigned individual colors?
I am experienced in Matlab and have coded a lot of numerical analysis projects before. This is a side project, and I've never worked with image importing and detection in Matlab, which is why I'm asking.
Thank You
  1 Comment
Star Strider
Star Strider on 29 Nov 2021
It will likely be necessary to use the Mapping Toolbox for this project, and specifically use Web Map Service. The U.S. CDC Covid Data Tracker should be able to provide the information, however it may require a bit of exploration to find the source of the data in a usable, numeric form that can be downloaded.
I do not have the Mapping Toolbox (my only experience with it is the online Run feature here) however I am certain others have extensive experience with it and will likely be able to help.
Post back here when it works satisfactorily, and consider uploading it to the File Exchange as well, since COVID is going to be with us for a few years. SARS-CoV-2 is an unstable virus, mutates readily, and so will circulate widely until a large enough fraction of the population has broad-based natural immunity to it to stop its spread.

Sign in to comment.

Accepted Answer

Chunru
Chunru on 29 Nov 2021
Edited: Chunru on 29 Nov 2021
warning off
states = shaperead( 'usastatehi.shp'); % MATALB comes with usa states map .shp file
You can download the county level map from:
% Extract the polygons in the .shp file
struct2poly = @(s) polyshape(s.X, s.Y);
p = arrayfun(struct2poly, states);
plot(p)
% to specify the color for each state
figure; hold on
plot(p(1), 'FaceColor', 'r');
plot(p(2), 'FaceColor', 'g');
plot(p(3), 'FaceColor', 'b'); % and so on
  3 Comments
Dipak Dulal
Dipak Dulal on 29 Nov 2021
Did you download the file usastatehi.shp from the link you sent. I could not find the exact map file to plot. Your little bit more elaboration means a lot to me.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!