public Limits CreateExpandedLimit(double rangeOutKm) { var result = new Limits(); var geoList = new List<Geo>(); if (Geos == null || Geos.Count == 0) { result.Name = Name + "-Undefined"; } else { var newName = Name; if (newName != null) { var suffix = ""; if (newName.EndsWith(".ovr")) { newName = newName.Substring(0, newName.IndexOf(".ovr")); suffix = ".ovr"; } result.Name = String.Format("{0}_{1}K{2}", newName, rangeOutKm, suffix); } Geo lastEndPt = null; GeoSegment segment = null; foreach (var curSegment in _region.Segments) { var lineCourse = curSegment[0].Azimuth(curSegment[1]); segment = curSegment; // gives specular reflection with angle from center of region // double ang = Geo.angle(centerOfRegion, segPts[1], segPts[0]); // double azimuth = Math.toDegrees((lineCourse + (isClockWise ? 1 : // -1) * ang)) % (360.0); var azimuth = (lineCourse + (_isClockWise ? -1 : 1) * (Math.PI / 2)) % ((Math.PI * 2.0)); var newPt0 = curSegment[0].Offset(Geo.KilometersToRadians(rangeOutKm), azimuth); var newPt1 = curSegment[1].Offset(Geo.KilometersToRadians(rangeOutKm), azimuth); if (lastEndPt != null) { var left = (_isClockWise ? lastEndPt : newPt0); var right = (_isClockWise ? newPt0 : lastEndPt); var arc = curSegment[0].ApproximateArc(left, right, Geo.DegreesToRadians(5.0)); var arcList = new List<Geo>(arc.Length); for (var i = 1; i < arc.Length - 1; i++) { var a = arc[i]; if (_isClockWise) arcList.Add(a); else arcList.Insert(0, a); } geoList.AddRange(arcList); } geoList.Add(newPt0); geoList.Add(newPt1); for (var i = 0; i < geoList.Count - 1; i++) if ((Math.Abs(geoList[i].Latitude - geoList[i + 1].Latitude) < .000001) && (Math.Abs(geoList[i].Longitude - geoList[i + 1].Longitude) < .000001)) Debugger.Break(); lastEndPt = newPt1; } if (lastEndPt != null) { var left = (_isClockWise ? lastEndPt : geoList[0]); var right = (_isClockWise ? geoList[0] : lastEndPt); var arc = segment[1].ApproximateArc(left, right, Geo.DegreesToRadians(5.0)); var arcList = new List<Geo>(arc.Length); for (var i = 1; i < arc.Length; i++) { var a = arc[i]; if (_isClockWise) arcList.Add(a); else arcList.Insert(0, a); } geoList.AddRange(arcList); } for (var i = 0; i < geoList.Count - 1; i++) if ((Math.Abs(geoList[i].Latitude - geoList[i + 1].Latitude) < .000001) && (Math.Abs(geoList[i].Longitude - geoList[i + 1].Longitude) < .000001)) Debugger.Break(); result.Geos = geoList; result.Initialize(); } return result; }
public static Limits CreateBoundingBoxLimit(List<Limits> areas, double rangeOutKm) { var result = new Limits { Name = "bounds-cw.ovr" }; foreach (var l in areas) { foreach (var p in l.Geos) result.Geos.Add(p); } foreach (var geo in result.Geos) { if (geo.Latitude < result._minLat) { result._minLat = geo.Latitude; } if (geo.Latitude > result._maxLat) { result._maxLat = geo.Latitude; } if (geo.Longitude < result._minLon) { result._minLon = geo.Longitude; } if (geo.Longitude > result._maxLon) { result._maxLon = geo.Longitude; } } result.Geos.Clear(); result.Geos.Add(new Geo(result._minLat, result._minLon).Offset(Geo.KilometersToRadians(Math.Sqrt(2) * rangeOutKm), Geo.DegreesToRadians(225))); result.Geos.Add(new Geo(result._maxLat, result._minLon).Offset(Geo.KilometersToRadians(Math.Sqrt(2) * rangeOutKm), Geo.DegreesToRadians(315))); result.Geos.Add(new Geo(result._maxLat, result._maxLon).Offset(Geo.KilometersToRadians(Math.Sqrt(2) * rangeOutKm), Geo.DegreesToRadians(45))); result.Geos.Add(new Geo(result._minLat, result._maxLon).Offset(Geo.KilometersToRadians(Math.Sqrt(2) * rangeOutKm), Geo.DegreesToRadians(135))); result.Geos.Add(new Geo(result._minLat, result._minLon).Offset(Geo.KilometersToRadians(Math.Sqrt(2) * rangeOutKm), Geo.DegreesToRadians(225))); result.Initialize(); return result; }
public Limits CreateBoundingBoxLimit(double rangeOutKm) { var result = new Limits(); if (Geos == null || Geos.Count == 0) { result.Name = Name + "-Undefined"; } else { result.Name = Name + "-Bounding"; foreach (var geo in Geos) { var dot = _centerOfRegion.Azimuth(geo); var point = geo.Offset(Geo.KilometersToRadians(rangeOutKm), dot); result.Geos.Add(point); } result.Initialize(); } return result; }