Creating mask from coastline
显示 更早的评论
I'm trying to create a mask from coastline data, which is a N x 2 array of the points, however I'm having trouble actually creating the mask. I've tried using the inpolygon function as an alternative, but it's coming up empty. Here is the part of the code:
C=load('costatotal.dat'); % loading the coastal data
C=C(~isnan(C)); % taking out the NaNs as they don't work in deg2utm
C=reshape(C,numel(C)/2,2); % reshapes
[x_c,y_c]=deg2utm(C(:,2),C(:,1)); % C(:,2)=latitude , C(:,1)=longitude
[X,Y]=meshgrid(linspace(min(xo),max(xo),N),linspace(min(yo),max(yo),N)); % creates a mesh grid that contains the lats and longs of the query points
[in]=inpolygon(X,Y,x_c,y_c); % inpolygon is testing to see if the query points are within the coastline
4 个评论
Sara
2014-8-6
maybe attach the inputs...
Roseanne
2014-8-7
Sara
2014-8-7
- Are xo,yo the coordinates or a rectangular area in lat lon coordinates or UTM?
- What do you mean with 40 by 40? cells, km, degrees?
- Is what you want to do extracting the points that lie within an area defined with xo,yo from the coordinates in C? In this case you can do:
k = find(x_c >= min(xo) & x_c <= max(xo) & y_c >= min(yo) & y_c <= max(yo));
x_c = x_c(k);
y_c = y_c(k);
Note, this line in your code may be in the wrong if the lat and the lon are not NaN's at the same time:
C=C(~isnan(C)); % taking out the NaNs as they don't work in deg2utm
Roseanne
2014-8-8
采纳的回答
更多回答(1 个)
Image Analyst
2014-8-20
0 个投票
Wow - so complicated. Too bad you don't have the Image Processing Toolbox where you could simply use poly2mask(). Very simple - one line of code.
类别
在 帮助中心 和 File Exchange 中查找有关 Geometric Geodesy 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!