예제 #1
0
        /// <summary>
        /// A string formatted and represented coordinate.
        /// </summary>
        /// <param name="options">CoordinateFormatOptions</param>
        /// <returns>Formatted Coordinate string</returns>
        /// <example>
        /// The following example will demonstrate how to output a custom formatted
        /// string representation of a Coordinate.
        /// <code>
        /// Coordinate c = new Coordinate(25, 25);
        ///
        /// //Create the formatting object to pass to the ToString() overload.
        /// CoordinateFormatOptions cfo = new CoordinateFormatOptions();
        ///
        /// cfo.Format = CoordinateFormatType.Degree_Decimal_Minutes; //Set string format to DDM
        /// cfo.Display_Leading_Zeros = true; //Display leading zeros
        /// cfo.Round = 2; //Round to the 2nd decimal place
        ///
        /// Console.WriteLine(c.ToString(cfo)); //N 25º 00' E 025º 00'
        /// </code>
        /// </example>
        public string ToString(CoordinateFormatOptions options)
        {
            string latString = latitude.ToString(options);
            string longSting = longitude.ToString(options);

            return(latString + " " + longSting);
        }
예제 #2
0
        /// <summary>
        /// Creates a Coordinate object with default values and a custom datum.
        /// </summary>
        /// <remarks>
        /// Default Coordinate objects will initialize with a latitude and longitude of 0 degrees,
        /// a GeoDate of 1900-1-1 00:00:00. All properties will be set to EagerLoaded.
        /// </remarks>
        internal Coordinate(double equatorialRadius, double inverseFlattening, bool t)
        {
            FormatOptions    = new CoordinateFormatOptions();
            geoDate          = new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            latitude         = new CoordinatePart(CoordinateType.Lat);
            longitude        = new CoordinatePart(CoordinateType.Long);
            latitude.parent  = this;
            longitude.parent = this;
            celestialInfo    = new Celestial();
            utm       = new UniversalTransverseMercator(latitude.ToDouble(), longitude.ToDouble(), this, equatorialRadius, inverseFlattening);
            mgrs      = new MilitaryGridReferenceSystem(utm);
            cartesian = new Cartesian(this);
            ecef      = new ECEF(this);

            EagerLoadSettings = new EagerLoad();
            Set_Datum(equatorialRadius, inverseFlattening);
        }
예제 #3
0
        /// <summary>
        /// String format settings.
        /// </summary>
        /// <param name="options">CoordinateFormatOptions</param>
        /// <returns>Formatted coordinate part string</returns>
        private string FormatString(CoordinateFormatOptions options)
        {
            ToStringType type          = ToStringType.Degree_Minute_Second;
            int?         rounding      = null;
            bool         lead          = false;
            bool         trail         = false;
            bool         hyphen        = false;
            bool         symbols       = true;
            bool         degreeSymbol  = true;
            bool         minuteSymbol  = true;
            bool         secondsSymbol = true;
            bool         positionFirst = true;

            #region Assign Formatting Rules
            switch (options.Format)
            {
            case CoordinateFormatType.Degree_Minutes_Seconds:
                type = ToStringType.Degree_Minute_Second;
                break;

            case CoordinateFormatType.Degree_Decimal_Minutes:
                type = ToStringType.Degree_Decimal_Minute;
                break;

            case CoordinateFormatType.Decimal_Degree:
                type = ToStringType.Decimal_Degree;
                break;

            case CoordinateFormatType.Decimal:
                type = ToStringType.Decimal;
                break;

            default:
                type = ToStringType.Degree_Minute_Second;
                break;
            }
            rounding      = options.Round;
            lead          = options.Display_Leading_Zeros;
            trail         = options.Display_Trailing_Zeros;
            symbols       = options.Display_Symbols;
            degreeSymbol  = options.Display_Degree_Symbol;
            minuteSymbol  = options.Display_Minute_Symbol;
            secondsSymbol = options.Display_Seconds_Symbol;
            hyphen        = options.Display_Hyphens;
            positionFirst = options.Position_First;
            #endregion

            switch (type)
            {
            case ToStringType.Decimal_Degree:
                if (rounding == null)
                {
                    rounding = 6;
                }
                return(ToDecimalDegreeString(rounding.Value, lead, trail, symbols, degreeSymbol, positionFirst, hyphen));

            case ToStringType.Degree_Decimal_Minute:
                if (rounding == null)
                {
                    rounding = 3;
                }
                return(ToDegreeDecimalMinuteString(rounding.Value, lead, trail, symbols, degreeSymbol, minuteSymbol, hyphen, positionFirst));

            case ToStringType.Degree_Minute_Second:
                if (rounding == null)
                {
                    rounding = 3;
                }
                return(ToDegreeMinuteSecondString(rounding.Value, lead, trail, symbols, degreeSymbol, minuteSymbol, secondsSymbol, hyphen, positionFirst));

            case ToStringType.Decimal:
                if (rounding == null)
                {
                    rounding = 9;
                }
                double dub = ToDouble();
                dub = Math.Round(dub, rounding.Value);
                string lt = Leading_Trailing_Format(lead, trail, rounding.Value, Position);
                return(string.Format(lt, dub));
            }

            return(string.Empty);
        }
예제 #4
0
 /// <summary>
 /// Formatted coordinate part string.
 /// </summary>
 /// <param name="options">CoordinateFormatOptions</param>
 /// <returns>string</returns>
 public string ToString(CoordinateFormatOptions options)
 {
     return(FormatString(options));
 }
예제 #5
0
        /// <summary>
        /// Coordinate build logic goes here.
        /// </summary>
        /// <param name="lat">Signed latitude</param>
        /// <param name="longi">Signed longitude</param>
        /// <param name="date">Date at location</param>
        /// <param name="eagerLoad">Eagerloading settings</param>
        private void Coordinate_Builder(double lat, double longi, DateTime date, EagerLoad eagerLoad)
        {
            FormatOptions = new CoordinateFormatOptions();

            //Use default constructor if signed degree is 0 for performance.
            if (lat == 0)
            {
                latitude = new CoordinatePart(CoordinateType.Lat);
            }
            else
            {
                latitude = new CoordinatePart(lat, CoordinateType.Lat);
            }

            if (longi == 0)
            {
                longitude = new CoordinatePart(CoordinateType.Long);
            }
            else
            {
                longitude = new CoordinatePart(longi, CoordinateType.Long);
            }

            //Set CoordinatePart parents
            latitude.parent  = this;
            longitude.parent = this;

            //Set UTC date at location
            geoDate = date;


            //LOAD NEW COORDINATE SYSTEMS HERE

            //Load Celestial
            if (eagerLoad.Celestial)
            {
                celestialInfo = new Celestial(lat, longi, date);
            }
            //Load UTM MGRS
            if (eagerLoad.UTM_MGRS)
            {
                utm  = new UniversalTransverseMercator(lat, longi, this);
                mgrs = new MilitaryGridReferenceSystem(utm);
            }
            //Load CARTESIAN
            if (eagerLoad.Cartesian)
            {
                cartesian = new Cartesian(this);
            }
            //Load ECEF
            if (eagerLoad.ECEF)
            {
                ecef = new ECEF(this);
            }

            //SET EagerLoading Setting
            EagerLoadSettings = eagerLoad;

            //Set Ellipsoid
            equatorial_radius  = 6378137.0;
            inverse_flattening = 298.257223563;
        }