How can I make a grid on US maps based on latitude and longitude of its boundary polygon?

Hi all,
I am struggeling wth making a mesh on US map so that I could use contourm function to show specific parameter across the US. I can not use meshgrid function based on the bounding box since I will have contours somewhere outside the US. Can anyone help me with this regard?

4 commentaires

For anyone to help we need to know what the difficulty is that you are having. Can you attatch your data, post your code, and decribe your objective?
State_name=shaperead("tl_2017_27_place.shp");
Bounding_box={State_name.BoundingBox};
Coordinate_table=zeros(size(Bounding_box,2),4);
for i=1:size(Bounding_box,2)
Coordinate_table(i,:)=[Bounding_box{i}(:,1)',Bounding_box{i}(:,2)'];
end
min_lon=min(Coordinate_table(:,1));
max_lon=max(Coordinate_table(:,2));
min_lat=min(Coordinate_table(:,3));
max_lat=max(Coordinate_table(:,4));
[lon,lat]=meshgrid(linspace(min_lon,max_lon,20),linspace(min_lat,max_lat,20));
X_boundary=[State_name.X]';
Y_boundary=[State_name.Y]';
inBoundary = inpolygon(lon(:), lat(:), X_boundary, Y_boundary);
lat = lat(inBoundary);
lon = lon(inBoundary);
[Lon,Lat] = meshgrid(lon,lat);
for zz=1:size(Prob,1)
data = cell2mat(Prob{zz,5});
for v = 1:(size(data, 2)-2)
figure
usamap("Minnesota")
states=readgeotable("usastatehi.shp");
row=states.Name=="Minnesota";
Minnesota=states(row,:);
geoshow(Minnesota,'FaceColor','none')
textm(Minnesota.LabelLat,Minnesota.LabelLon,Minnesota.Name,"HorizontalAlignment","center")
I = scatteredInterpolant(data(:,[2 1]), data(:,v+2));
I.Method='natural';
I.ExtrapolationMethod='none';
contourm(Lat,Lon,min(1,max(0,I(Lon,Lat))));
colormap(jet(10));
colorbar('Ticks',[0.1, 0.3, 0.5, 0.7, 0.9, 1])
title(['POFDE of ' num2str(v) ' feet' ' \mu_{w} =' num2str(round(Prob{zz,1},2)) '%' ' \sigma_{w} =' num2str(round(Prob{zz,2},2)) '%' ' \mu_{\gamma} =' num2str(round(Prob{zz,3},2)) ' lb/ft^{3}' ' \sigma_{\gamma} =' num2str(round(Prob{zz,4},2)) ' lb/ft^{3}'])
exportgraphics(gca, sprintf('%dFrostPlot_%d_feet.png',[zz,v]))
end
end
Above is my code. you can use the shape file located in the attached zipped folder. A cell array called "prob" is also attached here (the last column of this cell array include longirtude, latitide, the probability that the specific parameter exceeds 1 foot, 2 feet, 3 feet, 4 feet, and 5 feet respectively). I think the way that I created mesh on Mineesota map is not correct and, consequently the contour values are wrong.
I have estimated a specific parameter( freezing depth) for almost all weather stations having thier own longitude and latitude existing in the Minnesota state. As the stations are scatterd across the Minessota, I used scatteredInterpolant function to interpolate the freezing depth on the generated nodes(from the mesh) since I aim to draw contour lines for freezing depth. The main problem is with the way I generated the mesh in my code. I used inBoundary funvtion to exclude the points outside the state's boundary. However, I think I still have problem with that,

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by