private string ProcessInput(string input)
        {
            string   result = string.Empty;
            MapPoint point;

            HasInputError = false;

            if (string.IsNullOrWhiteSpace(input))
            {
                return(result);
            }

            var coordType = GetCoordinateType(input, out point);

            if (coordType == CoordinateType.Unknown)
            {
                HasInputError = true;
            }
            else
            {
                proCoordGetter.Point = point;
                result = new CoordinateDD(point.Y, point.X).ToString("", new CoordinateDDFormatter());
            }

            return(result);
        }
        private void BroadcastCoordinateValues(MapPoint mapPoint)
        {
            var dict = new Dictionary <CoordinateType, string>();

            if (mapPoint == null)
            {
                return;
            }

            var dd = new CoordinateDD(mapPoint.Y, mapPoint.X);

            try
            {
                dict.Add(CoordinateType.DD, dd.ToString("", new CoordinateDDFormatter()));
            }
            catch { }
            try
            {
                dict.Add(CoordinateType.DDM, new CoordinateDDM(dd).ToString("", new CoordinateDDMFormatter()));
            }
            catch { }
            try
            {
                dict.Add(CoordinateType.DMS, new CoordinateDMS(dd).ToString("", new CoordinateDMSFormatter()));
            }
            catch { }

            Mediator.NotifyColleagues(CoordinateConversionLibrary.Constants.BroadcastCoordinateValues, dict);
        }
        public void FormatterDD()
        {
            var coord = new CoordinateDD(40.273048, -78.847427);
            var temp  = coord.ToString("Y0.0#N X0.0#E", new CoordinateDDFormatter());

            Assert.AreEqual(temp, "40.27N 78.85W");

            temp = coord.ToString("Y0.0#S X0.0#W", new CoordinateDDFormatter());
            Assert.AreEqual(temp, "40.27N 78.85W");

            temp = coord.ToString("Y+-0.##N X+-0.##E", new CoordinateDDFormatter());
            Assert.AreEqual(temp, "+40.27N -78.85W");

            temp = coord.ToString("Y+-0.0# X+-0.0#", new CoordinateDDFormatter());
            Assert.AreEqual(temp, "+40.27 -78.85");

            temp = coord.ToString("Y0.0# N, X0.0# E", new CoordinateDDFormatter());
            Assert.AreEqual(temp, "40.27 N, 78.85 W");

            temp = coord.ToString("Y0.0#° N, X0.0#° E", new CoordinateDDFormatter());
            Assert.AreEqual(temp, "40.27° N, 78.85° W");

            temp = coord.ToString("N Y0.0#°, E X0.0#°", new CoordinateDDFormatter());
            Assert.AreEqual(temp, "N 40.27°, W 78.85°");

            // test the default
            temp = coord.ToString("", new CoordinateDDFormatter());
            Assert.AreEqual(temp, "40.273048 -78.847427");
        }
Ejemplo n.º 4
0
        public virtual bool CanGetDD(int srFactoryCode, out string coord)
        {
            CoordinateDD dd;

            if (CoordinateDD.TryParse(InputCoordinate, out dd, true))
            {
                Project(srFactoryCode);
                coord = dd.ToString("", new CoordinateDDFormatter());
                return(true);
            }
            else
            {
                coord = string.Empty;
                return(false);
            }
        }
Ejemplo n.º 5
0
        private CoordinateType GetCoordinateType(string input, out MapPoint point)
        {
            point = null;

            // DD
            CoordinateDD dd;

            if (CoordinateDD.TryParse(input, out dd))
            {
                point = QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                }).Result;
                return(CoordinateType.DD);
            }

            // DDM
            CoordinateDDM ddm;

            if (CoordinateDDM.TryParse(input, out ddm))
            {
                dd    = new CoordinateDD(ddm);
                point = QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                }).Result;
                return(CoordinateType.DDM);
            }
            // DMS
            CoordinateDMS dms;

            if (CoordinateDMS.TryParse(input, out dms))
            {
                dd    = new CoordinateDD(dms);
                point = QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                }).Result;
                return(CoordinateType.DMS);
            }

            return(CoordinateType.Unknown);
        }
Ejemplo n.º 6
0
        public override void ProcessInput(string input)
        {
            if (input == "NA")
            {
                return;
            }

            string result = string.Empty;

            //MapPoint point;
            HasInputError = false;

            if (string.IsNullOrWhiteSpace(input))
            {
                return;
            }

            //var coordType = GetCoordinateType(input, out point);
            // must force non async here to avoid returning to base class early
            var ccc = QueuedTask.Run(() =>
            {
                return(GetCoordinateType(input));
            }).Result;


            if (ccc.Type == CoordinateType.Unknown)
            {
                HasInputError        = true;
                proCoordGetter.Point = null;
                foreach (var output in CoordinateConversionLibraryConfig.AddInConfig.OutputCoordinateList)
                {
                    output.OutputCoordinate = "";
                    output.Props.Clear();
                }
                System.Windows.Forms.MessageBox.Show(CoordinateConversionLibrary.Properties.Resources.InvalidCoordMsg,
                                                     CoordinateConversionLibrary.Properties.Resources.InvalidCoordCap);
            }
            else
            {
                proCoordGetter.Point = ccc.Point;
                result = new CoordinateDD(ccc.Point.Y, ccc.Point.X).ToString("", new CoordinateDDFormatter());
            }

            return;
        }
        public void ParseDD()
        {
            CoordinateDD coord;

            Assert.IsTrue(CoordinateDD.TryParse("40.273048 -78.847427", out coord));
            Assert.AreEqual(40.273048, coord.Lat);
            Assert.AreEqual(-78.847427, coord.Lon);

            Assert.IsFalse(CoordinateDD.TryParse("", out coord));

            Assert.IsTrue(CoordinateDD.TryParse("40.273048N 78.847427W", out coord));
            Assert.IsTrue(CoordinateDD.TryParse("40.273048N,78.847427W", out coord));
            Assert.IsTrue(CoordinateDD.TryParse("40.273048N78.847427W", out coord));
            Assert.IsTrue(CoordinateDD.TryParse("40.273048N;78.847427W", out coord));
            Assert.IsTrue(CoordinateDD.TryParse("40.273048N:78.847427W", out coord));

            Assert.IsFalse(CoordinateDD.TryParse("This is not a coordinate", out coord));
        }
