示例#1
0
        void doAllFields()
        {
            if (selectedField == null)
            {
                if (Fields.Count > 0)
                {
                    selectedField = Fields.First();
                }
            }

            GuidanceLines.Clear();
            Swathes.Clear();
            AnalysisResult.Clear();
            foreach (var poly in Fields)
            {
                PointExtension.LocalLatitude = poly.Locations.Min(p => p.Latitude);

                var geoPolygon = new List <GeoPoint>();
                foreach (var p in poly.Locations)
                {
                    geoPolygon.Add(p.ToGeoPoint());
                }

                List <MyPoint3D> cartPolygon = new List <MyPoint3D>();
                foreach (var p in poly.Locations)
                {
                    cartPolygon.Add(p.ToGeoPoint().ToCart());
                }

                var lineDef = LineDefinition.GetBestLine(cartPolygon);
                var res     = AnalyzeFieldAndShowSwaths(poly, lineDef);
                if (double.IsNaN(res.AppliedArea))
                {
                    continue;
                }
                res.AppliedArea = res.AppliedArea / 10000;
                res.FieldArea   = res.FieldArea / 10000;
                //res.Savings = (res.AppliedArea - res.FieldArea) * CostHa;
                res.SectionSaving = (res.AppliedArea - res.FieldArea) * CostHa * (1 - 1.0 / NumberOfSections);
                res.SectionLoss   = (res.AppliedArea - res.FieldArea) * CostHa - res.SectionSaving;
                res.FieldName     = (AnalysisResult.Count + 1).ToString();
                AnalysisResult.Add(res);
            }
            AppliedArea   = AnalysisResult.Sum(r => r.AppliedArea);
            FieldArea     = AnalysisResult.Sum(r => r.FieldArea);
            SectionSaving = AnalysisResult.Sum(r => r.SectionSaving);
            SectionLoss   = AnalysisResult.Sum(r => r.SectionLoss);

            double totalNozzleSaving = (AppliedArea - FieldArea) * CostHa * (1 - 1.0 / NumberOfNozzles);

            NozzleSaving = totalNozzleSaving - SectionSaving;
            NozzleLoss   = (AppliedArea - FieldArea) * CostHa - totalNozzleSaving;

            SectionPaybackHa = SectionControlPrice / (SectionSaving / AppliedArea);
            NozzlePaybackHa  = (NozzleControlPrice - SectionControlPrice) / (NozzleSaving / AppliedArea);
        }
示例#2
0
 private void DrawField(object sender, RoutedEventArgs e)
 {
     menuDrawField.IsEnabled     = false;
     menuStopDrawField.IsEnabled = true;
     mainMap.Cursor = Cursors.Cross;
     mainMap.PreviewMouseLeftButtonUp += mainMap_MouseLeftUp_AddPointToField;
     fieldDrawn           = new VM.FieldVM();
     fieldDrawn.Locations = new MapControl.LocationCollection();
     fieldDrawn.Fill      = greenBrush;
     vm.Fields.Add(fieldDrawn);
 }
示例#3
0
        void Select(object polygon)
        {
            if (selectedField != null)
            {
                selectedField.Fill = greenBrush;
            }
            FieldVM f = (FieldVM)polygon;

            f.Fill        = darkBrush;
            selectedField = f;
            setCanProcessField();
        }
示例#4
0
        private void OpenKml(object sender, RoutedEventArgs e)
        {
            OpenFileDialog opfd = new OpenFileDialog();

            opfd.Filter = "Google Earth files *.kml|*.kml";
            var res = opfd.ShowDialog();

            if (res == true)
            {
                vm.Fields = new System.Collections.ObjectModel.ObservableCollection <VM.FieldVM>();

                XmlDocument document = new XmlDocument();
                document.Load(opfd.FileName);
                var places = document.GetElementsByTagName("Placemark");
                foreach (XmlElement place in places)
                {
                    var el = place.GetElementsByTagName("coordinates")[0];
                    try
                    {
                        VM.FieldVM polygon = new VM.FieldVM();
                        vm.Fields.Add(polygon);
                        polygon.Fill      = greenBrush;
                        polygon.Locations = new MapControl.LocationCollection();
                        string[]    coordStrs = ((System.Xml.XmlElement)el).InnerText.Split(' ');
                        CultureInfo ci        = new CultureInfo("en-US");
                        foreach (var pointStr in coordStrs)
                        {
                            try
                            {
                                if (string.IsNullOrEmpty(pointStr))
                                {
                                    continue;
                                }
                                double   longitude;
                                string[] pCoords = pointStr.Split(',');
                                longitude = double.Parse(pCoords[0].Trim(), ci);
                                double latitude = double.Parse(pCoords[1], ci);
                                polygon.Locations.Add(new MapControl.Location(latitude, longitude));
                            }
                            catch { }
                        }

                        var southWest = new MapControl.Location(polygon.Locations.Min(p => p.Latitude), polygon.Locations.Min(p => p.Longitude));
                        var northEast = new MapControl.Location(polygon.Locations.Max(p => p.Latitude), polygon.Locations.Max(p => p.Longitude));
                        mainMap.ZoomToBounds(southWest, northEast);
                    }
                    catch
                    { }
                }
            }
        }
示例#5
0
        private AnalysisResult AnalyzeFieldAndShowSwaths(FieldVM polygon, LineDefinition lineDef)
        {
            double processedArea = 0;
            double width         = ImplementWidth;
            var    geoPolygon    = new List <GeoPoint>();

            foreach (var p in polygon.Locations)
            {
                geoPolygon.Add(p.ToGeoPoint());
            }

            List <MyPoint3D> cartPolygon = new List <MyPoint3D>();

            foreach (var p in polygon.Locations)
            {
                cartPolygon.Add(p.ToGeoPoint().ToCart());
            }

            double length = width / 2.0;

            if (Utility.CalculateArea(geoPolygon, false) < 0)
            {
                length = -length;
            }


            List <MyPoint3D> boundary = new List <MyPoint3D>();
            MyPoint3D        prevP    = cartPolygon[0];

            boundary.Add(cartPolygon[0]);
            for (int i = 1; i < cartPolygon.Count; i++)
            {
                if ((prevP - cartPolygon[i]).Norm < 3)
                {
                    continue;
                }
                prevP = cartPolygon[i];
                boundary.Add(cartPolygon[i]);
            }
            if ((boundary.First() - boundary.Last()).Norm < 3)
            {
                boundary.Remove(boundary.Last());
            }

            length = -length;
            List <MyPoint3D> headLand = Utility.ShiftBoundary(length, boundary);

            headLand.Add(headLand.First());
            List <MyPoint3D> innerBoundary = Utility.ShiftBoundary(2 * length, boundary);

            AddHeadLandToMap(headLand);
            AddOuterSwathToMap(boundary, innerBoundary);

            var intersections = Utility.GetHeadlandIntersections(headLand, lineDef, width);

            processedArea += width * ComputeParallelLines(width, headLand, lineDef, intersections, true).LinesLength;

            lineDef        = LineDefinition.GetParallelLine(lineDef, -width);
            intersections  = Utility.GetHeadlandIntersections(headLand, lineDef, width);
            processedArea += width * ComputeParallelLines(-width, headLand, lineDef, intersections, true).LinesLength;
            for (int i = 1; i < headLand.Count; i++)
            {
                processedArea += width * (headLand[i - 1] - headLand[i]).Norm;
            }

            AnalysisResult res = new AnalysisResult();

            res.AppliedArea = processedArea;
            res.FieldArea   = Utility.CalculateArea(geoPolygon);
            return(res);
        }