Пример #1
0
        private void CB_ClippingLayer_SelectedIndexChanged(object sender, EventArgs e)
        {
            VectorLayer aLayer     = _polygonLayers[CB_ClippingLayer.SelectedIndex];
            List <int>  selIndexes = aLayer.GetSelectedShapeIndexes();

            if (selIndexes.Count > 0)
            {
                ChB_SelFeaturesOnly.Enabled = true;
                ChB_SelFeaturesOnly.Text    = "Selected features only (" + selIndexes.Count.ToString() + " features selected)";
            }
            else
            {
                ChB_SelFeaturesOnly.Enabled = false;
                ChB_SelFeaturesOnly.Checked = false;
                ChB_SelFeaturesOnly.Text    = "Selected features only";
            }
        }
        private void CB_MapLayers_SelectedIndexChanged(object sender, EventArgs e)
        {
            _currentLayer = m_MapLayers[CB_MapLayers.SelectedIndex];

            int    i;
            string str = CB_OutputFormat.Text;

            CB_OutputFormat.Items.Clear();
            CB_OutputFormat.Items.Add("ASCII wmp File");
            CB_OutputFormat.Items.Add("Shape File");
            CB_OutputFormat.Items.Add("KML File");
            List <int> selIndexes = _currentLayer.GetSelectedShapeIndexes();

            switch (_currentLayer.ShapeType)
            {
            case ShapeTypes.Polygon:
                CB_OutputFormat.Items.Add("GrADS Map File");
                CB_OutputFormat.Items.Add("GrADS Maskout File");
                CB_OutputFormat.Items.Add("Surfer BLN File");
                break;

            case ShapeTypes.Polyline:
                CB_OutputFormat.Items.Add("GrADS Map File");
                CB_OutputFormat.Items.Add("Surfer BLN File");
                break;
            }

            int idx = CB_OutputFormat.Items.IndexOf(str);

            if (idx >= 0)
            {
                CB_OutputFormat.SelectedIndex = idx;
            }
            else
            {
                CB_OutputFormat.SelectedIndex = 0;
            }
        }
        private void SaveWMPFile()
        {
            SaveFileDialog SFDlg = new SaveFileDialog();

            SFDlg.Filter = "wmp File (*.wmp)|*.wmp";
            if (SFDlg.ShowDialog() == DialogResult.OK)
            {
                //ProgressBar
                toolStripProgressBar1.Visible = true;
                this.Cursor = Cursors.WaitCursor;

                string       aFile       = SFDlg.FileName;
                StreamWriter sw          = new StreamWriter(aFile);
                List <int>   selIndexes  = _currentLayer.GetSelectedShapeIndexes();
                bool         hasSelShape = _currentLayer.HasSelectedShapes();
                int          shpNum      = _currentLayer.ShapeNum;
                if (hasSelShape)
                {
                    shpNum = selIndexes.Count;
                }
                int i;
                switch (_currentLayer.ShapeType)
                {
                case ShapeTypes.Point:
                    sw.WriteLine("Point");
                    sw.WriteLine(shpNum.ToString());
                    PointShape aPS = new PointShape();
                    if (hasSelShape)
                    {
                        for (i = 0; i < _currentLayer.ShapeNum; i++)
                        {
                            aPS = (PointShape)_currentLayer.ShapeList[i];
                            if (aPS.Selected)
                            {
                                sw.WriteLine(aPS.Point.X.ToString() + "," + aPS.Point.Y.ToString());
                            }
                            this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                        }
                    }
                    else
                    {
                        for (i = 0; i < _currentLayer.ShapeNum; i++)
                        {
                            aPS = (PointShape)_currentLayer.ShapeList[i];
                            sw.WriteLine(aPS.Point.X.ToString() + "," + aPS.Point.Y.ToString());
                            this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                        }
                    }
                    break;

                case ShapeTypes.Polyline:
                    sw.WriteLine("Polyline");
                    int           shapeNum = 0;
                    PolylineShape aPLS     = new PolylineShape();
                    if (hasSelShape)
                    {
                        for (i = 0; i < _currentLayer.ShapeNum; i++)
                        {
                            aPLS = (PolylineShape)_currentLayer.ShapeList[i];
                            if (aPLS.Selected)
                            {
                                shapeNum += aPLS.PartNum;
                            }
                        }
                    }
                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPLS      = (PolylineShape)_currentLayer.ShapeList[i];
                        shapeNum += aPLS.PartNum;
                    }
                    sw.WriteLine(shpNum.ToString());

                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPLS = (PolylineShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPLS.Selected)
                            {
                                continue;
                            }
                        }
                        MeteoInfoC.PointD[] Pointps;
                        for (int p = 0; p < aPLS.PartNum; p++)
                        {
                            if (p == aPLS.PartNum - 1)
                            {
                                Pointps = new MeteoInfoC.PointD[aPLS.PointNum - aPLS.parts[p]];
                                for (int pp = aPLS.parts[p]; pp < aPLS.PointNum; pp++)
                                {
                                    Pointps[pp - aPLS.parts[p]] = (MeteoInfoC.PointD)aPLS.Points[pp];
                                }
                            }
                            else
                            {
                                Pointps = new MeteoInfoC.PointD[aPLS.parts[p + 1] - aPLS.parts[p]];
                                for (int pp = aPLS.parts[p]; pp < aPLS.parts[p + 1]; pp++)
                                {
                                    Pointps[pp - aPLS.parts[p]] = (MeteoInfoC.PointD)aPLS.Points[pp];
                                }
                            }
                            sw.WriteLine(Pointps.Length.ToString());
                            foreach (MeteoInfoC.PointD aPoint in Pointps)
                            {
                                sw.WriteLine(aPoint.X.ToString() + "," + aPoint.Y.ToString());
                            }
                            shapeNum += 1;
                        }
                        Application.DoEvents();
                        this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                    }
                    break;

                case ShapeTypes.Polygon:
                    sw.WriteLine("Polygon");
                    shapeNum = 0;
                    PolygonShape aPGS = new PolygonShape();
                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPGS = (PolygonShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPGS.Selected)
                            {
                                continue;
                            }
                        }
                        shapeNum += aPGS.PartNum;
                    }
                    sw.WriteLine(shapeNum.ToString());

                    for (i = 0; i < _currentLayer.ShapeNum; i++)
                    {
                        aPGS = (PolygonShape)_currentLayer.ShapeList[i];
                        if (hasSelShape)
                        {
                            if (!aPGS.Selected)
                            {
                                continue;
                            }
                        }

                        MeteoInfoC.PointD[] Pointps;
                        for (int p = 0; p < aPGS.PartNum; p++)
                        {
                            if (p == aPGS.PartNum - 1)
                            {
                                Pointps = new MeteoInfoC.PointD[aPGS.PointNum - aPGS.parts[p]];
                                for (int pp = aPGS.parts[p]; pp < aPGS.PointNum; pp++)
                                {
                                    Pointps[pp - aPGS.parts[p]] = (MeteoInfoC.PointD)aPGS.Points[pp];
                                }
                            }
                            else
                            {
                                Pointps = new MeteoInfoC.PointD[aPGS.parts[p + 1] - aPGS.parts[p]];
                                for (int pp = aPGS.parts[p]; pp < aPGS.parts[p + 1]; pp++)
                                {
                                    Pointps[pp - aPGS.parts[p]] = (MeteoInfoC.PointD)aPGS.Points[pp];
                                }
                            }
                            sw.WriteLine(Pointps.Length.ToString());
                            foreach (MeteoInfoC.PointD aPoint in Pointps)
                            {
                                sw.WriteLine(aPoint.X.ToString() + "," + aPoint.Y.ToString());
                            }
                            shapeNum += 1;
                        }
                        Application.DoEvents();
                        this.toolStripProgressBar1.Value = (i + 1) * 100 / _currentLayer.ShapeNum;
                    }
                    break;
                }

                sw.Close();

                //Progressbar
                this.toolStripProgressBar1.Value   = 0;
                this.toolStripProgressBar1.Visible = false;
                this.Cursor = Cursors.Default;
            }
        }