public void FormatterMGRS()
        {
            var coord = new CoordinateMGRS("17T", "PE", 83016, 60286);
            var temp  = coord.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());

            Assert.AreEqual(temp, "17TPE8301660286");

            temp = coord.ToString("Z S X00000 Y00000", new CoordinateMGRSFormatter());
            Assert.AreEqual(temp, "17T PE 83016 60286");

            temp = coord.ToString("Z,S,X00000,Y00000", new CoordinateMGRSFormatter());
            Assert.AreEqual(temp, "17T,PE,83016,60286");

            temp = coord.ToString("Z-S-X00000-Y00000", new CoordinateMGRSFormatter());
            Assert.AreEqual(temp, "17T-PE-83016-60286");

            temp = coord.ToString("ZS X00000Y00000", new CoordinateMGRSFormatter());
            Assert.AreEqual(temp, "17TPE 8301660286");

            temp = coord.ToString("ZS X00000 Y00000", new CoordinateMGRSFormatter());
            Assert.AreEqual(temp, "17TPE 83016 60286");

            // test the default
            temp = coord.ToString("", new CoordinateMGRSFormatter());
            Assert.AreEqual(temp, "17TPE8301660286");
        }
示例#2
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);
        }
示例#3
0
        private IPolygon GetMGRSPolygon(IPoint point)
        {
            CoordinateMGRS mgrs;

            IPointCollection pc = new RingClass();

            // bottom left
            CoordinateMGRS.TryParse(InputCoordinate, out mgrs);

            // don't create a polygon for 1m resolution
            if (mgrs.Easting.ToString().Length > 4 && mgrs.Northing.ToString().Length > 4)
            {
                return(null);
            }

            var tempPoint = new PointClass() as IConversionNotation;

            (tempPoint as IPoint).SpatialReference = GetSR();
            var anotherMGRSstring = mgrs.ToString("", new CoordinateMGRSFormatter());

            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top left
            var tempMGRS    = new CoordinateMGRS(mgrs.GZD, mgrs.GS, mgrs.Easting, mgrs.Northing);
            var tempEasting = mgrs.Easting.ToString().PadRight(5, '0');

            tempMGRS.Easting = Convert.ToInt32(tempEasting);
            var tempNorthing = mgrs.Northing.ToString().PadRight(5, '9');

            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            anotherMGRSstring = tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top right
            tempEasting       = mgrs.Easting.ToString().PadRight(5, '9');
            tempMGRS.Easting  = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing      = mgrs.Northing.ToString().PadRight(5, '9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // bottom right
            tempEasting       = mgrs.Easting.ToString().PadRight(5, '9');
            tempMGRS.Easting  = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing      = mgrs.Northing.ToString().PadRight(5, '0');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing);

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // create polygon
            var poly = new PolygonClass();

            poly.SpatialReference = GetSR();
            poly.AddPointCollection(pc);
            poly.Close();

            return(poly);
        }