/// <summary> /// Create UTM boxes (can be full utm cell of partly utm cell (at edges map)) /// </summary> /// <param name="pLatitudeLines"> /// </param> /// <param name="pLongitudeLines"> /// </param> /// <returns> /// The <see cref="List"/>. /// </returns> private static List<GridZone> CalculateVisibleUtmBoxes( List<double> pLatitudeLines, List<double> pLongitudeLines) { var result = new List<GridZone>(); for (int i = 0; i < pLatitudeLines.Count - 1; i++) { for (int j = 0; j < pLongitudeLines.Count - 1; j++) { if ((pLatitudeLines[i] >= 72 && AlmostEqual(pLongitudeLines[j], 6)) || (pLatitudeLines[i] >= 72 && AlmostEqual(pLongitudeLines[j], 18)) || (pLatitudeLines[i] >= 72 && AlmostEqual(pLongitudeLines[j], 30))) { // do nothing } else { // Substract small var dta = new GridZone( pLatitudeLines[i], pLatitudeLines[i + 1] - CorrectForZoneBorder, pLongitudeLines[j], pLongitudeLines[j + 1] - CorrectForZoneBorder); result.Add(dta); // Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", dta.nlat, dta.wlng, dta.slat, dta.elng)); } } } return result; }
private void RenderMgrsGridCell( DrawingContext pDC, GridZone pCell) { var view = Viewport.Extend; Point[] clipPolygon = new Point[] { new Point(pCell.Extend.WestBoundLongitude, pCell.Extend.NorthBoundLatitude), new Point(pCell.Extend.EastBoundLongitude, pCell.Extend.NorthBoundLatitude), new Point(pCell.Extend.EastBoundLongitude, pCell.Extend.SouthBoundLatitude), new Point(pCell.Extend.WestBoundLongitude, pCell.Extend.SouthBoundLatitude) }; int interval = (int)MgrsGridPrecision; // Number of meters int precision = (int)MgrsGridPrecision; var sw = pCell.SouthWest(); var ne = pCell.NorthEast(); var swUtm = sw.ConvertToUtm(); var neUtm = ne.ConvertToUtm(); var swMgrs = sw.ConvertToMgrs(); Debug.Assert(swUtm.Zone == neUtm.Zone, "UTM cell over multiple zones"); int utmZone = swUtm.Zone; double sw_utm_e = (Math.Floor(swUtm.East / precision) * precision); double sw_utm_n = (Math.Floor(swUtm.North / precision) * precision); double ne_utm_e = (Math.Floor(neUtm.East / precision) * precision); double ne_utm_n = (Math.Floor(neUtm.North / precision) * precision); int numberOfCells = (((int)(Math.Abs(sw_utm_n - ne_utm_n) / interval)) * ((int)(Math.Abs(sw_utm_e - ne_utm_e) / interval))); if (numberOfCells > 210) { return; // Safety check; takes to long to render } int count = 0; for (double currentNorth = sw_utm_n; currentNorth <= ne_utm_n; currentNorth += interval) { for (double currentEast = sw_utm_e; currentEast <= ne_utm_e; currentEast += interval) { count++; var lowerLeftLatLon = UTMtoLL(currentNorth, currentEast, utmZone, sw.Latitude >= 0 ? Geocentric.Hemisphere.North : Geocentric.Hemisphere.South); ; var upperRightLatLon = UTMtoLL(currentNorth + interval, currentEast + interval, utmZone, sw.Latitude >= 0 ? Geocentric.Hemisphere.North : Geocentric.Hemisphere.South); ; var lowerRightLatLon = UTMtoLL(currentNorth, currentEast + interval, utmZone, sw.Latitude >= 0 ? Geocentric.Hemisphere.North : Geocentric.Hemisphere.South); ; var upperLeftLatLon = UTMtoLL(currentNorth + interval, currentEast, utmZone, sw.Latitude >= 0 ? Geocentric.Hemisphere.North : Geocentric.Hemisphere.South); ; Point[] utm = new Point[] { new Point(upperLeftLatLon.Longitude, upperLeftLatLon.Latitude), new Point(upperRightLatLon.Longitude, upperRightLatLon.Latitude), new Point(lowerRightLatLon.Longitude, lowerRightLatLon.Latitude), new Point(lowerLeftLatLon.Longitude, lowerLeftLatLon.Latitude), }; var intersect = SutherlandHodgman.GetIntersectedPolygon(utm, clipPolygon); if ((intersect != null) && (intersect.Length >= 4)) { for (int i = 0; i < intersect.Length - 1; i++) { var p1 = Viewport.EsriMap.MapToScreen(WGS84LatLongPoint.Create(intersect[i].Y, intersect[i].X).ToEsriGeometry(102100)); var p2 = Viewport.EsriMap.MapToScreen(WGS84LatLongPoint.Create(intersect[i + 1].Y, intersect[i + 1].X).ToEsriGeometry(102100)); pDC.DrawLine(mMgrsLinePen, new Point(p1.X, p1.Y), new Point(p2.X, p2.Y)); } var bb = new MgrsBoundingBox(intersect); if (currentNorth + interval > ne_utm_n) RenderMgrsCellLabels(pDC, bb, currentNorth, currentEast, NorthEast.North); if (currentEast + interval > ne_utm_e) RenderMgrsCellLabels(pDC, bb, currentNorth, currentEast, NorthEast.East); RenderMgrsCenterLabel(pDC, bb, currentNorth, currentEast); } } } }