Ejemplo n.º 8
0
        private async void OnFlashPointCommand(object obj)
        {
            CoordinateDD dd;
            var          ctvm = CTView.Resources["CTViewModel"] as CoordinateToolViewModel;

            if (ctvm != null)
            {
                if (!CoordinateDD.TryParse(ctvm.InputCoordinate, out dd))
                {
                    return;
                }
            }
            else
            {
                return;
            }

            ArcGIS.Core.CIM.CIMPointSymbol symbol = null;
            var point = await QueuedTask.Run(() =>
            {
                ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
            });

            await QueuedTask.Run(() =>
            {
                // Construct point symbol
                symbol = SymbolFactory.ConstructPointSymbol(ColorFactory.Red, 10.0, SimpleMarkerStyle.Star);
            });

            //Get symbol reference from the symbol
            CIMSymbolReference symbolReference = symbol.MakeSymbolReference();

            await QueuedTask.Run(() =>
            {
                ClearOverlay();
                _overlayObject = MapView.Active.AddOverlay(point, symbolReference);
                MapView.Active.ZoomToAsync(point, new TimeSpan(2500000), true);
            });
        }
 public override bool CanGetDMS(int srFactoryCode, out string coord)
 {
     coord = string.Empty;
     if (base.CanGetDMS(srFactoryCode, out coord))
     {
         return(true);
     }
     else
     {
         if (base.CanGetDD(srFactoryCode, out coord))
         {
             // convert dd to ddm
             CoordinateDD dd;
             if (CoordinateDD.TryParse(coord, out dd))
             {
                 var dms = new CoordinateDMS(dd);
                 coord = dms.ToString("", new CoordinateDMSFormatter());
                 return(true);
             }
         }
     }
     return(false);
 }
        private async void OnFlashPointCommand(object obj)
        {
            var previous = IsToolActive;

            if (!IsToolActive)
            {
                IsToolActive = true;
            }

            CoordinateDD dd;
            var          ctvm = CTView.Resources["CTViewModel"] as CoordinateConversionViewModel;

            if (ctvm != null)
            {
                if (!CoordinateDD.TryParse(ctvm.InputCoordinate, out dd))
                {
                    return;
                }
            }
            else
            {
                return;
            }

            ArcGIS.Core.CIM.CIMPointSymbol symbol = null;
            var point = await QueuedTask.Run(() =>
            {
                ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
            });

            //await QueuedTask.Run(() =>
            //{
            //    // Construct point symbol
            //    symbol = SymbolFactory.ConstructPointSymbol(ColorFactory.Red, 10.0, SimpleMarkerStyle.Star);
            //});

            ////Get symbol reference from the symbol
            //CIMSymbolReference symbolReference = symbol.MakeSymbolReference();

            //QueuedTask.Run(() =>
            //{
            //    ClearOverlay();
            //    _overlayObject = MapView.Active.AddOverlay(point, symbolReference);
            //    //MapView.Active.ZoomToAsync(point, new TimeSpan(2500000), true);
            //});


            QueuedTask.Run(() =>
            {
                Mediator.NotifyColleagues("UPDATE_FLASH", point);
            });

            //await QueuedTask.Run(() =>
            //{
            //    Task.Delay(500);
            //    ClearOverlay();
            //    //_overlayObject = MapView.Active.AddOverlay(point, symbolReference);
            //    //MapView.Active.ZoomToAsync(point, new TimeSpan(2500000), true);
            //});
            //if (previous != IsToolActive)
            //    IsToolActive = previous;
            //await QueuedTask.Run(() =>
            //{
            //    Task.Delay(500);
            //    ClearOverlay();
            //    MapView.Active.LookAt(MapView.Active.Extent.Center);
            //});
        }
Ejemplo n.º 11
0
        private void UpdateSample()
        {
            var type = GetCoordinateType();

            switch (type)
            {
            case CoordinateType.DD:
                var dd = new CoordinateDD();

                if (ctdict.ContainsKey(CoordinateType.DD))
                {
                    CoordinateDD.TryParse(ctdict[type], out dd);
                }

                Sample = dd.ToString(Format, new CoordinateDDFormatter());

                break;

            case CoordinateType.DDM:
                var ddm = new CoordinateDDM();

                if (ctdict.ContainsKey(type))
                {
                    CoordinateDDM.TryParse(ctdict[type], out ddm);
                }

                Sample = ddm.ToString(Format, new CoordinateDDMFormatter());
                break;

            case CoordinateType.DMS:
                var dms = new CoordinateDMS();

                if (ctdict.ContainsKey(type))
                {
                    CoordinateDMS.TryParse(ctdict[type], out dms);
                }
                Sample = dms.ToString(Format, new CoordinateDMSFormatter());
                break;

            case CoordinateType.GARS:
                var gars = new CoordinateGARS();

                if (ctdict.ContainsKey(type))
                {
                    CoordinateGARS.TryParse(ctdict[type], out gars);
                }

                Sample = gars.ToString(Format, new CoordinateGARSFormatter());
                break;

            case CoordinateType.MGRS:
                var mgrs = new CoordinateMGRS();

                if (ctdict.ContainsKey(type))
                {
                    CoordinateMGRS.TryParse(ctdict[type], out mgrs);
                }

                Sample = mgrs.ToString(Format, new CoordinateMGRSFormatter());
                break;

            case CoordinateType.USNG:
                var usng = new CoordinateUSNG();

                if (ctdict.ContainsKey(type))
                {
                    CoordinateUSNG.TryParse(ctdict[type], out usng);
                }

                Sample = usng.ToString(Format, new CoordinateMGRSFormatter());
                break;

            case CoordinateType.UTM:
                var utm = new CoordinateUTM();

                if (ctdict.ContainsKey(type))
                {
                    CoordinateUTM.TryParse(ctdict[type], out utm);
                }

                Sample = utm.ToString(Format, new CoordinateUTMFormatter());
                break;

            default:
                break;
            }

            RaisePropertyChanged(() => Sample);
        }
