Exemplo n.º 1
0
        public GeoLine(double value, GeoLineType lineType, CardinalDirection cardinalDirection)
        {
            if (lineType == GeoLineType.Latitude)
            {
                MaxDegrees = 90;
            }
            else
            {
                MaxDegrees = 180;
            }



            if (value < 0 && lineType == GeoLineType.Longitude && cardinalDirection == CardinalDirection.E)
            {
                throw new ArgumentException("A negative Longitude can only represent Western Meridians.");
            }

            if (value < 0 && lineType == GeoLineType.Latitude && cardinalDirection == CardinalDirection.N)
            {
                throw new ArgumentException("A negative Latitude can only represent Southern Parallels.");
            }

            if (lineType == GeoLineType.Latitude && (cardinalDirection == CardinalDirection.E || cardinalDirection == CardinalDirection.W))
            {
                throw new ArgumentException("Latitude only measures location relative to North and South.");
            }

            if (lineType == GeoLineType.Longitude && (cardinalDirection == CardinalDirection.N || cardinalDirection == CardinalDirection.S))
            {
                throw new ArgumentException("Longitude only measures location relative to East and West.");
            }

            if (Math.Abs(value) > Math.Abs(MaxDegrees))
            {
                throw new ArgumentException("Absolute Value of the measurement cannot be greater than the max");
            }
            var decimalValue = Convert.ToDecimal(value);

            decimalValue = Math.Abs(decimalValue);

            var degrees = Decimal.Truncate(decimalValue);

            decimalValue = (decimalValue - degrees) * 60;

            var minutes = Decimal.Truncate(decimalValue);
            var seconds = (decimalValue - minutes) * 60;

            Degrees           = Convert.ToDouble(degrees);
            Minutes           = Convert.ToDouble(minutes);
            Seconds           = Convert.ToDouble(seconds);
            CardinalDirection = cardinalDirection;
        }
Exemplo n.º 2
0
        public GeoLine(double degrees, double minutes, double seconds, GeoLineType lineType, CardinalDirection cardinalDirection)
        {
            if (lineType == GeoLineType.Latitude)
            {
                MaxDegrees = 90;
            }
            else
            {
                MaxDegrees = 180;
            }



            if (degrees < 0 && lineType == GeoLineType.Longitude && cardinalDirection == CardinalDirection.W)
            {
                throw new ArgumentException("A negative Longitude can only represent Eastern Meridians.");
            }

            if (degrees < 0 && lineType == GeoLineType.Latitude && cardinalDirection == CardinalDirection.N)
            {
                throw new ArgumentException("A negative Latitude can only represent Southern Parallels.");
            }

            if (lineType == GeoLineType.Latitude && (cardinalDirection == CardinalDirection.E || cardinalDirection == CardinalDirection.W))
            {
                throw new ArgumentException("Latitude only measures location relative to North and South.");
            }

            if (lineType == GeoLineType.Longitude && (cardinalDirection == CardinalDirection.N || cardinalDirection == CardinalDirection.S))
            {
                throw new ArgumentException("Longitude only measures location relative to East and West.");
            }

            if (Math.Abs(degrees) > Math.Abs(MaxDegrees))
            {
                throw new ArgumentException("Absolute Value of the measurement cannot be greater than the max");
            }
            Degrees           = Math.Abs(degrees);
            Minutes           = Math.Abs(minutes);
            Seconds           = Math.Abs(seconds);
            CardinalDirection = cardinalDirection;
        }
Exemplo n.º 3
0
        private GeoLine GetGeoLineFromProperties(PropertyItem lineRef, PropertyItem line, GeoLineType lineType)
        {
            var lineDir = Encoding.ASCII.GetString(lineRef.Value).Substring(0, 1);
            CardinalDirection direction = (CardinalDirection)Enum.Parse(typeof(CardinalDirection), lineDir);
            var measurements            = GetRationalNumbersFromValue(line);

            return(new GeoLine(measurements[0], measurements[1], measurements[2], lineType, direction));
        }