public void ProcessPrescription(Prescription prescription) { if (prescription is VectorPrescription) //Only Vector currently supported for the Visualizer map { VectorPrescription vectorPrescription = prescription as VectorPrescription; using (var graphics = _spatialViewer.CreateGraphics()) { _drawingUtil = new DrawingUtil(_spatialViewer.Width, _spatialViewer.Height, graphics); List <Point> allPoints = new List <Point>(); List <List <Point> > projectedPointsPerPolygon = new List <List <Point> >(); foreach (Polygon polygon in vectorPrescription.RxShapeLookups.SelectMany(x => x.Shape.Polygons)) { List <Point> polygonPoints = new List <Point>(); foreach (Point point in polygon.ExteriorRing.Points) { Point projectedPoint = point.ToUtm(); allPoints.Add(projectedPoint); polygonPoints.Add(projectedPoint); } projectedPointsPerPolygon.Add(polygonPoints); } _drawingUtil.SetMinMax(allPoints); foreach (List <Point> polygonPoints in projectedPointsPerPolygon) { var screenPolygon = polygonPoints.Select(point => point.ToXy(_drawingUtil.MinX, _drawingUtil.MinY, _drawingUtil.GetDelta())).ToArray(); graphics.DrawPolygon(DrawingUtil.B_Black, screenPolygon); } } } }
public void GivenMinAndMaxesSetAndHeightAndLonAreGreaterWhenGetDeltaThenDeltaIsReturned() { _drawingUtil = new DrawingUtil(600, 1050, _graphics); var points = new List<Point>(); points.Add(new Point { X = 5600, Y = 9000 }); points.Add(new Point { X = 3600, Y = 7200 }); points.Add(new Point { X = 9000, Y = 2000 }); points.Add(new Point { X = 7600, Y = 2700 }); points.Add(new Point { X = 1000, Y = 8000 }); _drawingUtil.SetMinMax(points); var delta = _drawingUtil.GetDelta(); Assert.AreEqual(7, delta); }
public void ProcessBoundary(FieldBoundary fieldBoundary) { using (var graphics = _spatialViewer.CreateGraphics()) { _drawingUtil = new DrawingUtil(_spatialViewer.Width, _spatialViewer.Height, graphics); foreach (var polygon in fieldBoundary.SpatialData.Polygons) { var projectedPoints = polygon.ExteriorRing.Points.Select(point => point.ToUtm()).ToList(); _drawingUtil.SetMinMax(projectedPoints); var screenPolygon = projectedPoints.Select(point => point.ToXy(_drawingUtil.MinX, _drawingUtil.MinY, _drawingUtil.GetDelta())).ToArray(); graphics.DrawPolygon(DrawingUtil.B_Black, screenPolygon); } } }
public void ProcessBoundary(FieldBoundary fieldBoundary) { using (var graphics = _spatialViewer.CreateGraphics()) { _drawingUtil = new DrawingUtil(_spatialViewer.Width, _spatialViewer.Height, graphics); foreach (var polygon in fieldBoundary.SpatialData.Polygons) { var projectedPoints = polygon.ExteriorRing.Points.Select(point => point.ToUtm()).ToList(); _drawingUtil.SetMinMax(projectedPoints); var screenPolygon = projectedPoints.Select(point => point.ToXy(_drawingUtil.MinX, _drawingUtil.MinY, _drawingUtil.GetDelta())).ToArray(); graphics.DrawPolygon(DrawingUtil.Pen, screenPolygon); } } }
private static void SetMinMax(DrawingUtil drawingUtil, List <Point> points) { drawingUtil.SetMinMax(points); }
private static void SetMinMax(DrawingUtil drawingUtil, List<Point> points) { drawingUtil.SetMinMax(points); }
/// <summary> /// Draws a Red polygon if all values 0, a DarkMagenta polygon if all values the same non-zero value, or else themes Red/DarkOrange/Gold/YellowGreen/LawnGreen/LimeGreen/ForestGreen/DarkGreen. /// </summary> /// <param name="operation"></param> /// <param name="workingDataKey"></param> public void ThemeMap(string workingDataKey) { using (var graphics = _spatialViewer.CreateGraphics()) { graphics.Clear(System.Drawing.Color.White); _drawingUtil = new DrawingUtil(_spatialViewer.Width, _spatialViewer.Height, graphics); List <Point> projectedPoints = new List <Point>(); List <double> doubleValues = null; foreach (SpatialRecord record in _spatialRecords) { Point point = record.Geometry as Point; projectedPoints.Add(point.ToUtm()); if (_workingDataDictionary.ContainsKey(workingDataKey)) { WorkingData workingData = _workingDataDictionary[workingDataKey]; RepresentationValue repValue = record.GetMeterValue(workingData); if (repValue is NumericRepresentationValue) { NumericRepresentationValue numericValue = repValue as NumericRepresentationValue; if (doubleValues == null) { doubleValues = new List <double>(); } doubleValues.Add(numericValue.Value.Value); } else if (repValue is EnumeratedValue) { EnumeratedValue enumValue = repValue as EnumeratedValue; if (enumValue.Representation.Code == "dtRecordingStatus") { if (doubleValues == null) { doubleValues = new List <double>(); } doubleValues.Add(enumValue.Value.Value == "On" ? 1d : -1d); } } } } if (!projectedPoints.Any()) { return; } _drawingUtil.SetMinMax(projectedPoints); var screenPolygon = projectedPoints.Select(point => point.ToXy(_drawingUtil.MinX, _drawingUtil.MinY, _drawingUtil.GetDelta())).ToArray(); if (screenPolygon.All(p => !double.IsNaN(p.X) && !double.IsNaN(p.Y))) { if (doubleValues == null) { //WorkingData is not numeric graphics.DrawPolygon(DrawingUtil.B_Black, screenPolygon); } else { if (doubleValues.Max() == doubleValues.Min()) { //All values are the same if (doubleValues.Max() <= 0d) { //Zero values graphics.DrawPolygon(DrawingUtil.E_Red, screenPolygon); } else { //Non-zero values graphics.DrawPolygon(DrawingUtil.L_DarkGreen, screenPolygon); } } else { double max = doubleValues.Max(); double min = doubleValues.Min(); double average = doubleValues.Average(); List <double> removedZeroValues = doubleValues.Where(dv => dv != 0).ToList(); double avarageWithoutZeroes = removedZeroValues.Average(); if (average != avarageWithoutZeroes) { min = removedZeroValues.Min(); } int i = 0; double range = (max - min) / 7.0; double e7th = min; double f7th = e7th + range; double g7th = f7th + range; double h7th = g7th + range; double i7th = h7th + range; double j7th = i7th + range; double k7th = j7th + range; double l7th = max; foreach (System.Drawing.PointF f in screenPolygon) { double dbl = i < doubleValues.Count ? doubleValues[i] : 0d; //Values will be in same order as points System.Drawing.Pen pen = DrawingUtil.B_Black; if (dbl <= e7th) { pen = DrawingUtil.E_Red; } else if (dbl <= f7th) { pen = DrawingUtil.F_DarkOrange; } else if (dbl <= g7th) { pen = DrawingUtil.G_Gold; } else if (dbl <= h7th) { pen = DrawingUtil.H_YellowGreen; } else if (dbl <= i7th) { pen = DrawingUtil.I_LawnGreen; } else if (dbl <= j7th) { pen = DrawingUtil.J_LimeGreen; } else if (dbl <= k7th) { pen = DrawingUtil.K_ForestGreen; } else if (dbl <= l7th) { pen = DrawingUtil.L_DarkGreen; } graphics.DrawEllipse(pen, new System.Drawing.RectangleF(f.X, f.Y, 2, 2)); i++; } } } } } }