Ejemplo n.º 12
0
        public override string ProcessInput(string input)
        {
            if (input == "NA")
            {
                return(string.Empty);
            }

            string result = string.Empty;

            //MapPoint point;
            HasInputError = false;

            if (string.IsNullOrWhiteSpace(input))
            {
                return(string.Empty);
            }

            //var coordType = GetCoordinateType(input, out point);
            // must force non async here to avoid returning to base class early
            var ccc = QueuedTask.Run(() =>
            {
                return(GetCoordinateType(input));
            }).Result;


            if (ccc.Type == CoordinateType.Unknown)
            {
                HasInputError        = true;
                proCoordGetter.Point = null;
                foreach (var output in CoordinateConversionLibraryConfig.AddInConfig.OutputCoordinateList)
                {
                    output.OutputCoordinate = "";
                    output.Props.Clear();
                }
                System.Windows.Forms.MessageBox.Show(CoordinateConversionLibrary.Properties.Resources.InvalidCoordMsg,
                                                     CoordinateConversionLibrary.Properties.Resources.InvalidCoordCap);
            }
            else
            {
                proCoordGetter.Point = ccc.Point;
                var inputCategorySelection = Enum.GetValues(typeof(CoordinateTypes)).Cast <CoordinateTypes>().Where(x => x.ToString() == ccc.Type.ToString()).FirstOrDefault();
                //switch (CoordinateBase.InputCategorySelection)
                switch (inputCategorySelection)
                {
                case CoordinateTypes.DD:
                    if (ccc.GetType() == typeof(CoordinateDD))
                    {
                        var pointInformationDD = (CoordinateDD)ccc.PointInformation;
                        result = new CoordinateDD(pointInformationDD.Lat, pointInformationDD.Lon).ToString("", new CoordinateDDFormatter());
                    }
                    else
                    {
                        result = new CoordinateDD(ccc.Point.Y, ccc.Point.X).ToString("", new CoordinateDDFormatter());
                    }
                    break;

                case CoordinateTypes.DDM:
                    if (ccc.GetType() == typeof(CoordinateDDM))
                    {
                        var pointInformationDDM = (CoordinateDDM)ccc.PointInformation;
                        result = new CoordinateDDM(pointInformationDDM.LatDegrees, pointInformationDDM.LatMinutes, pointInformationDDM.LonDegrees, pointInformationDDM.LonMinutes)
                                 .ToString("", new CoordinateDDMFormatter());
                    }
                    else
                    {
                        result = new CoordinateDDM(new CoordinateDD(ccc.Point.Y, ccc.Point.X))
                                 .ToString("", new CoordinateDDMFormatter());
                    }
                    break;

                case CoordinateTypes.DMS:
                    if (ccc.GetType() == typeof(CoordinateDMS))
                    {
                        var pointInformationDMS = (CoordinateDMS)ccc.PointInformation;
                        result = new CoordinateDMS(pointInformationDMS.LatDegrees, pointInformationDMS.LatMinutes, pointInformationDMS.LatSeconds,
                                                   pointInformationDMS.LonDegrees, pointInformationDMS.LonMinutes, pointInformationDMS.LonSeconds)
                                 .ToString("", new CoordinateDMSFormatter());
                    }
                    else
                    {
                        result = new CoordinateDMS(new CoordinateDD(ccc.Point.Y, ccc.Point.X))
                                 .ToString("", new CoordinateDMSFormatter());
                    }
                    break;

                case CoordinateTypes.MGRS:
                    var pointInformationMGRS = (CoordinateMGRS)ccc.PointInformation;
                    if (ccc.GetType() == typeof(CoordinateMGRS))
                    {
                        result = new CoordinateMGRS(pointInformationMGRS.GZD, pointInformationMGRS.GS, pointInformationMGRS.Easting, pointInformationMGRS.Northing)
                                 .ToString();
                    }
                    else
                    {
                        result = new CoordinateMGRS(pointInformationMGRS.GZD, pointInformationMGRS.GS, pointInformationMGRS.Easting, pointInformationMGRS.Northing)
                                 .ToString("", new CoordinateMGRSFormatter());
                    }
                    break;

                case CoordinateTypes.USNG:
                    var pointInformationUSNG = (CoordinateUSNG)ccc.PointInformation;
                    result = new CoordinateUSNG(pointInformationUSNG.GZD, pointInformationUSNG.GS, pointInformationUSNG.Easting, pointInformationUSNG.Northing)
                             .ToString();
                    break;

                case CoordinateTypes.UTM:
                    var pointInformationUTM = (CoordinateUTM)ccc.PointInformation;
                    result = new CoordinateUTM(pointInformationUTM.Zone, pointInformationUTM.Band, pointInformationUTM.Easting, pointInformationUTM.Northing)
                             .ToString();
                    break;

                case CoordinateTypes.None:
                    break;

                case CoordinateTypes.Custom:
                    break;

                default:
                    break;
                }
            }

            return(result);
        }
