Recently, a GIS Coordinate Transformation task needs to involve this conversion. So we will record it here and present the code. Please criticize and correct it.
/**
* Converts an angle to a string representation of degrees, in seconds.
* @ Param Angle
* @ Return
*/
Public static string convert (double angle)
{
Stringbuffer transangle = new stringbuffer ();
Int deg = (INT) angle;
If (deg> 0)
{
Transangle. append (deg + "° ");
}
Double MI = angle-deg;
// Score
Int minute = (INT) (MI * 60 );
Transangle. append (minute + "′");
Double Se = mi * 60-minute;
Transangle. append (Se * 60 + "″");
Return transangle. tostring ();
}
/**
* Converts the degree-to-second string representation to a numerical value format.
* @ Param Angle
* @ Return
*/
Public static double converttoangle (string angle)
{
Stringbuffer transangle = new stringbuffer (angle );
// Obtain the string in the unit of second.
String degreestring = transangle. substring (0, transangle. indexof ("° "));
String minutestring = transangle. substring (transangle. indexof ("°") + 1,
Transangle. indexof ("′"));
String secondstring = transangle. substring (transangle. indexof ("'") + 1,
Transangle. indexof ("″"));
// Determine whether the value format is correct
Double Degree = 0;
Double minute = 0;
Double second = 0;
If (checknum (degreestring) & checknum (minutestring) & checknum (secondstring ))
{
Degree = double. parsedouble (degreestring );
Minute = double. parsedouble (minutestring );
Second = double. parsedouble (secondstring );
}
Return degree + (minute * 60 + second)/3600.0;
}