コード例 #1
0
ファイル: Form1.cs プロジェクト: GIS-gongcheng/Homework
        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墨卡托投影!", "投影转换结果");
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: GIS-gongcheng/Homework
        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墨卡托投影!", "投影转换结果");
                }
            }
        }