How can I plot a map and calculate distance between two points in the Geographic Space?

37 Ansichten (letzte 30 Tage)
How can I show a map in a figure? I want the map to be draggable.
How can I calculate the distance between two points in a Geographic Space? I have a longitude and latitude point I want to plot in a map.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 17 Apr. 2024 um 0:00
Bearbeitet: MathWorks Support Team am 17 Apr. 2024 um 15:38

Showing the map in a figure

There are different projections as shown in documentation page in https://www.mathworks.com/help/map/summary-and-guide-to-projections.html. You can choose the most appropriate for your workflow.
You can plot latitude and longitude points, e.g. 52.229588, 0.150855, using "geoshow" function as shown in documentation page in https://www.mathworks.com/help/map/ref/geoshow.html. Here is an example:\n
>> figure
>> geoax = axesm('pcarree');
>> geoshow('landareas.shp', 'FaceColor', [0.5 1.0 0.5]);
>> geoshow(52.229588, 0.150855, 'DisplayType', 'Point', 'Marker', '+', 'Color', 'red');
>> geoshow(42.301853, -71.376126, 'DisplayType', 'Point', 'Marker', '+', 'Color', 'red');
The figure will have a map which is draggable, and will have a red cross in Cambridge, UK. The figure allows to zoom in closer, to zoom out and to drag around the map.

Distance between two points in the Geographic Space

You can calculate the distance between two points, as shown in documentation page in https://www.mathworks.com/help/map/ref/distance.htmlhttps://www.mathworks.com/help/map/ref/distance.html.
For the example, let us choose two GPS points:
  • 52.229588, 0.150855 in Cambridge, UK.
  • 42.301853, -71.376126 in Natick, MA, USA.
Then the arc length distance can be computed in this way:
[arclen, az] = distance([52.229588, 0.150855], [42.301853, -71.376126])
arclen =
47.5027
az =
287.9302
Then the distance can be calculated in kilometres using "deg2km" function as shown in documentation page in https://www.mathworks.com/help/map/ref/deg2km.html.\n
>> km = deg2km(arclen)
km =
5.2821e+03

Weitere Antworten (0)

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by