Convert Degrees/Minutes/Seconds to Decimal Coordinates

前端 未结 7 1279
青春惊慌失措
青春惊慌失措 2020-12-01 12:31

In one part of my code I convert from decimal coordinates to degrees/minutes/seconds and I use this:

double coord = 59.345235;
int sec = (int)Math.Round(coor         


        
7条回答
  •  抹茶落季
    2020-12-01 13:15

    Often the western and southern hemispheres are expressed as negative degrees, and seconds contain decimals for accuracy: -86:44:52.892 Remember longitude is the X-coordinate and latitude is the Y-coordinate. This often gets mixed up because people often refer to them lat/lon and X/Y. I modified the code below for the above format.

    private double ConvertDegreesToDecimal(string coordinate)
    {
        double decimalCoordinate;
        string[] coordinateArray = coordinate.Split(':');
        if (3 == coordinateArray.Length)
        {
            double degrees = Double.Parse(coordinateArray[0]);
            double minutes = Double.Parse(coordinateArray[1]) / 60;
            double seconds = Double.Parse(coordinateArray[2]) / 3600;
    
            if (degrees > 0)
            {
                decimalCoordinate = (degrees + minutes + seconds);
            }
            else
            {
                decimalCoordinate = (degrees - minutes - seconds);
            }
        }
        return decimalCoordinate;
    }
    

提交回复
热议问题