public String ToMgrsString(Int16 digits) { String result = String.Empty; Int16 actualDigits = MakeDigitValid(digits); String northing = Northing.ToString("0000000"); String easting = Easting.ToString("0000000"); String eastingLetters = MgrsEastingChars(ZoneNumber); Int32 eastingIdentifier = Convert.ToInt32(easting.Substring(0, 2)) % 8; if (eastingIdentifier != 0) { String eastingChar = eastingLetters.Substring(eastingIdentifier - 1, 1); Int32 northingIdentifier = Convert.ToInt32(northing.Substring(0, 1)); northingIdentifier = (northingIdentifier % 2) * 10; northingIdentifier = northingIdentifier + Convert.ToInt32(northing.Substring(1, 1)); String northingLetters = MgrsNorthingChars(ZoneNumber); String northingChar = northingLetters.Substring(northingIdentifier, 1); result = ZoneNumber.ToString("00") + ZoneBand() + ' ' + eastingChar + northingChar + ' ' + easting.Substring(2, actualDigits - 2) + northing.Substring(2, actualDigits - 2); } return(result); }
public String ToUtmString(Int16 digits) { Int16 actualDigits = MakeDigitValid(digits); String northing = Northing.ToString("0000000"); String easting = Easting.ToString("0000000"); easting = easting.Substring(0, actualDigits); northing = northing.Substring(0, actualDigits); String result = ZoneNumber.ToString("00") + ZoneBand() + ' ' + easting + ' ' + northing; return(result); }
public override string ToString() { var sb = new StringBuilder(); //vnum line sb.Append("#"); sb.AppendLine(VNUM.ToString()); //title line sb.Append(Title); sb.AppendLine("~"); //description sb.AppendLine(MainDescription); sb.AppendLine("~"); // zone number, flags, sector line sb.Append(ZoneNumber.ToString()); // space before flags sb.Append(" "); if (RoomFlags.Count == 0) { sb.Append("0"); } else { var sortedRoomFlags = RoomFlags.OrderBy(rf => (int)rf); sb.Append("^"); // prepend the first item's caret, take care of the rest with this join sb.Append(string.Join("|^", sortedRoomFlags.Select(x => ((int)x).ToString()).ToArray())); } // space before sector sb.Append(" "); sb.AppendLine(((int)SectorType).ToString()); // exits - only get the ones that are enabled var sortedExits = Exits.OrderBy(e => ((int)e.Direction)).Where(e => e.Enabled == true).ToList(); foreach (var exit in sortedExits) { //D line sb.Append("D"); sb.AppendLine(((int)exit.Direction).ToString()); //Exit description sb.AppendLine(exit.Description); sb.AppendLine("~"); // Door keywords line if (exit.DoorType != DoorType.None) { sb.Append(exit.DoorKeywords); } sb.AppendLine("~"); // Door config line sb.Append(((int)exit.DoorType).ToString()); sb.Append(" "); sb.Append(exit.DoorKeyVnum); sb.Append(" "); sb.AppendLine(exit.DestinationVnum.ToString()); } // extra descriptions foreach (var ex in ExtraDescriptions) { // E line sb.AppendLine("E"); // Extra description keywords line sb.Append(ex.Keywords); sb.AppendLine("~"); // Extra description sb.AppendLine(ex.Description); sb.AppendLine("~"); } // closing S sb.AppendLine("S"); return(sb.ToString()); }
private void LatLongtoUTM(double Lat, double Long, out double UTMNorthing, out double UTMEasting, out string Zone) { double a = 6378137; //WGS84 double eccSquared = 0.00669438; //WGS84 double k0 = 0.9996; double LongOrigin; double eccPrimeSquared; double N, T, C, A, M; //Make sure the longitude is between -180.00 .. 179.9 double LongTemp = (Long + 180) - ((int)((Long + 180) / 360)) * 360 - 180; // -180.00 .. 179.9; double LatRad = DegreesToRadians(Lat); double LongRad = DegreesToRadians(LongTemp); double LongOriginRad; int ZoneNumber; ZoneNumber = ((int)((LongTemp + 180) / 6)) + 1; if (Lat >= 56.0 && Lat < 64.0 && LongTemp >= 3.0 && LongTemp < 12.0) { ZoneNumber = 32; } // Special zones for Svalbard if (Lat >= 72.0 && Lat < 84.0) { if (LongTemp >= 0.0 && LongTemp < 9.0) { ZoneNumber = 31; } else if (LongTemp >= 9.0 && LongTemp < 21.0) { ZoneNumber = 33; } else if (LongTemp >= 21.0 && LongTemp < 33.0) { ZoneNumber = 35; } else if (LongTemp >= 33.0 && LongTemp < 42.0) { ZoneNumber = 37; } } LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin in middle of zone LongOriginRad = DegreesToRadians(LongOrigin); //compute the UTM Zone from the latitude and longitude Zone = ZoneNumber.ToString() + UTMLetterDesignator(Lat); eccPrimeSquared = (eccSquared) / (1 - eccSquared); N = a / Math.Sqrt(1 - eccSquared * Math.Sin(LatRad) * Math.Sin(LatRad)); T = Math.Tan(LatRad) * Math.Tan(LatRad); C = eccPrimeSquared * Math.Cos(LatRad) * Math.Cos(LatRad); A = Math.Cos(LatRad) * (LongRad - LongOriginRad); M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.Sin(2 * LatRad) + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.Sin(4 * LatRad) - (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.Sin(6 * LatRad)); UTMEasting = (double)(k0 * N * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120) + 500000.0); UTMNorthing = (double)(k0 * (M + N * Math.Tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24 + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720))); if (Lat < 0) { UTMNorthing += 10000000.0; //10000000 meter offset for southern hemisphere } }
public static void LLtoUTM(int ReferenceEllipsoid, double Lat, double Long, out double UTMNorthing, out double UTMEasting, out string UTMZone) { //converts lat/long to UTM coords. Equations from USGS Bulletin 1532 //East Longitudes are positive, West longitudes are negative. //North latitudes are positive, South latitudes are negative //Lat and Long are in decimal degrees double a = Constants.ellipsoid[ReferenceEllipsoid].EquatorialRadius; double eccSquared = Constants.ellipsoid[ReferenceEllipsoid].eccentricitySquared; double k0 = 0.9996; double LongOrigin; double eccPrimeSquared; double N, T, C, A, M; //Make sure the longitude is between -180.00 .. 179.9 double LongTemp = (Long + 180) - (Int32)((Long + 180) / 360) * 360 - 180; // -180.00 .. 179.9; double LatRad = Lat * Constants.deg2rad; double LongRad = LongTemp * Constants.deg2rad; double LongOriginRad; int ZoneNumber; ZoneNumber = (Int32)((LongTemp + 180) / 6) + 1; eccPrimeSquared = (eccSquared) / (1 - eccSquared); if (Lat >= 56.0 && Lat < 64.0 && LongTemp >= 3.0 && LongTemp < 12.0) { ZoneNumber = 32; } // Special zones for Svalbard if (Lat >= 72.0 && Lat < 84.0) { if (LongTemp >= 0.0 && LongTemp < 9.0) { ZoneNumber = 31; } else if (LongTemp >= 9.0 && LongTemp < 21.0) { ZoneNumber = 33; } else if (LongTemp >= 21.0 && LongTemp < 33.0) { ZoneNumber = 35; } else if (LongTemp >= 33.0 && LongTemp < 42.0) { ZoneNumber = 37; } } LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin in middle of zone LongOriginRad = LongOrigin * Constants.deg2rad; UTMZone = ZoneNumber.ToString() + UTMLetterDesignator(Lat); N = a / Math.Sqrt(1 - eccSquared * Math.Sin(LatRad) * Math.Sin(LatRad)); T = Math.Tan(LatRad) * Math.Tan(LatRad); C = eccPrimeSquared * Math.Cos(LatRad) * Math.Cos(LatRad); A = Math.Cos(LatRad) * (LongRad - LongOriginRad); M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.Sin(2 * LatRad) + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.Sin(4 * LatRad) - (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.Sin(6 * LatRad)); UTMEasting = (double)(k0 * N * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120) + 500000.0); UTMNorthing = (double)(k0 * (M + N * Math.Tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24 + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720))); if (Lat < 0) { UTMNorthing += 10000000.0; //10000000 meter offset for southern hemisphere } }