示例#1
0
        private void btnAddFence_Click(object sender, EventArgs e)
        {
            if (bingLine.Count > 2)
            {
                CBoundaryList New = new CBoundaryList();
                double        east, nort;
                for (int i = 0; i < bingLine.Count; i++)
                {
                    mf.pn.ConvertWGS84ToLocal(bingLine[i].Latitude, bingLine[i].Longitude, out nort, out east);
                    vec3 v = new vec3(east, nort, 0);
                    New.fenceLine.Add(v);
                }

                New.CalculateFenceArea(mf.bnd.bndList.Count);
                New.FixFenceLine(mf.bnd.bndList.Count);

                mf.bnd.bndList.Add(New);
                mf.fd.UpdateFieldBoundaryGUIAreas();

                //turn lines made from boundaries
                mf.CalculateMinMax();
                mf.FileSaveBoundary();
                mf.bnd.BuildTurnLines();
                mf.btnABDraw.Visible = true;
            }

            //clean up line
            bingLine.Clear();
            mapControl.Markers.Clear();
            mapControl.Invalidate();
            lblPoints.Text = bingLine.Count.ToString();
        }
示例#2
0
        private void btnStop_Click(object sender, EventArgs e)
        {
            if (mf.bnd.bndBeingMadePts.Count > 2)
            {
                CBoundaryList New = new CBoundaryList();

                for (int i = 0; i < mf.bnd.bndBeingMadePts.Count; i++)
                {
                    New.fenceLine.Add(mf.bnd.bndBeingMadePts[i]);
                }

                New.CalculateFenceArea(mf.bnd.bndList.Count);
                New.FixFenceLine(mf.bnd.bndList.Count);

                mf.bnd.bndList.Add(New);
                mf.fd.UpdateFieldBoundaryGUIAreas();

                //turn lines made from boundaries
                mf.CalculateMinMax();
                mf.FileSaveBoundary();
                mf.bnd.BuildTurnLines();
                //mf.hd.BuildSingleSpaceHeadLines();
                mf.btnABDraw.Visible = true;
            }

            //stop it all for adding
            mf.bnd.isOkToAddPoints = false;
            mf.bnd.isBndBeingMade  = false;
            mf.bnd.bndBeingMadePts.Clear();

            //close window
            isClosing = true;
            Close();
        }
示例#3
0
        private void btnLoadBoundaryFromGE_Click(object sender, EventArgs e)
        {
            if (sender is Button button)
            {
                string fileAndDirectory;
                {
                    //create the dialog instance
                    OpenFileDialog ofd = new OpenFileDialog
                    {
                        //set the filter to text KML only
                        Filter = "KML files (*.KML)|*.KML",

                        //the initial directory, fields, for the open dialog
                        InitialDirectory = mf.fieldsDirectory + mf.currentFieldDirectory
                    };

                    //was a file selected
                    if (ofd.ShowDialog(this) == DialogResult.Cancel)
                    {
                        return;
                    }
                    else
                    {
                        fileAndDirectory = ofd.FileName;
                    }
                }

                string coordinates = null;
                int    startIndex;

                using (StreamReader reader = new StreamReader(fileAndDirectory))
                {
                    if (button.Name == "btnLoadMultiBoundaryFromGE")
                    {
                        ResetAllBoundary();
                    }

                    try
                    {
                        while (!reader.EndOfStream)
                        {
                            //start to read the file
                            string line = reader.ReadLine();

                            startIndex = line.IndexOf("<coordinates>");

                            if (startIndex != -1)
                            {
                                while (true)
                                {
                                    int endIndex = line.IndexOf("</coordinates>");

                                    if (endIndex == -1)
                                    {
                                        //just add the line
                                        if (startIndex == -1)
                                        {
                                            coordinates += line.Substring(0);
                                        }
                                        else
                                        {
                                            coordinates += line.Substring(startIndex + 13);
                                        }
                                    }
                                    else
                                    {
                                        if (startIndex == -1)
                                        {
                                            coordinates += line.Substring(0, endIndex);
                                        }
                                        else
                                        {
                                            coordinates += line.Substring(startIndex + 13, endIndex - (startIndex + 13));
                                        }
                                        break;
                                    }
                                    line       = reader.ReadLine();
                                    line       = line.Trim();
                                    startIndex = -1;
                                }

                                line = coordinates;
                                char[]   delimiterChars = { ' ', '\t', '\r', '\n' };
                                string[] numberSets     = line.Split(delimiterChars);

                                //at least 3 points
                                if (numberSets.Length > 2)
                                {
                                    CBoundaryList New = new CBoundaryList();

                                    foreach (string item in numberSets)
                                    {
                                        string[] fix = item.Split(',');
                                        double.TryParse(fix[0], NumberStyles.Float, CultureInfo.InvariantCulture, out lonK);
                                        double.TryParse(fix[1], NumberStyles.Float, CultureInfo.InvariantCulture, out latK);

                                        mf.pn.ConvertWGS84ToLocal(latK, lonK, out norting, out easting);

                                        //add the point to boundary
                                        New.fenceLine.Add(new vec3(easting, norting, 0));
                                    }

                                    New.CalculateFenceArea(mf.bnd.bndList.Count);
                                    New.FixFenceLine(mf.bnd.bndList.Count);

                                    mf.bnd.bndList.Add(New);

                                    mf.btnMakeLinesFromBoundary.Visible = true;

                                    coordinates = "";
                                }
                                else
                                {
                                    mf.TimedMessageBox(2000, gStr.gsErrorreadingKML, gStr.gsChooseBuildDifferentone);
                                }
                                if (button.Name == "btnLoadBoundaryFromGE")
                                {
                                    break;
                                }
                            }
                        }
                        mf.FileSaveBoundary();
                        mf.bnd.BuildTurnLines();
                        mf.btnMakeLinesFromBoundary.Visible = true;
                        UpdateChart();
                    }
                    catch (Exception)
                    {
                        return;
                    }
                }
            }
            mf.bnd.isOkToAddPoints = false;

            panelMain.Visible   = true;
            panelChoose.Visible = false;
            panelKML.Visible    = false;

            this.Size = new Size(566, 377);

            UpdateChart();
        }
