Is there a way to convert between latitude/longitude and Military Grid Reference System coordinates in MATLAB?
조회 수: 40 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Pratyush
2023년 7월 7일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Call C++ from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!