我对美国大陆许多点到海洋的 W、NW、SW 距离感兴趣。出于测试目的,我在 500 m(32x32 像素) GMTED2010和垂直海岸线上循环通过 1/8 度 dem 。我环顾了这个站点并因此实现了 pdist2 函数,但是我没有得到我期望的结果。所以我的第一个问题是我是否在概念上是错误的,第二个问题是我的 pdist2 实现是否不正确?我也对其他解决方案持开放态度。
考虑到方向约束,我希望在所有 3 个方向上看到相同的模式。最西边的像素列将具有相同的距离,下一列将是相同的,等等,所以当我绘制一个 32x32 矩阵dlong
使用时,imagesc
我得到一个从低到高、从左到右的渐变。
%**************
%For those truly interested, you can download the DEM and get Z and R accordingly:
[Z120,R120]=geotiffread('~/path/to/tif/GMTED2010N30W120_150/30n120w_20101117_gmted_mea150.tif');
[Z150,R150]=geotiffread('~/path/to/tif/GMTED2010N30W150_150/30n150w_20101117_gmted_mea150.tif');
Z=[Z150 Z120];
R=R120;
Z=Z(:,6001:4800+7200); %crop Z from -100 to -125. use latlon2pix to confirm between sub-z and z
R.Lonlim=[-125, -100];
R.RasterSize=size(Z);
clear Z150 Z120 R150 R120
%******* HERE STARTS THE ALGORITHM
%coastline (ultimately will be from the coast library)
latlim=[0.25:.25:60];
lonlim=ones(length(latlim),1)*-110
%variables r and c are the row and column indices for the point I'm interested in. r and c are relative to a DEM for the entire western USA so a point in Colorado is something like 2370,4350.
rstart=2370;
cstart=4350;
for r=2370:2370+31
for c=4350:4350+31
%rows and cols are the vectors in the NW direction from point r,c.
%in the SW direction, rows=r+[1:min(r,c)-1]. cols is the same.
%W direction, rows=ones(r,1)*r; cols=c-[1:c-1];
rows= r-[1:min(r,c)-1];
cols= c-[1:min(r,c)-1];
%Use referencing object R for DEM Z of the western USA to convert rows and cols to lat and long.
[NWcoord(:,1) NWcoord(:,2)]=pix2latlon(R,rows,cols);
%use pdist2 to find the shortest distance between any two points in the two vectors
[D,i]=pdist2(lonlim,NWcoord(:,2),'euclidean','smallest',1);
[~, mi]=min(D);
sta.NWcoast=[latlim(i(mi)) lonlim(i(mi))];
dlong(r-rstart+1,c-cstart+1)=distance(lat,long,latlim(i(mi)),lonlim(i(mi))); %great arc distance on earth's surface. radians
end
end