Ejemplo n.º 13
0
        private async Task <CCCoordinate> GetCoordinateType(string input)
        {
            MapPoint point = null;

            // DD
            CoordinateDD dd;

            if (CoordinateDD.TryParse(input, out dd, true))
            {
                if (dd.Lat > 90 || dd.Lat < -90 || dd.Lon > 180 || dd.Lon < -180)
                {
                    return new CCCoordinate()
                           {
                               Type = CoordinateType.Unknown, Point = null
                           }
                }
                ;
                point = await QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                });//.Result;

                return(new CCCoordinate()
                {
                    Type = CoordinateType.DD, Point = point, PointInformation = dd
                });
            }

            // DDM
            CoordinateDDM ddm;

            if (CoordinateDDM.TryParse(input, out ddm, true))
            {
                dd = new CoordinateDD(ddm);
                if (dd.Lat > 90 || dd.Lat < -90 || dd.Lon > 180 || dd.Lon < -180)
                {
                    return new CCCoordinate()
                           {
                               Type = CoordinateType.Unknown, Point = null
                           }
                }
                ;
                point = await QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                });//.Result;

                return(new CCCoordinate()
                {
                    Type = CoordinateType.DDM, Point = point, PointInformation = ddm
                });
            }
            // DMS
            CoordinateDMS dms;

            if (CoordinateDMS.TryParse(input, out dms, true))
            {
                dd = new CoordinateDD(dms);
                if (dd.Lat > 90 || dd.Lat < -90 || dd.Lon > 180 || dd.Lon < -180)
                {
                    return new CCCoordinate()
                           {
                               Type = CoordinateType.Unknown, Point = null
                           }
                }
                ;
                point = await QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                });//.Result;

                return(new CCCoordinate()
                {
                    Type = CoordinateType.DMS, Point = point, PointInformation = dms
                });
            }

            CoordinateGARS gars;

            if (CoordinateGARS.TryParse(input, out gars))
            {
                try
                {
                    point = await QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(gars.ToString("", new CoordinateGARSFormatter()), sptlRef, GeoCoordinateType.GARS, FromGeoCoordinateMode.Default);
                        return(tmp);
                    });//.Result;

                    return(new CCCoordinate()
                    {
                        Type = CoordinateType.GARS, Point = point, PointInformation = gars
                    });
                }
                catch { }
            }

            CoordinateMGRS mgrs;

            if (CoordinateMGRS.TryParse(input, out mgrs))
            {
                try
                {
                    point = await QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(mgrs.ToString(), sptlRef, GeoCoordinateType.MGRS, FromGeoCoordinateMode.Default);
                        return(tmp);
                    });//.Result;

                    return(new CCCoordinate()
                    {
                        Type = CoordinateType.MGRS, Point = point, PointInformation = mgrs
                    });
                }
                catch { }
            }

            CoordinateUSNG usng;

            if (CoordinateUSNG.TryParse(input, out usng))
            {
                try
                {
                    point = await QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(usng.ToString("", new CoordinateMGRSFormatter()), sptlRef, GeoCoordinateType.USNG, FromGeoCoordinateMode.Default);
                        return(tmp);
                    });//.Result;

                    return(new CCCoordinate()
                    {
                        Type = CoordinateType.USNG, Point = point, PointInformation = usng
                    });
                }
                catch { }
            }

            CoordinateUTM utm;

            if (CoordinateUTM.TryParse(input, out utm))
            {
                try
                {
                    point = await QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(utm.ToString("", new CoordinateUTMFormatter()), sptlRef, GeoCoordinateType.UTM, FromGeoCoordinateMode.Default);
                        return(tmp);
                    });//.Result;

                    return(new CCCoordinate()
                    {
                        Type = CoordinateType.UTM, Point = point, PointInformation = utm
                    });
                }
                catch { }
            }

            /*
             * Updated RegEx to capture invalid coordinates like 00, 45, or 456987.
             */
            Regex regexMercator = new Regex(@"^(?<latitude>\-?\d+[.,]?\d*)[+,;:\s]{1,}(?<longitude>\-?\d+[.,]?\d*)");

            var matchMercator = regexMercator.Match(input);

            if (matchMercator.Success && matchMercator.Length == input.Length)
            {
                try
                {
                    var Lat = Double.Parse(matchMercator.Groups["latitude"].Value);
                    var Lon = Double.Parse(matchMercator.Groups["longitude"].Value);
                    var sr  = proCoordGetter.Point != null ? proCoordGetter.Point.SpatialReference : SpatialReferences.WebMercator;
                    point = await QueuedTask.Run(() =>
                    {
                        return(MapPointBuilder.CreateMapPoint(Lon, Lat, sr));
                    });//.Result;

                    return(new CCCoordinate()
                    {
                        Type = CoordinateType.DD, Point = point
                    });
                }
                catch (Exception)
                {
                    return(new CCCoordinate()
                    {
                        Type = CoordinateType.Unknown, Point = null
                    });
                }
            }

            return(new CCCoordinate()
            {
                Type = CoordinateType.Unknown, Point = null
            });
        }
    }
}
Ejemplo n.º 14
0
        public Dictionary <string, string> GetOutputFormats(AddInPoint input)
        {
            var    results = new Dictionary <string, string>();
            IPoint point;
            var    inputText = input.Point.Y + " " + input.Point.X;
            var    ctype     = GetCoordinateType(inputText, out point);

            if (point != null)
            {
                ArcMapCoordinateGet arcMapCoordinateGetter = new ArcMapCoordinateGet();
                arcMapCoordinateGetter.Point = point;
                CoordinateGetBase coordinateGetter = arcMapCoordinateGetter as CoordinateGetBase;
                results.Add(CoordinateFieldName, input.Text);
                CoordinateBase.IsOutputInProcess = true;
                foreach (var output in CoordinateConversionLibraryConfig.AddInConfig.OutputCoordinateList)
                {
                    var    props = new Dictionary <string, string>();
                    string coord = string.Empty;

                    switch (output.CType)
                    {
                    case CoordinateType.DD:
                        CoordinateDD cdd;
                        if (coordinateGetter.CanGetDD(output.SRFactoryCode, out coord) &&
                            CoordinateDD.TryParse(coord, out cdd, true))
                        {
                            results.Add(output.Name, cdd.ToString(output.Format, new CoordinateDDFormatter()));
                        }
                        break;

                    case CoordinateType.DMS:
                        CoordinateDMS cdms;
                        if (coordinateGetter.CanGetDMS(output.SRFactoryCode, out coord) &&
                            CoordinateDMS.TryParse(coord, out cdms, true))
                        {
                            results.Add(output.Name, cdms.ToString(output.Format, new CoordinateDMSFormatter()));
                        }
                        break;

                    case CoordinateType.DDM:
                        CoordinateDDM ddm;
                        if (coordinateGetter.CanGetDDM(output.SRFactoryCode, out coord) &&
                            CoordinateDDM.TryParse(coord, out ddm, true))
                        {
                            results.Add(output.Name, ddm.ToString(output.Format, new CoordinateDDMFormatter()));
                        }
                        break;

                    case CoordinateType.GARS:
                        CoordinateGARS gars;
                        if (coordinateGetter.CanGetGARS(output.SRFactoryCode, out coord) &&
                            CoordinateGARS.TryParse(coord, out gars))
                        {
                            results.Add(output.Name, gars.ToString(output.Format, new CoordinateGARSFormatter()));
                        }
                        break;

                    case CoordinateType.MGRS:
                        CoordinateMGRS mgrs;
                        if (coordinateGetter.CanGetMGRS(output.SRFactoryCode, out coord) &&
                            CoordinateMGRS.TryParse(coord, out mgrs))
                        {
                            results.Add(output.Name, mgrs.ToString(output.Format, new CoordinateMGRSFormatter()));
                        }
                        break;

                    case CoordinateType.USNG:
                        CoordinateUSNG usng;
                        if (coordinateGetter.CanGetUSNG(output.SRFactoryCode, out coord) &&
                            CoordinateUSNG.TryParse(coord, out usng))
                        {
                            results.Add(output.Name, usng.ToString(output.Format, new CoordinateMGRSFormatter()));
                        }
                        break;

                    case CoordinateType.UTM:
                        CoordinateUTM utm;
                        if (coordinateGetter.CanGetUTM(output.SRFactoryCode, out coord) &&
                            CoordinateUTM.TryParse(coord, out utm))
                        {
                            results.Add(output.Name, utm.ToString(output.Format, new CoordinateUTMFormatter()));
                        }
                        break;

                    default:
                        break;
                    }
                }
                CoordinateBase.IsOutputInProcess = false;
            }
            return(results);
        }
