コード例 #1
0
        //开始输出  事件
        private void Btn_OutPutShape_Click(object sender, EventArgs e)
        {
            try
            {
                this.Btn_OutPutShape.Enabled = false;
                this.Cursor = Cursors.WaitCursor;

                object obj = this.comboBox1.SelectedItem;
                if (obj != null && obj is CommonComboBoxItem)
                {
                    CommonComboBoxItem item = obj as CommonComboBoxItem;
                    IFeatureClass      fc   = item.Tag as IFeatureClass;

                    string outShapeFilePath = this.textBox1.Text;//
                    if (outShapeFilePath.Trim() == "")
                    {
                        MessageBox.Show("请先录入要输出的Shape文件的路径!", "提示");
                        return;
                    }

                    OutShapeClass shpOp = new OutShapeClass();
                    shpOp.ParentForm = this;
                    if (cb_IsObjGeo.Checked == true)
                    {
                        shpOp.OIDFieldName      = "OBJECTID";
                        shpOp.GeometryFieldName = "GEOMETRY";
                        shpOp.IsObjGeo          = true;
                    }
                    if (IsSelected.Checked == false)
                    {  //对整表要素
                        shpOp.OutPut(fc, outShapeFilePath);
                    }
                    else
                    {  //对已选择要素
                        ZhMapClass zhmap   = new ZhMapClass(ArcMap.Document.FocusMap);
                        string     fc_Name = (fc as IDataset).Name;
                        fc_Name = TokayWorkspace.GetDatasetName(fc as IDataset);
                        IFeatureLayer featLayer = zhmap.GetFeatureLayerByFeatureClassName(fc_Name);
                        shpOp.OutPutSelectedFeature(featLayer, outShapeFilePath);
                    }
                    MessageBox.Show("输出Shape成功!", "提示");
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message, "提示");
            }
            finally
            {
                this.Btn_OutPutShape.Enabled = true;
                this.Cursor = Cursors.Default;
            }
        }
コード例 #2
0
        //输出shape功能
        private void Btn_OutPutShape_Click(object sender, EventArgs e)
        {
            frmProgressBar1 pb = null;

            try
            {
                this.Btn_OutPutShape.Enabled = false;
                this.Cursor = Cursors.WaitCursor;
                //获取选中的范围要素类
                IFeatureClass reg_fc = null;
                object        obj    = this.comboBox1.SelectedItem;
                if (obj != null && obj is CommonComboBoxItem)
                {
                    CommonComboBoxItem item = obj as CommonComboBoxItem;
                    reg_fc = item.Tag as IFeatureClass;
                }
                if (reg_fc == null)
                {
                    MessageBox.Show("请先选择选中的范围图层", "提示");
                    return;
                }
                ZhMapClass zhmap   = new ZhMapClass(ArcMap.Document.FocusMap);
                string     fc_Name = (reg_fc as IDataset).Name;
                fc_Name = TokayWorkspace.GetDatasetName(reg_fc as IDataset);
                IFeatureLayer SelectedfeatLayer = zhmap.GetFeatureLayerByFeatureClassName(fc_Name);
                //
                List <IFeatureClass> fcList = new List <IFeatureClass>();
                for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
                {
                    if (this.checkedListBox1.GetItemChecked(i) == true)
                    {   //选中输出的要素类
                        CommonComboBoxItem cbitem = this.checkedListBox1.Items[i] as CommonComboBoxItem;
                        fcList.Add(cbitem.Tag as IFeatureClass);
                    }
                }
                //获取要输出的目录:
                string outShapeFilePath = "";
                string outShapeDir      = "";

                outShapeDir = this.textBox1.Text;

                if (fcList != null && fcList.Count > 0)
                {
                    pb                      = new frmProgressBar1();
                    pb.Text                 = "输出多shape文件功能";
                    pb.Caption1.Text        = "输出shape进度...";
                    pb.progressBar1.Maximum = fcList.Count;
                    pb.progressBar1.Value   = 0;
                    pb.Show(this);
                    Application.DoEvents();

                    string        tmpLayerName = "";
                    IFeatureClass fc           = null;
                    OutShapeClass shpOp        = new OutShapeClass();
                    for (int i = 0; i < fcList.Count; i++)
                    {
                        fc = fcList[i];
                        if (fc is IDataset)
                        {   //英文名
                            tmpLayerName = (fc as IDataset).Name;
                        }
                        else
                        {   //中文名
                            tmpLayerName = fc.AliasName;
                        }
                        outShapeFilePath = outShapeDir + "\\" + tmpLayerName + ".shp";
                        pb.Caption1.Text = "正在输出要素类:" + tmpLayerName + "(" + fc.AliasName + ")";
                        if (pb.progressBar1.Value <= pb.progressBar1.Maximum)
                        {
                            pb.progressBar1.Value += 1;
                        }
                        Application.DoEvents();
                        //对选中范围的表要素输出
                        shpOp.OutPutSelectedFeatureByOverlap(SelectedfeatLayer, fc, outShapeFilePath);
                    }
                    MessageBox.Show("输出完成!", "提示");
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message, "提示");
            }
            finally
            {
                this.Btn_OutPutShape.Enabled = true;
                this.Cursor = Cursors.Default;
                if (pb != null)
                {
                    pb.Close();
                    pb.Dispose();
                    pb = null;
                }
            }
        }
