How to convert from MGRS in Indian 1960 (ING-A) to Lat-Lon (DMS and DD) in WGS 1984


Summary This topic shows how to use the Defense Solutions Coordinate API to convert an MGRS coordinate string in "Indian 1960" datum to normalized MGRS and DMS strings, DD, and x-y values.

Many of the ArcGIS Military Analyst and MOLE extension application programming interface (API) objects you have used in the past have equivalent or near equivalent objects in the ArcGIS 10 ArcObjects API. These new objects should now be used and do not require a Military Analyst extension or MOLE extension license. See Migrating from Military Analyst and MOLE for information on how to accomplish tasks in ArcGIS 10 that previously required the Military Analyst and MOLE APIs.
How to use:
 
  1. In your project, add a reference to the ESRI Defense Solutions jar.
  2. Copy and paste the sample code into your project.
  3. Compile and run your project.
[Java]
public void convertCoordMGRS(){
    try{
        SpatialReferenceEnvironment SREnv = new SpatialReferenceEnvironment();
        ISpatialReference ING_A_SR = SREnv.createGeographicCoordinateSystem((int)
            esriSRGeoCSType.esriSRGeoCS_Indian1960);

        MGRSCoordinate mgrsCoord = new MGRSCoordinate();
        mgrsCoord.setPrecision(esriCoordinatePrecision.esriCPOneCentimeter);

        DMSCoordinate dmsCoord = new DMSCoordinate();
        dmsCoord.setPrecision(esriCoordinatePrecision.esriCPOneTenThousandthSecond);

        DDCoordinate ddCoord = new DDCoordinate();
        ddCoord.setPrecision(esriCoordinatePrecision.esriCPOneTenthThousandthDegree);

        // forward the output
        mgrsCoord.addOutputCoordinate(dmsCoord);
        mgrsCoord.addOutputCoordinate(ddCoord);

        // set up the SRs
        mgrsCoord.setInputSpatialReference(ING_A_SR);
        mgrsCoord.setOutputSpatialReference(ING_A_SR);

        // if desired, may specify that the dms and dd output be in Indian1960 as well
        // dmsCoord.OutputSpatialReference = ING_A_SR; 
        // forwarded coordinates get their InputSR from the calling coordinate
        // ddCoord.OutputSpatialReference = ING_A_SR; 
        // but need to have their OutputSR specified (it would be WGS84 otherwise)

        mgrsCoord.setString("48 Q YD 8871621421"); // this does all the conversions
        double mgrs[] = new double[2];
        mgrsCoord.getCoords(mgrs, mgrs);

        double dms[] = new double[2];
        dmsCoord.getCoords(dms, dms);

        double dd[] = new double[2];
        ddCoord.getCoords(dd, dd);

        System.out.println("Input (string ING-A) = 48 Q YD 8871621421)");
        System.out.println("Output (MGRS string ING-A) = " + mgrsCoord.getString());
        System.out.println("Output (MGRS x, y ING-A) = (" + mgrs[0] + ", " + mgrs[1]
            + ")");
        System.out.println("Output (DMS string WGS84) = (" + dmsCoord.getString() + 
            ")");
        System.out.println("Output (DMS x, y WGS84) = (" + dms[0] + ", " + dms[1] + 
            ")");
        System.out.println("Output (DD string WGS84) = (" + ddCoord.getString() + 
            ")");
        System.out.println("Output (DD x, y WGS84) = (" + dd[0] + ", " + dd[1] + ")")
            ;
    }
    catch (IOException ex){
        System.out.println(" CTool Geotransformation ");
        ex.printStackTrace();
    }
}


See Also:

Defense Solutions Library Reference - Converting Coordinates
Defense Solutions Coordinate API Input-Output Formats
Sample: How to convert DMS to DD
Sample: How to convert coordinate arrays
Sample: How to normalize Decimal Degree coordinates




Development licensing Deployment licensing
Engine Developer Kit: Military Analyst Engine Runtime: Military Analyst