How can I remove contours outside the US border?
8 visualizaciones (últimos 30 días)
Using the code below, I am going to draw contour lines showing the probability that frost depth exceeds 1 foot accros the US. Using your guidance, I used masking method in order to remove contour lines outside the US border. Althogh I could improve my contour map to some extent, there are still some contour lines lying outside the US map. Can anyone help me with this regard?
Compelelemtary explainations can be seen on comments in the code.
%%%% Loading longitude(X) and latitude(Y) vectors of US border points which
%%%% are captured by ArcGIS
%%%Prob1 is a cell array that its first column, second column, and third
%%%column are latitude, longitude of weather stations, and probability that
%%%frost depth exceeds 1 foot, respectively
%%%%%determining bounding box for the US
%%%%%%%%creating mesh based on the bounding box
%%%%creating a polygon based on the US border coordinates(X,Y) and determining
%%%%which nodes of the mesh will be located inside the US polygon
pgon = polyshape(X, Y);
idx = isinterior(pgon,lon(:),lat(:));
%%%%drawing a raw map of the US so that we can plot contours on that
data = cell2mat(Prob1);
states = readgeotable("usastatelo.shp");
rows = states.Name ~= "Alaska" & states.Name ~= "Hawaii";
states = states(rows,:);
h = height(states);
faceColors = makesymbolspec("Polygon",...
%%%% Interpolaing using scatteredInterpolant function. We know the
%%%% probability that frost depth exceeds 1 foot in the locations of weather
%%%% stations. Now, to draw contour lines, we need to use interpolation to
%%%% estimate the probability of frost depth exceedance of 1 foot in all
%%%% nodes of the generated mesh
I = scatteredInterpolant(data(:,[2 1]), data(:,3));
z1(~idx) = nan;
%%%% draw contours