/// <summary> /// Attempts to parse a string into a Coordinate with a specified date and eager loading settings. /// </summary> /// <param name="value">Coordinate string</param> /// <param name="geoDate">GeoDate</param> /// <param name="eagerLoad">Eager loading options</param> /// <param name="coordinate">Coordinate</param> /// <returns>boolean</returns> /// <example> /// The following example parses a decimal degree formatted geodetic coordinate string, with a provided GeoDate. /// Eager loading is set to load celestial calculations only. /// <code> /// Coordinate c; /// EagerLoad el = new EagerLoad(EagerLoadType.Celestial); /// if(Coordinate.TryParse("N 32.891º W 64.872º", new DateTime(2018,7,7), el, out c)) /// { /// Console.WriteLine(c); //N 32º 53' 28.212" W 64º 52' 20.914" /// } /// </code> /// </example> public static bool TryParse(string value, DateTime geoDate, EagerLoad eagerLoad, out Coordinate coordinate) { coordinate = null; if (FormatFinder.TryParse(value, CartesianType.Cartesian, out coordinate)) { Parse_Format_Type pft = coordinate.Parse_Format; coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate, eagerLoad); //Reset with specified eager load options. coordinate.parse_Format = pft; return(true); } return(false); }
/*TRYPARSE METHODS*/ /// <summary> /// Attempts to parse a string into a Coordinate. /// </summary> /// <param name="value">Coordinate string</param> /// <param name="coordinate">Coordinate</param> /// <returns>boolean</returns> /// <example> /// The following example parses a decimal degree formatted geodetic coordinate string. /// <code> /// Coordinate c; /// if(Coordinate.TryParse("N 32.891º W 64.872º", out c)) /// { /// Console.WriteLine(c); //N 32º 53' 28.212" W 64º 52' 20.914" /// } /// </code> /// </example> public static bool TryParse(string value, out Coordinate coordinate) { coordinate = null; if (FormatFinder.TryParse(value, CartesianType.Cartesian, out coordinate)) { Parse_Format_Type pft = coordinate.Parse_Format; coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad default settings coordinate.parse_Format = pft; return(true); } return(false); }
/// <summary> /// Attempts to parse a string into an ECEF coordinate. /// </summary> /// <param name="value">string</param> /// <param name="ecef">ECEF</param> /// <returns>ECEF</returns> /// <example> /// The following example attempts to parse an ECEF coordinate. /// <code> /// ECEF ecef; /// if(!ECEF.TryParse("217.206 km, -4127.862 km, 4841.101 km", out ecef)) /// { /// Console.WriteLine(ecef);//217.206 km, -4127.862 km, 4841.101 km /// } /// </code> /// </example> public static bool TryParse(string value, out ECEF ecef) { double[] vals = null; if (FormatFinder.TryCartesian(value.ToUpper().Replace("KM", "").Replace("X", "").Replace("Y", "").Replace("Z", ""), out vals)) { try { ecef = new ECEF(vals[0], vals[1], vals[2]); return(true); } catch {//Parser failed try next method } } ecef = null; return(false); }
/// <summary> /// Attempts to parse a string into an UTM coordinate. /// </summary> /// <param name="value">string</param> /// <param name="radius">Equatorial Radius (Semi-Major Axis)</param> /// <param name="flattening">Inverse Flattening</param> /// <param name="utm">UniversalTransverseMercator</param> /// <returns>UniversalTransverseMercator</returns> /// <example> /// The following example attempts to parse a UTM coordinate set with GRS80 system ellipsoid values. /// <code> /// UniversalTransverseMercator utm; /// if(!UniversalTransverseMercator.TryParse("16U 500872mE 5505009mN", 6378137.0, 298.257222101, out utm)) /// { /// Console.WriteLine(utm);//16U 500872mE 5505009mN /// } /// </code> /// </example> public static bool TryParse(string value, double radius, double flattening, out UniversalTransverseMercator utm) { string[] vals = null; if (FormatFinder.TryUTM(value, out vals) || FormatFinder.TryUPS(value, out vals)) { try { double zone = Convert.ToDouble(vals[0], CultureInfo.InvariantCulture); double easting = Convert.ToDouble(vals[2], CultureInfo.InvariantCulture); double northing = Convert.ToDouble(vals[3], CultureInfo.InvariantCulture); utm = new UniversalTransverseMercator(vals[1], (int)zone, easting, northing, radius, flattening); return(true); } catch { //silent fail, return false. } } utm = null; return(false); }
/// <summary> /// Attempts to parse a string into a Coordinate with a specified date, Cartesian system type and eager loading settings. /// </summary> /// <param name="value">Coordinate string</param> /// <param name="geoDate">GeoDate</param> /// <param name="cartesianType">Cartesian Type</param> /// <param name="eagerLoad">Eager loading options</param> /// <param name="coordinate">Coordinate</param> /// <returns>boolean</returns> /// <example> /// The following example parses an ECEF formatted coordinate string, with an included GeoDate. /// Because this is an ECEF Cartesian type coordinate, we will specify the Cartesian system type. /// Eager loading options have been specified for efficiency. /// <code> /// Coordinate c; /// EagerLoad el = new EagerLoad(EagerLoadType.Cartesian); /// if(Coordinate.TryParse("5242.097 km, 2444.43 km, 2679.074 km", new DateTime(2018,7,7), CartesianType.ECEF, el, out c)) /// { /// Console.WriteLine(c); //N 24º 59' 59.987" E 25º 0' 0.001" /// } /// </code> /// </example> public static bool TryParse(string value, DateTime geoDate, CartesianType cartesianType, EagerLoad eagerLoad, out Coordinate coordinate) { coordinate = null; if (FormatFinder.TryParse(value, cartesianType, out coordinate)) { Parse_Format_Type pft = coordinate.Parse_Format; if (cartesianType == CartesianType.ECEF) { Distance h = coordinate.ecef.GeoDetic_Height; coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate, eagerLoad); //Reset with eager load options specified. coordinate.ecef.Set_GeoDetic_Height(coordinate, h); } else { coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble(), geoDate, eagerLoad); //Reset with eager load options specified. } coordinate.parse_Format = pft; return(true); } return(false); }
/// <summary> /// Attempts to parse a string into a Coordinate with a specified Cartesian system type. /// </summary> /// <param name="value">Coordinate string</param> /// <param name="cartesianType">Cartesian Type</param> /// <param name="coordinate">Coordinate</param> /// <returns>boolean</returns> /// <example> /// The following example parses an ECEF formatted coordinate string. /// Because this is an ECEF Cartesian type coordinate, we will specify the Cartesian system type. /// <code> /// Coordinate c; /// if(Coordinate.TryParse("5242.097 km, 2444.43 km, 2679.074 km", CartesianType.Cartesian, out c)) /// { /// Console.WriteLine(c); //N 24º 59' 59.987" E 25º 0' 0.001" /// } /// </code> /// </example> public static bool TryParse(string value, CartesianType cartesianType, out Coordinate coordinate) { coordinate = null; if (FormatFinder.TryParse(value, cartesianType, out coordinate)) { Parse_Format_Type pft = coordinate.Parse_Format; if (cartesianType == CartesianType.ECEF) { Distance h = coordinate.ecef.GeoDetic_Height; coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad default settings coordinate.ecef.Set_GeoDetic_Height(coordinate, h); } else { coordinate = new Coordinate(coordinate.Latitude.ToDouble(), coordinate.Longitude.ToDouble()); //Reset with EagerLoad default settings } coordinate.parse_Format = pft; return(true); } return(false); }
/// <summary> /// Attempts to parse a string into an MGRS coordinate. /// </summary> /// <param name="value">string</param> /// <param name="radius">Equatorial Radius (Semi-Major Axis)</param> /// <param name="flattening">Inverse Flattening</param> /// <param name="mgrs">MilitaryGridReferenceSystem</param> /// <returns>MilitaryGridReferenceSystem</returns> /// <example> /// The following example attempts to parse an MGRS coordinate set with GRS80 system ellipsoid values. /// <code> /// MilitaryGridReferenceSystem mgrs; /// if(!MilitaryGridReferenceSystem.TryParse("16U EA 00872 05009", 6378137.0, 298.257222101, out mgrs)) /// { /// Console.WriteLine(mgrs);//16U EA 00872 05009 /// } /// </code> /// </example> public static bool TryParse(string value, double radius, double flattening, out MilitaryGridReferenceSystem mgrs) { string[] vals = null; if (FormatFinder.TryMGRS(value, out vals) || FormatFinder.TryMGRS_Polar(value, out vals)) { try { double zone = Convert.ToDouble(vals[0], CultureInfo.InvariantCulture); double easting = Convert.ToDouble(vals[3], CultureInfo.InvariantCulture); double northing = Convert.ToDouble(vals[4], CultureInfo.InvariantCulture); mgrs = new MilitaryGridReferenceSystem(vals[1], (int)zone, vals[2], easting, northing, radius, flattening); return(true); } catch {//Parser failed try next method } } mgrs = null; return(false); }