Latitude and Longitude of Path from A to B

8 Ansichten (letzte 30 Tage)
czeslaw
czeslaw am 21 Dez. 2017
Kommentiert: Edoardo am 24 Jul. 2024
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 Kommentar
Edoardo
Edoardo am 24 Jul. 2024
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 21 Dez. 2017
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 Kommentare
New to matlab
New to matlab am 24 Apr. 2021
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 am 24 Jul. 2024
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Construction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by