Is there a way to convert between latitude/longitude and Military Grid Reference System coordinates in MATLAB?
39 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a project where I would like to convert Military Grid Reference System (MGRS) coordinates to latitude/longitude coordinates and vice versa. I haven't found any helpful web resources that explain how this is done. Is there a way to do this in MATLAB, or could I get some help writing some custom functions that handle this?
0 Kommentare
Antworten (1)
Pratyush
am 7 Jul. 2023
Hi Mike. Acording to my understanding, you have MGRS coordinates and you want to convert them to latitudes and longitudes. For achieving it, you can use a C++ library called GeographicLib. With the help of this library you can achieve the above conversions in any direction. Here is an example in C++.
// Example of using the GeographicLib::MGRS class
#include <iostream>
#include <exception>
#include <string>
#include <GeographicLib/UTMUPS.hpp>
#include <GeographicLib/MGRS.hpp>
using namespace std;
using namespace GeographicLib;
int main() {
try {
// See also example-GeoCoords.cpp
{
// Sample forward calculation
double lat = 33.3, lon = 44.4; // Baghdad
int zone;
bool northp;
double x, y;
UTMUPS::Forward(lat, lon, zone, northp, x, y);
string mgrs;
MGRS::Forward(zone, northp, x, y, lat, 5, mgrs);
cout << mgrs << "\n";
}
{
// Sample reverse calculation
string mgrs = "38SMB4488";
int zone, prec;
bool northp;
double x, y;
MGRS::Reverse(mgrs, zone, northp, x, y, prec);
double lat, lon;
UTMUPS::Reverse(zone, northp, x, y, lat, lon);
cout << prec << " " << lat << " " << lon << "\n";
}
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
}
You may refer to the below MGRS documentation on GeographicLib for more information.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Call C++ from MATLAB 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!