有谁知道在哪里可以找到将Lat / Lon位置转换为Military Grid Reference System (MGRS)的代码库?如果可能的话,我正在寻找一个C#实现。
我们最终使用GeoTrans并从代码创建DLL并使用PInvoke调用函数。我们从源头中提取了以下任何人想知道的内容(最小解决方案):
我们使用的PInvoke签名:
[DllImport("mgrs.dll")]
public static extern int Convert_Geodetic_To_MGRS(
double Latitude,
double Longitude,
int Precision, // 1 to 5, we used 4 (10 square meters)
StringBuilder MGRS);
对应于mgrs.h中的此函数:
MGRSDLL_API long __stdcall Convert_Geodetic_To_MGRS(
double Latitude,
double Longitude,
long Precision,
char* MGRS);
您可以使用GDAL的C#包装器将lat / lon转换为UTM。然后,您只需要为MGRS适当地格式化值,因为它只是具有不同数字格式的UTM。
CoordinateSharp可作为Nuget包使用,可以做到这一点。
Coordinate c = new Coordinate(40.57682, -70.75678);
c.MGRS.ToString(); // Outputs 19T CE 51307 93264
在js上找到它是否有帮助......
https://github.com/codice/usng.js
用法-
var converter = new usngs.Converter();
alert(converter.LLtoMGRS(33.754032, -98.451233, 9));