distance of random points to coastline
4 ビュー (過去 30 日間)
古いコメントを表示
I have 18 global sites, and I want to find the shortest distance from each site to the coastline.
Can anybody provide a simple way to do this?
load coastlines.mat
Dlon = [-43.5 -44.5 -79.4 -110.5 59.8 90.4 -33.0 -15.9 -23.6 -118.4 -126.4 -90.8 -83.7 -21.0 8.9 113.3 116.6 -171.0];
Dlat = [4.2 5.5 11.5 0.2 16.6 5.4 41.0 57.5 60.4 32.3 41.0 -3.1 1.2 18.1 -42.9 9.4 18.8 -41.8]
plot(coastlon, coastlat)
hold on
scatter(Dlon, Dlat,'k','filled')
0 件のコメント
採用された回答
Akira Agata
2024 年 10 月 7 日
If you can treat longitude and lattitude as X and Y, one straight-forward solution would be as follows.
Of course, if you want to calculate more accurate solution, you have to consider geoid model and calculate shortest path on the sphere.
load coastlines.mat
Dlon = [-43.5 -44.5 -79.4 -110.5 59.8 90.4 -33.0 -15.9 -23.6 -118.4 -126.4 -90.8 -83.7 -21.0 8.9 113.3 116.6 -171.0];
Dlat = [4.2 5.5 11.5 0.2 16.6 5.4 41.0 57.5 60.4 32.3 41.0 -3.1 1.2 18.1 -42.9 9.4 18.8 -41.8];
% Calculate euclid distance between each points
coastxy = [coastlon, coastlat];
Dxy = [Dlon', Dlat'];
d = pdist2(Dxy, coastxy);
% Visualize the result
figure
plot(coastlon, coastlat)
hold on
h1 = scatter(Dlon, Dlat, 'rx');
for kk = 1:numel(Dlat)
[~, pt] = min(d(kk, :));
lon = [Dlon(kk), coastlon(pt)];
lat = [Dlat(kk), coastlat(pt)];
h2 = plot(lon, lat, 'm-');
end
legend([h1 h2], ["18 Global Site", "Shortest path to coast"])
2 件のコメント
Akira Agata
2024 年 10 月 7 日
移動済み: John D'Errico
2024 年 10 月 7 日
Well, in the above code, raw min distance value is meaningless because it only calculates Euclid distance beteen two points on lon-lat plane.
As mentioned in my comment, actual min distance shall be calculated considering geoid model. If you have Mapping Toolbox, you can do this task as follows:
load coastlines.mat
Dlon = [-43.5 -44.5 -79.4 -110.5 59.8 90.4 -33.0 -15.9 -23.6 -118.4 -126.4 -90.8 -83.7 -21.0 8.9 113.3 116.6 -171.0];
Dlat = [4.2 5.5 11.5 0.2 16.6 5.4 41.0 57.5 60.4 32.3 41.0 -3.1 1.2 18.1 -42.9 9.4 18.8 -41.8];
% Calculate euclid distance between each points
coastxy = [coastlon, coastlat];
Dxy = [Dlon', Dlat'];
d = pdist2(Dxy, coastxy);
% Use WGS84 reference ellipsoid
wgs84 = wgs84Ellipsoid("kilometer");
figure
plot(coastlon, coastlat)
hold on
scatter(Dlon, Dlat, 'rx')
for kk = 1:numel(Dlat)
[~, pt] = min(d(kk, :));
lon = [Dlon(kk), coastlon(pt)];
lat = [Dlat(kk), coastlat(pt)];
% Calculate distance in km
l = distance(lat(1), lon(1), lat(2), lon(2), wgs84);
plot(lon, lat, 'm-')
text(lon(1)+5, lat(1), compose("%.1f km", l))
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Geodesy and Mapping についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!