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;
}