How to convert Degrees Minutes Seconds to Decimal Degrees


Summary This topic shows how to use the Defense Solutions Coordinate API to convert a DMS coordinate string into a normalized DMS string, DD string, 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 static void convertCoordDMS(){
    try{
        // create coordinate object for degrees, minutes, seconds format
        DMSCoordinate dmsCoord = new DMSCoordinate();
        dmsCoord.setString("37 -123 32 34.43"); // put a string value
        String dms = dmsCoord.getString(); // get back the normalized DMS string
        System.out.println("Input (string): (\"37 -123 32 34.43\")");
        System.out.println("Output (normalized string): " + dms + '\n');

        // now for decimal degrees
        DDCoordinate ddCoord = new DDCoordinate();
        // put in the Point from dmsCoord. The Point property is
        // “common ground” for all Coordinate objects
        IPoint point = null;
        ddCoord.setPoint(dmsCoord.getPoint());

        // get back the normalized DD string
        String dd = ddCoord.getString();
        System.out.println("Input (Point): same as DMS");
        System.out.println("Output (normalized string): " + dd + '\n');

        // and the coordinate as lon lat doubles 
        double[] x = new double[25];
        double[] y = new double[25];
        ddCoord.getCoords(x, y);
        System.out.println("Input (Point): same as DMS");
        System.out.println("Output (Lat Lon): " + x + " " + y);
    }
    catch (Exception ex){
        ex.printStackTrace();
    }
}


See Also:

Defense Solutions Library Reference - Converting Coordinates
Defense Solutions Coordinate API Input-Output Formats
Sample: How to convert coordinate arrays
Sample: How to convert from MGRS in Indian 1960 (ING-A) to Lat-Lon (DMS and DD) in WGS 1984
Sample: How to normalize Decimal Degree coordinates




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