Ejemplo n.º 15
0
        private CoordinateType GetCoordinateType(string input, out MapPoint point)
        {
            point = null;

            // DD
            CoordinateDD dd;

            if (CoordinateDD.TryParse(input, out dd))
            {
                point = QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                }).Result;
                return(CoordinateType.DD);
            }

            // DDM
            CoordinateDDM ddm;

            if (CoordinateDDM.TryParse(input, out ddm))
            {
                dd    = new CoordinateDD(ddm);
                point = QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                }).Result;
                return(CoordinateType.DDM);
            }
            // DMS
            CoordinateDMS dms;

            if (CoordinateDMS.TryParse(input, out dms))
            {
                dd    = new CoordinateDD(dms);
                point = QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                }).Result;
                return(CoordinateType.DMS);
            }

            CoordinateGARS gars;

            if (CoordinateGARS.TryParse(input, out gars))
            {
                try
                {
                    point = QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(gars.ToString("", new CoordinateGARSFormatter()), sptlRef, GeoCoordinateType.GARS, FromGeoCoordinateMode.Default);
                        return(tmp);
                    }).Result;

                    return(CoordinateType.GARS);
                }
                catch { }
            }

            CoordinateMGRS mgrs;

            if (CoordinateMGRS.TryParse(input, out mgrs))
            {
                try
                {
                    point = QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(mgrs.ToString("", new CoordinateMGRSFormatter()), sptlRef, GeoCoordinateType.MGRS, FromGeoCoordinateMode.Default);
                        return(tmp);
                    }).Result;

                    return(CoordinateType.MGRS);
                }
                catch { }
            }

            CoordinateUSNG usng;

            if (CoordinateUSNG.TryParse(input, out usng))
            {
                try
                {
                    point = QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(usng.ToString("", new CoordinateMGRSFormatter()), sptlRef, GeoCoordinateType.USNG, FromGeoCoordinateMode.Default);
                        return(tmp);
                    }).Result;

                    return(CoordinateType.USNG);
                }
                catch { }
            }

            CoordinateUTM utm;

            if (CoordinateUTM.TryParse(input, out utm))
            {
                try
                {
                    point = QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(utm.ToString("", new CoordinateUTMFormatter()), sptlRef, GeoCoordinateType.UTM, FromGeoCoordinateMode.Default);
                        return(tmp);
                    }).Result;

                    return(CoordinateType.UTM);
                }
                catch { }
            }

            Regex regexMercator = new Regex(@"^(?<latitude>\-?\d+[.,]?\d*)[+,;:\s]*(?<longitude>\-?\d+[.,]?\d*)");

            var matchMercator = regexMercator.Match(input);

            if (matchMercator.Success && matchMercator.Length == input.Length)
            {
                try
                {
                    var Lat = Double.Parse(matchMercator.Groups["latitude"].Value);
                    var Lon = Double.Parse(matchMercator.Groups["longitude"].Value);
                    var sr  = proCoordGetter.Point != null ? proCoordGetter.Point.SpatialReference : SpatialReferences.WebMercator;
                    point = QueuedTask.Run(() =>
                    {
                        return(MapPointBuilder.CreateMapPoint(Lon, Lat, sr));
                    }).Result;
                    return(CoordinateType.DD);
                }
                catch (Exception ex)
                {
                    return(CoordinateType.Unknown);
                }
            }

            return(CoordinateType.Unknown);
        }
        public string ProcessInput(string inputData)
        {
            CoordinateBase PointInformation;

            ESRI.ArcGIS.Geometry.IPoint point;
            var result = "";

            var ctype = GetCoordinateType(inputData, out point, out PointInformation);
            var inputCategorySelection = Enum.GetValues(typeof(CoordinateTypes)).Cast <CoordinateTypes>().Where(x => x.ToString() == ctype.ToString()).FirstOrDefault();

            switch (inputCategorySelection)
            {
            case CoordinateTypes.DD:
                if (ctype.ToString() == CoordinateTypes.DD.ToString())
                {
                    var pointInformationDD = (CoordinateDD)PointInformation;
                    result = new CoordinateDD(pointInformationDD.Lat, pointInformationDD.Lon).ToString("", new CoordinateDDFormatter());
                }
                else
                {
                    result = new CoordinateDD(point.Y, point.X).ToString("", new CoordinateDDFormatter());
                }
                break;

            case CoordinateTypes.DDM:
                if (ctype.ToString() == CoordinateTypes.DDM.ToString())
                {
                    var pointInformationDDM = (CoordinateDDM)PointInformation;
                    result = new CoordinateDDM(pointInformationDDM.LatDegrees, pointInformationDDM.LatMinutes, pointInformationDDM.LonDegrees, pointInformationDDM.LonMinutes)
                             .ToString("", new CoordinateDDMFormatter());
                }
                else
                {
                    result = new CoordinateDDM(new CoordinateDD(point.Y, point.X))
                             .ToString("", new CoordinateDDMFormatter());
                }
                break;

            case CoordinateTypes.DMS:
                if (ctype.ToString() == CoordinateTypes.DMS.ToString())
                {
                    var pointInformationDMS = (CoordinateDMS)PointInformation;
                    result = new CoordinateDMS(pointInformationDMS.LatDegrees, pointInformationDMS.LatMinutes, pointInformationDMS.LatSeconds,
                                               pointInformationDMS.LonDegrees, pointInformationDMS.LonMinutes, pointInformationDMS.LonSeconds)
                             .ToString("", new CoordinateDMSFormatter());
                }
                else
                {
                    result = new CoordinateDDM(new CoordinateDD(point.Y, point.X))
                             .ToString("", new CoordinateDMSFormatter());
                }
                break;

            case CoordinateTypes.MGRS:
                var pointInformationMGRS = (CoordinateMGRS)PointInformation;
                result = new CoordinateMGRS(pointInformationMGRS.GZD, pointInformationMGRS.GS, pointInformationMGRS.Easting, pointInformationMGRS.Northing)
                         .ToString("", new CoordinateMGRSFormatter());
                break;

            case CoordinateTypes.USNG:
                var pointInformationUSNG = (CoordinateUSNG)PointInformation;
                result = new CoordinateUSNG(pointInformationUSNG.GZD, pointInformationUSNG.GS, pointInformationUSNG.Easting, pointInformationUSNG.Northing)
                         .ToString();
                break;

            case CoordinateTypes.UTM:
                var pointInformationUTM = (CoordinateUTM)PointInformation;
                result = new CoordinateUTM(pointInformationUTM.Zone, pointInformationUTM.Band, pointInformationUTM.Easting, pointInformationUTM.Northing)
                         .ToString();
                break;

            case CoordinateTypes.None:
                break;

            case CoordinateTypes.Custom:
                break;

            default:
                break;
            }
            return(result);
        }