示例#4
0
        private void LoadKMLBoundary(string filename)
        {
            string coordinates = null;
            int    startIndex;

            using (System.IO.StreamReader reader = new System.IO.StreamReader(filename))
            {
                try
                {
                    while (!reader.EndOfStream)
                    {
                        //start to read the file
                        string line = reader.ReadLine();

                        startIndex = line.IndexOf("<coordinates>");

                        if (startIndex != -1)
                        {
                            while (true)
                            {
                                int endIndex = line.IndexOf("</coordinates>");

                                if (endIndex == -1)
                                {
                                    //just add the line
                                    if (startIndex == -1)
                                    {
                                        coordinates += line.Substring(0);
                                    }
                                    else
                                    {
                                        coordinates += line.Substring(startIndex + 13);
                                    }
                                }
                                else
                                {
                                    if (startIndex == -1)
                                    {
                                        coordinates += line.Substring(0, endIndex);
                                    }
                                    else
                                    {
                                        coordinates += line.Substring(startIndex + 13, endIndex - (startIndex + 13));
                                    }
                                    break;
                                }
                                line       = reader.ReadLine();
                                line       = line.Trim();
                                startIndex = -1;
                            }

                            line = coordinates;
                            char[]   delimiterChars = { ' ', '\t', '\r', '\n' };
                            string[] numberSets     = line.Split();

                            //at least 3 points
                            if (numberSets.Length > 2)
                            {
                                CBoundaryList New = new CBoundaryList();

                                foreach (string item in numberSets)
                                {
                                    if (item.Length < 3)
                                    {
                                        continue;
                                    }
                                    string[] fix = item.Split(',');
                                    double.TryParse(fix[0], NumberStyles.Float, CultureInfo.InvariantCulture, out lonK);
                                    double.TryParse(fix[1], NumberStyles.Float, CultureInfo.InvariantCulture, out latK);

                                    mf.pn.ConvertWGS84ToLocal(latK, lonK, out northing, out easting);

                                    //add the point to boundary
                                    New.fenceLine.Add(new vec3(easting, northing, 0));
                                }

                                //build the boundary, make sure is clockwise for outer counter clockwise for inner
                                New.CalculateFenceArea(mf.bnd.bndList.Count);
                                New.FixFenceLine(mf.bnd.bndList.Count);

                                mf.bnd.bndList.Add(New);

                                mf.btnABDraw.Visible = true;

                                coordinates = "";
                            }
                            else
                            {
                                mf.TimedMessageBox(2000, gStr.gsErrorreadingKML, gStr.gsChooseBuildDifferentone);
                            }
                            break;
                        }
                    }
                    mf.FileSaveBoundary();
                    mf.bnd.BuildTurnLines();
                    mf.fd.UpdateFieldBoundaryGUIAreas();
                    mf.CalculateMinMax();

                    btnSave.Enabled    = true;
                    btnLoadKML.Enabled = false;
                }
                catch (Exception)
                {
                    btnSave.Enabled    = false;
                    btnLoadKML.Enabled = false;
                    return;
                }
            }

            mf.bnd.isOkToAddPoints = false;
        }