Latitude and Longitude of Path from A to B

7 次查看(过去 30 天)
Hi all,
Is there a premade function in Matlab that can gives sets of latitude and longitude of the shortest possible routes (like GPS) from one place to another (represented also as latitude longtitude)
So the input is:
Latitude and Longitude of a place A
Latitude and Longitude of a place B
The output is:
set of latitudes and longitudes of route 1 from A to B in a matrix
set of latitudes and longitudes of route 2 from A to B in a matrix
set of latitudes and longitudes of route 3 from A to B in a matrix
etc.....
The number of points of latitudes and longitudes in the output would depend on another input that describe how details the output would be.
Might be very complex things to do.
Thanks a lot in advance for any suggestion.
  1 个评论
Edoardo
Edoardo 2024-7-24
I've been doing something similar using https://openrouteservice.org/, you may also find https://open-elevation.com/ useful. They are both open source and provide free docker images for self hosting without any imposed usage limits, open elevation doesn't even require an API key but the free version sometimes rejects requests pretty often and you'll have to wait a minute.
You can use something like a https://curlconverter.com/matlab/ to automatically generate the matlab HTTP or POST requests generating the code from the API playground.
You can request more than one possible route between two sets of coordinates which seems to be what you want to do and also calculate distance matrices between several points

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2017-12-21
No, there is no such premade function.
However, you can use the Mapping Toolbox function distance() which can calculate distances between points on a reference spheroid (though it does not appear to know anything about elevation.) Once you have those distances, you can use the MATLAB function graph() to create a graph object, after which you can use shortestpath() to find shortest path along the graph.
  2 个评论
New to matlab
New to matlab 2021-4-24
Thank you for the answer.
so after finding the shortest path using graph displays. do do you have a way to extract latitude/longitude data (of that path) ?
Edoardo
Edoardo 2024-7-24
Or without having to use the mapping toolbox you could make a custom haversine formula function.
trueDistance = 6371000 * 2 * asin(sqrt(sin(dLat / 2)^2 + sin(dLon / 2)^2 * cos(lat1) * cos(lat2)));
You might need to divide your Lat / Lon (° ) to radians with * pi / 180 or deg2rad
where dLat and dLon are the difference in Lat and Lon between the two points, 6371000 is the radius of the earth in m. Not entirely sure but looks like dLat and dLon might not need to be absolute values so dLat = Lat1 - Lat2 or dLat = Lat2 - Lat1 should work as . Remember to convert to radians first.
As Walter (the goat) mentioned this doesn't account for distance but instead assumes points on a circle, but at least for my application, is good enough.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Construction 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by