Ejemplo n.º 17
0
        private CoordinateType GetCoordinateType(string input, out ESRI.ArcGIS.Geometry.IPoint point)
        {
            point = new PointClass();
            var  cn = (IConversionNotation)point;
            Type t  = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");

            if (t == null)
            {
                return(CoordinateType.Unknown);
            }

            System.Object obj = Activator.CreateInstance(t);
            if (obj == null)
            {
                return(CoordinateType.Unknown);
            }

            ISpatialReferenceFactory srFact = obj as ISpatialReferenceFactory;

            if (srFact == null)
            {
                return(CoordinateType.Unknown);
            }

            // Use the enumeration to create an instance of the predefined object.
            IGeographicCoordinateSystem geographicCS =
                srFact.CreateGeographicCoordinateSystem((int)
                                                        esriSRGeoCSType.esriSRGeoCS_WGS1984);

            point.SpatialReference = geographicCS;
            string numSep = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;

            input = numSep != "." ? input.Replace(numSep, ".") : input;

            try
            {
                CoordinateDD dd;
                if (CoordinateDD.TryParse(input, out dd, true))
                {
                    // Reformat the string for cases where lat/lon have been switched
                    // PutCoords calls fail if the double uses decimal separator other than a decimal point
                    // Added InvariantCulture option to ensure the current culture is ignored
                    string newInput = string.Format(CultureInfo.InvariantCulture, "{0} {1}", dd.Lat, dd.Lon);
                    cn.PutCoordsFromDD(newInput);

                    return(CoordinateType.DD);
                }
            }
            catch { /* Conversion Failed */ }

            try
            {
                CoordinateDDM ddm;
                if (CoordinateDDM.TryParse(input, out ddm, true))
                {
                    // Reformat the string for cases where lat/lon have been switched
                    // PutCoords calls fail if the double uses decimal separator other than a decimal point
                    // Added InvariantCulture option to ensure the current culture is ignored
                    string newInput = string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", ddm.LatDegrees, ddm.LatMinutes, ddm.LonDegrees, ddm.LonMinutes);
                    cn.PutCoordsFromDD(newInput);

                    return(CoordinateType.DDM);
                }
            }
            catch { /* Conversion Failed */ }

            try
            {
                CoordinateDMS dms;
                if (CoordinateDMS.TryParse(input, out dms, true))
                {
                    // Reformat the string for cases where lat/lon have been switched
                    // PutCoords calls fail if the double uses decimal separator other than a decimal point
                    // Added InvariantCulture option to ensure the current culture is ignored
                    string newInput = string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3} {4} {5}", dms.LatDegrees, dms.LatMinutes, dms.LatSeconds, dms.LonDegrees, dms.LonMinutes, dms.LonSeconds);
                    cn.PutCoordsFromDD(newInput);

                    return(CoordinateType.DMS);
                }
            }
            catch { /* Conversion Failed */ }

            try
            {
                cn.PutCoordsFromGARS(esriGARSModeEnum.esriGARSModeCENTER, input);
                return(CoordinateType.GARS);
            }
            catch { /* Conversion Failed */ }

            try
            {
                cn.PutCoordsFromGARS(esriGARSModeEnum.esriGARSModeLL, input);
                return(CoordinateType.GARS);
            }
            catch { /* Conversion Failed */ }

            CoordinateGARS gars;

            if (CoordinateGARS.TryParse(input, out gars))
            {
                try
                {
                    cn.PutCoordsFromGARS(esriGARSModeEnum.esriGARSModeCENTER, gars.ToString("", new CoordinateGARSFormatter()));
                    return(CoordinateType.GARS);
                }
                catch { /* Conversion Failed */ }
            }

            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_Automatic);
                return(CoordinateType.MGRS);
            }
            catch { /* Conversion Failed */ }
            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_NewStyle);
                return(CoordinateType.MGRS);
            }
            catch { /* Conversion Failed */ }
            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_NewWith180InZone01);
                return(CoordinateType.MGRS);
            }
            catch { /* Conversion Failed */ }
            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_OldStyle);
                return(CoordinateType.MGRS);
            }
            catch { /* Conversion Failed */ }
            try
            {
                cn.PutCoordsFromMGRS(input, esriMGRSModeEnum.esriMGRSMode_OldWith180InZone01);
                return(CoordinateType.MGRS);
            }
            catch { /* Conversion Failed */ }

            // mgrs try parse
            CoordinateMGRS mgrs;

            if (CoordinateMGRS.TryParse(input, out mgrs))
            {
                try
                {
                    cn.PutCoordsFromMGRS(mgrs.ToString("", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_NewStyle);
                    return(CoordinateType.MGRS);
                }
                catch { /* Conversion Failed */ }
            }

            try
            {
                cn.PutCoordsFromUSNG(input);
                return(CoordinateType.USNG);
            }
            catch { /* Conversion Failed */ }

            CoordinateUSNG usng;

            if (CoordinateUSNG.TryParse(input, out usng))
            {
                try
                {
                    cn.PutCoordsFromUSNG(usng.ToString("", new CoordinateMGRSFormatter()));
                    return(CoordinateType.USNG);
                }
                catch { /* Conversion Failed */ }
            }

            try
            {
                cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMAddSpaces, input);
                return(CoordinateType.UTM);
            }
            catch { /* Conversion Failed */ }

            try
            {
                cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMNoOptions, input);
                return(CoordinateType.UTM);
            }
            catch { /* Conversion Failed */ }

            try
            {
                cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMUseNS, input);
                return(CoordinateType.UTM);
            }
            catch { /* Conversion Failed */ }

            CoordinateUTM utm;

            if (CoordinateUTM.TryParse(input, out utm))
            {
                try
                {
                    cn.PutCoordsFromUTM(esriUTMConversionOptionsEnum.esriUTMNoOptions, utm.ToString("", new CoordinateUTMFormatter()));
                    return(CoordinateType.UTM);
                }
                catch { /* Conversion Failed */ }
            }

            /*
             * Updated RegEx to capture invalid coordinates like 00, 45, or 456987.
             */
            Regex regexMercator = new Regex(@"^(?<latitude>\-?\d+[.,]?\d*)[+,;:\s]{1,}(?<longitude>\-?\d+[.,]?\d*)");

            var matchMercator = regexMercator.Match(input);

            if (matchMercator.Success && matchMercator.Length == input.Length)
            {
                try
                {
                    var  Lat = Double.Parse(matchMercator.Groups["latitude"].Value);
                    var  Lon = Double.Parse(matchMercator.Groups["longitude"].Value);
                    IMap map = ((IMxDocument)ArcMap.Application.Document).FocusMap;
                    var  sr  = map.SpatialReference != null ? map.SpatialReference : ArcMapHelpers.GetSR((int)esriSRProjCS3Type.esriSRProjCS_WGS1984WebMercatorMajorAuxSphere);
                    point.X = Lon;
                    point.Y = Lat;
                    point.SpatialReference = sr;
                    return(CoordinateType.DD);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }

            return(CoordinateType.Unknown);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Returns a formatted coordinate string for an input coordinate string
        /// IMPORTANT: if a coordinate format is not matched:
        /// Returns CoordinateType.Unknown, the input string as the formattedString
        /// </summary>
        /// <param name="input">Input coord string</param>
        /// <param name="formattedString">Formatted coord string</param>
        /// <returns>CoordinateType of the format that matched, Unknown if unmatched</returns>
        public static CoordinateType GetCoordinateString(string input, out string formattedString)
        {
            // We don't want the Ambiguous Coords Dialog to show during these calls
            // But don't overwrite the setting in case user has set to prompt for this
            bool savedAmbigCoordSetting = CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg;

            CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg = false;

            formattedString = input;
            // DD
            CoordinateDD dd;

            if (CoordinateDD.TryParse(input, out dd, true) == true)
            {
                formattedString = dd.ToString("Y0.0#####N X0.0#####E", new CoordinateDDFormatter());
                return(CoordinateType.DD);
            }

            // DDM
            CoordinateDDM ddm;

            if (CoordinateDDM.TryParse(input, out ddm, true) == true)
            {
                dd = new CoordinateDD(ddm);
                formattedString = ddm.ToString("", new CoordinateDDMFormatter());
                return(CoordinateType.DDM);
            }

            // DMS
            CoordinateDMS dms;

            if (CoordinateDMS.TryParse(input, out dms, true) == true)
            {
                dd = new CoordinateDD(dms);
                formattedString = dms.ToString("A0°B0'C0.0##\"N X0°Y0'Z0.0##\"E", new CoordinateDMSFormatter());
                return(CoordinateType.DMS);
            }

            // restore the setting (not needed for others, only DD/DMS
            CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg = savedAmbigCoordSetting;

            // GARS
            CoordinateGARS gars;

            if (CoordinateGARS.TryParse(input, out gars) == true)
            {
                formattedString = gars.ToString("", new CoordinateGARSFormatter());
                return(CoordinateType.GARS);
            }

            // MGRS
            CoordinateMGRS mgrs;

            if (CoordinateMGRS.TryParse(input, out mgrs) == true)
            {
                formattedString = mgrs.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());
                return(CoordinateType.MGRS);
            }

            // USNG
            CoordinateUSNG usng;

            if (CoordinateUSNG.TryParse(input, out usng) == true)
            {
                formattedString = usng.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());
                return(CoordinateType.USNG);
            }

            // UTM
            CoordinateUTM utm;

            if (CoordinateUTM.TryParse(input, out utm) == true)
            {
                formattedString = utm.ToString("", new CoordinateUTMFormatter());
                return(CoordinateType.UTM);
            }

            return(CoordinateType.Unknown);
        }
        private void UpdateOutputs()
        {
            foreach (var output in CoordinateConversionLibraryConfig.AddInConfig.OutputCoordinateList)
            {
                var    props = new Dictionary <string, string>();
                string coord = string.Empty;

                switch (output.CType)
                {
                case CoordinateType.DD:
                    CoordinateDD cdd;
                    if (coordinateGetter.CanGetDD(output.SRFactoryCode, out coord) &&
                        CoordinateDD.TryParse(coord, out cdd))
                    {
                        output.OutputCoordinate = cdd.ToString(output.Format, new CoordinateDDFormatter());
                        var splits = output.Format.Split(new char[] { 'X' }, StringSplitOptions.RemoveEmptyEntries);
                        if (splits.Count() == 2)
                        {
                            props.Add(Properties.Resources.StringLat, cdd.ToString(splits[0].Trim(), new CoordinateDDFormatter()));
                            props.Add(Properties.Resources.StringLon, cdd.ToString("X" + splits[1].Trim(), new CoordinateDDFormatter()));
                        }
                        else
                        {
                            splits = output.Format.Split(new char[] { 'Y' }, StringSplitOptions.RemoveEmptyEntries);
                            if (splits.Count() == 2)
                            {
                                props.Add(Properties.Resources.StringLon, cdd.ToString(splits[0].Trim(), new CoordinateDDFormatter()));
                                props.Add(Properties.Resources.StringLat, cdd.ToString("Y" + splits[1].Trim(), new CoordinateDDFormatter()));
                            }
                            else
                            {
                                props.Add(Properties.Resources.StringLat, cdd.Lat.ToString());
                                props.Add(Properties.Resources.StringLon, cdd.Lon.ToString());
                            }
                        }
                        output.Props = props;
                    }
                    break;

                case CoordinateType.DMS:
                    CoordinateDMS cdms;
                    if (coordinateGetter.CanGetDMS(output.SRFactoryCode, out coord) &&
                        CoordinateDMS.TryParse(coord, out cdms))
                    {
                        output.OutputCoordinate = cdms.ToString(output.Format, new CoordinateDMSFormatter());
                        var splits = output.Format.Split(new char[] { 'X' }, StringSplitOptions.RemoveEmptyEntries);
                        if (splits.Count() == 2)
                        {
                            props.Add(Properties.Resources.StringLat, cdms.ToString(splits[0].Trim(), new CoordinateDMSFormatter()));
                            props.Add(Properties.Resources.StringLon, cdms.ToString("X" + splits[1].Trim(), new CoordinateDMSFormatter()));
                        }
                        else
                        {
                            splits = output.Format.Split(new char[] { 'Y' }, StringSplitOptions.RemoveEmptyEntries);
                            if (splits.Count() == 2)
                            {
                                props.Add(Properties.Resources.StringLon, cdms.ToString(splits[0].Trim(), new CoordinateDMSFormatter()));
                                props.Add(Properties.Resources.StringLat, cdms.ToString("Y" + splits[1].Trim(), new CoordinateDMSFormatter()));
                            }
                            else
                            {
                                props.Add(Properties.Resources.StringLat, cdms.ToString("A0°B0'C0.0\"N", new CoordinateDMSFormatter()));
                                props.Add(Properties.Resources.StringLon, cdms.ToString("X0°Y0'Z0.0\"E", new CoordinateDMSFormatter()));
                            }
                        }
                        output.Props = props;
                    }
                    break;

                case CoordinateType.DDM:
                    CoordinateDDM ddm;
                    if (coordinateGetter.CanGetDDM(output.SRFactoryCode, out coord) &&
                        CoordinateDDM.TryParse(coord, out ddm))
                    {
                        output.OutputCoordinate = ddm.ToString(output.Format, new CoordinateDDMFormatter());
                        var splits = output.Format.Split(new char[] { 'X' }, StringSplitOptions.RemoveEmptyEntries);
                        if (splits.Count() == 2)
                        {
                            props.Add(Properties.Resources.StringLat, ddm.ToString(splits[0].Trim(), new CoordinateDDMFormatter()));
                            props.Add(Properties.Resources.StringLon, ddm.ToString("X" + splits[1].Trim(), new CoordinateDDMFormatter()));
                        }
                        else
                        {
                            splits = output.Format.Split(new char[] { 'Y' }, StringSplitOptions.RemoveEmptyEntries);
                            if (splits.Count() == 2)
                            {
                                props.Add(Properties.Resources.StringLon, ddm.ToString(splits[0].Trim(), new CoordinateDDMFormatter()));
                                props.Add(Properties.Resources.StringLat, ddm.ToString("Y" + splits[1].Trim(), new CoordinateDDMFormatter()));
                            }
                            else
                            {
                                props.Add(Properties.Resources.StringLat, ddm.ToString("A0°B0.0#####'N", new CoordinateDDMFormatter()));
                                props.Add(Properties.Resources.StringLon, ddm.ToString("X0°Y0.0#####'E", new CoordinateDDMFormatter()));
                            }
                        }
                        output.Props = props;
                    }
                    break;

                case CoordinateType.GARS:
                    CoordinateGARS gars;
                    if (coordinateGetter.CanGetGARS(output.SRFactoryCode, out coord) &&
                        CoordinateGARS.TryParse(coord, out gars))
                    {
                        output.OutputCoordinate = gars.ToString(output.Format, new CoordinateGARSFormatter());
                        props.Add(Properties.Resources.StringLon, gars.LonBand.ToString());
                        props.Add(Properties.Resources.StringLat, gars.LatBand);
                        props.Add(Properties.Resources.StringQuadrant, gars.Quadrant.ToString());
                        props.Add(Properties.Resources.StringKey, gars.Key.ToString());
                        output.Props = props;
                    }
                    break;

                case CoordinateType.MGRS:
                    CoordinateMGRS mgrs;
                    if (coordinateGetter.CanGetMGRS(output.SRFactoryCode, out coord) &&
                        CoordinateMGRS.TryParse(coord, out mgrs))
                    {
                        output.OutputCoordinate = mgrs.ToString(output.Format, new CoordinateMGRSFormatter());
                        props.Add(Properties.Resources.StringGZD, mgrs.GZD);
                        props.Add(Properties.Resources.StringGridSq, mgrs.GS);
                        props.Add(Properties.Resources.StringEasting, mgrs.Easting.ToString("00000"));
                        props.Add(Properties.Resources.StringNorthing, mgrs.Northing.ToString("00000"));
                        output.Props = props;
                    }
                    break;

                case CoordinateType.USNG:
                    CoordinateUSNG usng;
                    if (coordinateGetter.CanGetUSNG(output.SRFactoryCode, out coord) &&
                        CoordinateUSNG.TryParse(coord, out usng))
                    {
                        output.OutputCoordinate = usng.ToString(output.Format, new CoordinateMGRSFormatter());
                        props.Add(Properties.Resources.StringGZD, usng.GZD);
                        props.Add(Properties.Resources.StringGridSq, usng.GS);
                        props.Add(Properties.Resources.StringEasting, usng.Easting.ToString("00000"));
                        props.Add(Properties.Resources.StringNorthing, usng.Northing.ToString("00000"));
                        output.Props = props;
                    }
                    break;

                case CoordinateType.UTM:
                    CoordinateUTM utm;
                    if (coordinateGetter.CanGetUTM(output.SRFactoryCode, out coord) &&
                        CoordinateUTM.TryParse(coord, out utm))
                    {
                        output.OutputCoordinate = utm.ToString(output.Format, new CoordinateUTMFormatter());
                        props.Add(Properties.Resources.StringZone, utm.Zone.ToString() + utm.Hemi);
                        props.Add(Properties.Resources.StringEasting, utm.Easting.ToString("000000"));
                        props.Add(Properties.Resources.StringNorthing, utm.Northing.ToString("0000000"));
                        output.Props = props;
                    }
                    break;

                default:
                    break;
                }
            }
        }
        private CoordinateType GetCoordinateType(string input, out MapPoint point)
        {
            point = null;

            // DD
            CoordinateDD dd;

            if (CoordinateDD.TryParse(input, out dd))
            {
                point = QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                }).Result;
                return(CoordinateType.DD);
            }

            // DDM
            CoordinateDDM ddm;

            if (CoordinateDDM.TryParse(input, out ddm))
            {
                dd    = new CoordinateDD(ddm);
                point = QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                }).Result;
                return(CoordinateType.DDM);
            }
            // DMS
            CoordinateDMS dms;

            if (CoordinateDMS.TryParse(input, out dms))
            {
                dd    = new CoordinateDD(dms);
                point = QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                    return(MapPointBuilder.CreateMapPoint(dd.Lon, dd.Lat, sptlRef));
                }).Result;
                return(CoordinateType.DMS);
            }

            CoordinateGARS gars;

            if (CoordinateGARS.TryParse(input, out gars))
            {
                try
                {
                    point = QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(gars.ToString("", new CoordinateGARSFormatter()), sptlRef, GeoCoordinateType.GARS, FromGeoCoordinateMode.Default);
                        return(tmp);
                    }).Result;

                    return(CoordinateType.GARS);
                }
                catch { }
            }

            CoordinateMGRS mgrs;

            if (CoordinateMGRS.TryParse(input, out mgrs))
            {
                try
                {
                    point = QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(mgrs.ToString("", new CoordinateMGRSFormatter()), sptlRef, GeoCoordinateType.MGRS, FromGeoCoordinateMode.Default);
                        return(tmp);
                    }).Result;

                    return(CoordinateType.MGRS);
                }
                catch { }
            }

            CoordinateUSNG usng;

            if (CoordinateUSNG.TryParse(input, out usng))
            {
                try
                {
                    point = QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(usng.ToString("", new CoordinateMGRSFormatter()), sptlRef, GeoCoordinateType.USNG, FromGeoCoordinateMode.Default);
                        return(tmp);
                    }).Result;

                    return(CoordinateType.USNG);
                }
                catch { }
            }

            CoordinateUTM utm;

            if (CoordinateUTM.TryParse(input, out utm))
            {
                try
                {
                    point = QueuedTask.Run(() =>
                    {
                        ArcGIS.Core.Geometry.SpatialReference sptlRef = SpatialReferenceBuilder.CreateSpatialReference(4326);
                        var tmp = MapPointBuilder.FromGeoCoordinateString(utm.ToString("", new CoordinateUTMFormatter()), sptlRef, GeoCoordinateType.UTM, FromGeoCoordinateMode.Default);
                        return(tmp);
                    }).Result;

                    return(CoordinateType.UTM);
                }
                catch { }
            }


            return(CoordinateType.Unknown);
        }
        public static string GetFormattedCoord(CoordinateType cType, string coord, string format)
        {
            if (cType == CoordinateType.DD)
            {
                CoordinateDD dd;
                if (CoordinateDD.TryParse(coord, out dd))
                {
                    return(dd.ToString(format, new CoordinateDDFormatter()));
                }
            }
            if (cType == CoordinateType.DDM)
            {
                CoordinateDDM ddm;
                if (CoordinateDDM.TryParse(coord, out ddm))
                {
                    return(ddm.ToString(format, new CoordinateDDMFormatter()));
                }
            }
            if (cType == CoordinateType.DMS)
            {
                CoordinateDMS dms;
                if (CoordinateDMS.TryParse(coord, out dms))
                {
                    return(dms.ToString(format, new CoordinateDMSFormatter()));
                }
            }
            if (cType == CoordinateType.GARS)
            {
                CoordinateGARS gars;
                if (CoordinateGARS.TryParse(coord, out gars))
                {
                    return(gars.ToString(format, new CoordinateGARSFormatter()));
                }
            }
            if (cType == CoordinateType.MGRS)
            {
                CoordinateMGRS mgrs;
                if (CoordinateMGRS.TryParse(coord, out mgrs))
                {
                    return(mgrs.ToString(format, new CoordinateMGRSFormatter()));
                }
            }
            if (cType == CoordinateType.USNG)
            {
                CoordinateUSNG usng;
                if (CoordinateUSNG.TryParse(coord, out usng))
                {
                    return(usng.ToString(format, new CoordinateMGRSFormatter()));
                }
            }
            if (cType == CoordinateType.UTM)
            {
                CoordinateUTM utm;
                if (CoordinateUTM.TryParse(coord, out utm))
                {
                    return(utm.ToString(format, new CoordinateUTMFormatter()));
                }
            }

            return(null);
        }