コード例 #3
0
        //输出shape功能
        private void Btn_OutPutShape_Click(object sender, EventArgs e)
        {
            try
            {
                this.Btn_OutPutShape.Enabled = false;
                this.Cursor = Cursors.WaitCursor;

                //获取选中的要素类
                List <IFeatureClass> fcList = new List <IFeatureClass>();
                for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
                {
                    if (this.checkedListBox1.GetItemChecked(i) == true)
                    {   //选中要素类
                        CommonComboBoxItem cbitem = this.checkedListBox1.Items[i] as CommonComboBoxItem;
                        fcList.Add(cbitem.Tag as IFeatureClass);
                    }
                }
                //获取要输出的目录:
                string outShapeFilePath = "";
                string outShapeDir      = "";

                outShapeDir = this.textBox1.Text;

                if (fcList != null && fcList.Count > 0)
                {
                    pb                      = new frmProgressBar1();
                    pb.Text                 = "输出多shape文件功能";
                    pb.Caption1.Text        = "输出shape进度...";
                    pb.progressBar1.Maximum = fcList.Count;
                    pb.progressBar1.Value   = 0;
                    pb.Show(this);
                    Application.DoEvents();

                    string        tmpLayerName = "";
                    IFeatureClass fc           = null;
                    OutShapeClass shpOp        = new OutShapeClass();
                    for (int i = 0; i < fcList.Count; i++)
                    {
                        fc = fcList[i];
                        if (fc is IDataset)
                        {   //英文名
                            tmpLayerName = (fc as IDataset).Name;
                        }
                        else
                        {   //中文名
                            tmpLayerName = fc.AliasName;
                        }
                        outShapeFilePath = outShapeDir + "\\" + tmpLayerName + ".shp";
                        pb.Caption1.Text = "正在输出要素类:" + tmpLayerName + "(" + fc.AliasName + ")";
                        if (pb.progressBar1.Value <= pb.progressBar1.Maximum)
                        {
                            pb.progressBar1.Value += 1;
                        }
                        Application.DoEvents();
                        //对整表要素
                        shpOp.OutPut(fc, outShapeFilePath);
                    }
                    MessageBox.Show("输出完成!", "提示");
                }
            }
            catch (Exception ee)
            {
                Log.WriteLine(ee);
                MessageBox.Show(ee.Message, "提示");
            }
            finally
            {
                this.Btn_OutPutShape.Enabled = true;
                this.Cursor = Cursors.Default;
                if (pb != null)
                {
                    pb.Close();
                    pb.Dispose();
                    pb = null;
                }
            }
        }