Esempio n. 1
0
        private void 矢量数据重投影ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //选择投影变换图层
            SelectLayer selFrm = new SelectLayer(mapControl);

            selFrm.Text              = "选择变换图层";
            selFrm.label1.Text       = "选择矢量图层";
            selFrm.label2.Visible    = false;
            selFrm.comboBox2.Visible = false;
            if (selFrm.ShowDialog(this) == DialogResult.OK)
            {
                int index = 0;
                for (int i = 0; i < mapControl._MapLayers.Count(); i++)
                {
                    if (mapControl._MapLayers[i].Name == selFrm.cb1)
                    {
                        index = i;
                        break;
                    }
                }
                //选择输出文件路径
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title  = "选择重投影文件存储路径";
                sfd.Filter = @"shp(*.shp)|*.shp";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    string   path  = sfd.FileName; //文件路径
                    string[] path2 = path.Split(new char[1] {
                        '\\'
                    });                                               //文件名
                    string name = path2[path2.Count() - 1];
                    //打开需转换矢量文件
                    DataSource ds = Ogr.Open(mapControl._MapLayers[index].FilePath, 0);
                    //投影转换
                    TransformProject transform = new TransformProject();
                    transform.TransformShp(ds, path);
                    //转换结果添加至地图
                    mapControl.AddShpLayer(path, name);
                    if (tVLayers.Nodes.Count == 0)
                    {
                        tVLayers.Nodes.Add("图层");
                    }
                    tVLayers.Nodes[0].Nodes.Insert(0, name);
                    tVLayers.ExpandAll();
                    tVLayers.SelectedNode = tVLayers.Nodes[0].Nodes[0];
                    MessageBox.Show("成功转换至Web墨卡托投影!", "投影转换结果");
                }
            }
        }
Esempio n. 2
0
        private void 统计分析ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            SelectLayer selFrm = new SelectLayer(mapControl);

            if (selFrm.ShowDialog(this) == DialogResult.OK)
            {
                int shpIndex = 0, tifIndex = 0;
                for (int i = 0; i < mapControl._MapLayers.Count(); i++)
                {
                    if (mapControl._MapLayers[i].Name == selFrm.cb1)
                    {
                        shpIndex = i;
                    }
                    else if (mapControl._MapLayers[i].Name == selFrm.cb2)
                    {
                        tifIndex = i;
                    }
                }
                Dataset    ds    = Gdal.Open(mapControl._MapLayers[tifIndex].FilePath, Access.GA_ReadOnly);
                DataSource ds2   = Ogr.Open(mapControl._MapLayers[shpIndex].FilePath, 0);
                Layer      layer = ds2.GetLayerByIndex(0);
                //判断二者坐标系是否一致
                SpatialReference SrsLayer = layer.GetSpatialRef();
                SpatialReference SrsRas   = new SpatialReference(ds.GetProjection());
                if (SrsLayer.IsSame(SrsRas) == 1)
                {
                    Statistic statistic = new Statistic();
                    //code-ave-max-min-count(最后一列count是像元数需要删去)
                    List <float[]> result = statistic.ComputeStatistic(layer, ds);
                    //存入数据库
                    DBConnector dbConnector = new DBConnector();
                    string      name        = selFrm.cb2;
                    name = name.Substring(0, name.Length - 4);//去掉名称中的.tif
                    //添加新表
                    dbConnector.AddTable(name);
                    //向新表中插入数据
                    dbConnector.InsertInfo(result, name);
                    MessageBox.Show("统计结果已经成功导入数据库!");
                }
                else
                {
                    MessageBox.Show("数据坐标系不一致!");
                }
            }
        }
Esempio n. 3
0
        private void 栅格数据重投影ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //选择投影变换图层
            SelectLayer selFrm = new SelectLayer(mapControl);

            selFrm.Text              = "选择变换图层";
            selFrm.label2.Text       = "选择栅格图层";
            selFrm.label1.Visible    = false;
            selFrm.comboBox1.Visible = false;
            selFrm.label3.Visible    = true;
            selFrm.comboBox3.Visible = true;
            selFrm.comboBox3.Items.Add("NearestNeighbour");
            selFrm.comboBox3.Items.Add("Bilinear");
            selFrm.comboBox3.Items.Add("Cubic");
            selFrm.comboBox3.Items.Add("CubicSpline");
            if (selFrm.ShowDialog(this) == DialogResult.OK)
            {
                int index = 0;
                for (int i = 0; i < mapControl._MapLayers.Count(); i++)
                {
                    if (mapControl._MapLayers[i].Name == selFrm.cb2)
                    {
                        index = i;
                        break;
                    }
                }
                //选择输出文件路径
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title  = "选择重投影文件存储路径";
                sfd.Filter = @"Tiff(*.tif)|*.tif";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    string   path  = sfd.FileName; //文件路径
                    string[] path2 = path.Split(new char[1] {
                        '\\'
                    });                                               //文件名
                    string name = path2[path2.Count() - 1];
                    //投影转换
                    TransformProject transform = new TransformProject();
                    float[]          MBR       = new float[4];
                    mapControl._MapLayers[index].GetExtent(MBR);
                    double[] dbx = { (double)MBR[0], (double)MBR[0], (double)MBR[2], (double)MBR[2] };
                    double[] dby = { (double)MBR[1], (double)MBR[3], (double)MBR[1], (double)MBR[3] };
                    Dataset  ds  = Gdal.Open(mapControl._MapLayers[index].FilePath, Access.GA_ReadOnly);
                    //重采样方式
                    ResampleAlg re = ResampleAlg.GRA_NearestNeighbour;
                    if (selFrm.cb3 == "Bilinear")
                    {
                        re = ResampleAlg.GRA_Bilinear;
                    }
                    else if (selFrm.cb3 == "Cubic")
                    {
                        re = ResampleAlg.GRA_Cubic;
                    }
                    else if (selFrm.cb3 == "CubicSpline")
                    {
                        re = ResampleAlg.GRA_CubicSpline;
                    }
                    transform.TransformTiff(ds, dbx, dby, path, re);
                    //转换结果添加至地图
                    mapControl.AddTiffLayer(path, name);
                    if (tVLayers.Nodes.Count == 0)
                    {
                        tVLayers.Nodes.Add("图层");
                    }
                    tVLayers.Nodes[0].Nodes.Insert(0, name);
                    tVLayers.ExpandAll();
                    tVLayers.SelectedNode = tVLayers.Nodes[0].Nodes[0];
                    MessageBox.Show("成功转换至Web墨卡托投影!", "投影转换结果");
                }
            }
        }