Contours and shapefiles
Mostrar comentarios más antiguos
Hi,
I am trying to plot contours over a map of US climate divisions. I imported a climate division shapefile, then found the centroid of each division. Next, I used the meshgrid and triscatteredInterp functions to interpolate the data on a grid. Finally I used the contour function to get isolines.
Once I plotted my isolines over my USA climate division map, I noticed that the contours go outside the US (and outside my centroids used in the meshgrid, etc. calculations). Is there a way to "contain" the centroids to the boundaries of the USA?
Thanks! Deb
Respuestas (1)
Kelly Kearney
el 3 de Ag. de 2011
Not quite sure whether your trying to contain individual points, or the contour lines themselves, and whether you're trying to mask with a polygon (the US coastlines) or just a bounding box. A few functions that might help:
help inpolygon
help polybool
help maptriml
help maptrimp
If none of these seem to do the trick, perhaps a little more detail on your data could be helpful.
EDIT: an example. I've used the contourcs function to extract isolines; I assume you already have this data, but if you want to run my example, download that from the FEX.
% Load coastlines (replace with your coastlines)
latlim = [23 50];
lonlim = [-127 -65];
Usa = shaperead('landareas', 'usegeo', true, 'bounding', [lonlim' latlim']);
[latusa, lonusa] = maptrimp(Usa(1).Lat, Usa(1).Lon, latlim, lonlim);
% Create isolines (replace with your isolines)
n = 50;
xdata = linspace(lonlim(1), lonlim(2), n);
ydata = linspace(latlim(1), latlim(2), n);
zdata = peaks(n);
S = contourcs(xdata, ydata, zdata); % FEX
% Trim to coastlines
[xc, yc] = deal(cell(length(S),1));
for ii = 1:length(S)
[xc{ii}, yc{ii}] = polybool('&', S(ii).X, S(ii).Y, lonusa, latusa);
end
% Plot
figure; axes; hold on;
plot(lonusa, latusa, 'k');
cnew = [xc yc]';
hn = plot(cnew{:}, 'r');
set(hn, 'color', 'b');
3 comentarios
Debra
el 3 de Ag. de 2011
Kelly Kearney
el 4 de Ag. de 2011
Okay, I've added an example to demonstrate using polybool to trim isolines to a coastline.
elvis asong ZILEFAC
el 15 de Abr. de 2013
error: Improper index matrix reference.
Hi Kelly,
I have a similar problem and your answer does it all. However, I receive the above error just after running your code.
Asong.
Categorías
Más información sobre Standard File Formats en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!