Example #1
0
        private void frmOutMuliShapeBySelectedGeometryUI_Load(object sender, EventArgs e)
        {
            this.comboBox1.Items.Clear();
            IFeatureClass fc    = null;
            ZhMapClass    zhmap = new ZhMapClass(ArcMap.Document.FocusMap);

            IFeatureClass[] fcArray = zhmap.GetFeatureClassArray();
            for (int i = 0; i < fcArray.Length; i++)
            {
                fc = fcArray[i];
                if (fc != null)
                {
                    CommonComboBoxItem itm = new CommonComboBoxItem();
                    itm.Text = fc.AliasName;
                    itm.Tag  = fc;
                    this.comboBox1.Items.Add(itm);
                }
            }
            //
            this.checkedListBox1.Items.Clear();
            zhmap   = new ZhMapClass(ArcMap.Document.FocusMap);
            fcArray = zhmap.GetFeatureClassArray();
            for (int i = 0; i < fcArray.Length; i++)
            {
                fc = fcArray[i];
                if (fc != null)
                {
                    CommonComboBoxItem itm = new CommonComboBoxItem();
                    itm.Text = fc.AliasName;
                    itm.Tag  = fc;
                    this.checkedListBox1.Items.Add(itm);
                }
            }
        }
        private void Btn_addEllipField_Click(object sender, EventArgs e)
        {
            object obj = this.comboBox1.SelectedItem;

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

                //
                if (fc.Fields.FindField("TQMJ") < 0)
                {
                    TokayWorkspace.CreateNumberField(fc as ITable, "TQMJ", "椭球面积");
                }
                if (fc.Fields.FindField("TQMJ2000") < 0)
                {
                    TokayWorkspace.CreateNumberField(fc as ITable, "TQMJ2000", "椭球面积2000");
                }
                if (fc.Fields.FindField("TXMJ") < 0)
                {
                    TokayWorkspace.CreateNumberField(fc as ITable, "TXMJ", "图形面积");
                }
            }
            this.comboBox1_SelectedIndexChanged(null, null);
        }
Example #3
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;
            }
        }
Example #4
0
        public override bool Equals(object obj)
        {
            CommonComboBoxItem ccbi = obj as CommonComboBoxItem;

            if (ccbi != null)
            {
                if (this.Text == ccbi.Text &&
                    this.Value == ccbi.Value)
                {
                    return(true);
                }
            }
            return(false);
        }
        private void frmEllipseAreaLayerListUI_Load(object sender, EventArgs e)
        {
            //初始化图层
            this.comboBox1.Items.Clear();
            IFeatureClass fc    = null;
            ZhMapClass    zhmap = new ZhMapClass(ArcMap.Document.FocusMap);

            IFeatureClass[] fcArray = zhmap.GetFeatureClassArray();
            for (int i = 0; i < fcArray.Length; i++)
            {
                fc = fcArray[i];
                if (fc != null)
                {
                    CommonComboBoxItem itm = new CommonComboBoxItem();
                    itm.Text = fc.AliasName;
                    itm.Tag  = fc;
                    this.comboBox1.Items.Add(itm);
                }
            }
        }
        void treeFeatures_AfterSelect(object sender, TreeViewEventArgs e)
        {
            cbxRings.Tag = null;
            cbxRings.Items.Clear();

            if (treeFeatures.SelectedNode != null)
            {
                IFeature  feature  = treeFeatures.SelectedNode.Tag as IFeature;
                IGeometry geometry = feature.ShapeCopy;
                (geometry as ITopologicalOperator).Simplify();

                switch (geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    //圈号
                    foreach (KeyValuePair <string, IRing> ring in PolygonHelper.GetAllRings(geometry as IPolygon))
                    {
                        IGeometry          geo  = ring.Value as IGeometry;
                        CommonComboBoxItem item = new CommonComboBoxItem("", "", geo);
                        item.Text = ring.Key;
                        cbxRings.Items.Add(item);
                    }
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    IGeometryCollection geoCol = geometry as IGeometryCollection;
                    for (int i = 0; i < geoCol.GeometryCount; i++)
                    {
                        cbxRings.Items.Add(new CommonComboBoxItem("第" + (i + 1).ToString() + "部分", "", geoCol.get_Geometry(i)));
                    }
                    break;
                }

                cbxRings.Tag = geometry;
                if (cbxRings.Items.Count > 0)
                {
                    cbxRings.SelectedIndex = 0;
                }
            }
        }
        //选择源图层已改变 事件
        private void CB_LayerList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            //初始化当前图层的列字段名称
            object obj = this.CB_LayerList2.SelectedItem;

            if (obj != null && obj is CommonComboBoxItem)
            {
                CommonComboBoxItem item        = obj as CommonComboBoxItem;
                IFeatureClass      fc          = item.Tag as IFeatureClass;
                ZhFeatureClass     zhfeatclass = new ZhPolylineFeatureClass(fc);
                //获取字段集合
                List <string> fieldNameArray = zhfeatclass.GetFieldNames();
                if (fieldNameArray != null && fieldNameArray.Count > 0)
                {
                    this.CB_Fields2.Items.Clear();
                    foreach (string fd in fieldNameArray)
                    {
                        this.CB_Fields2.Items.Add(fd);
                    }
                }
            }
        }
        //选择图层已改变 事件
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //初始化当前图层的列字段名称
            object obj = this.comboBox1.SelectedItem;

            if (obj != null && obj is CommonComboBoxItem)
            {
                CommonComboBoxItem item           = obj as CommonComboBoxItem;
                IFeatureClass      fc             = item.Tag as IFeatureClass;
                ZhFeatureClass     zhfeatclass    = new ZhPolylineFeatureClass(fc);
                List <string>      fieldNameArray = zhfeatclass.GetFieldNames();
                if (fieldNameArray != null && fieldNameArray.Count > 0)
                {
                    this.CB_Fields.Items.Clear();
                    foreach (string fd in fieldNameArray)
                    {
                        this.CB_Fields.Items.Add(fd);
                    }
                }
                this.RefreshSpatialReferenceText(fc);
            }
            //---
        }
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            frmProgressBar2 pb2 = null;

            try
            {
                this.BtnUpdate.Enabled = false;
                this.Cursor            = Cursors.WaitCursor;
                //
                string txtPath = this.textBox1.Text.Trim();
                if (txtPath == "" || System.IO.File.Exists(txtPath) == false)
                {
                    MessageBox.Show("请先选择YSDM对照txt文件", "提示");
                    this.BtnUpdate.Enabled = true;
                    this.Cursor            = Cursors.Default;
                    return;
                }
                //
                if (MessageBox.Show("请确认是否要对选中项进行批量更新YSDM字段的值操作?", "提示", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel)
                {
                    this.BtnUpdate.Enabled = true;
                    this.Cursor            = Cursors.Default;
                    return;
                }
                //--------------------------------------
                List <ItemClass> ItemList = new List <ItemClass>();
                StreamReader     sr       = new StreamReader(txtPath, Encoding.Default);
                while (sr.EndOfStream == false)
                {
                    string   line      = sr.ReadLine();
                    string[] lineArray = line.Split(new char[] { ',' });
                    if (lineArray != null && lineArray.Length >= 3)
                    {
                        ItemClass item = new ItemClass();
                        item.Value   = lineArray[0].Trim();   //YSDM
                        item.Caption = lineArray[1].Trim();   //YSDMName
                        item.Tag     = lineArray[2].Trim();   //LayerName
                        //
                        ItemList.Add(item);
                    }
                }
                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                    sr = null;
                }
                //--------------------------------------
                //获取选中的要素类
                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);
                    }
                }
                if (fcList != null && fcList.Count > 0)
                {
                    pb2      = new frmProgressBar2();
                    pb2.Text = "批量更新YSDM字段进度...";
                    pb2.progressBar1.Maximum = fcList.Count + 1;
                    pb2.progressBar1.Value   = 0;
                    pb2.Caption1.Text        = "正在更新...";
                    pb2.Show(this);
                    Application.DoEvents();
                    //
                    ZHFeaturePoint zhfeat    = null;
                    int            featIndex = 0;
                    int            featCount = 0;
                    //
                    string YSDM = "";
                    for (int i = 0; i < fcList.Count; i++)
                    {
                        featIndex = 0;
                        IFeatureClass fc = fcList[i];
                        pb2.Caption1.Text      = "正在更新图层:" + fc.AliasName + "...";
                        pb2.progressBar1.Value = i;
                        Application.DoEvents();
                        //
                        featCount = fc.FeatureCount(null);
                        pb2.progressBar2.Value   = 0;
                        pb2.progressBar2.Maximum = featCount + 1;
                        pb2.Caption2.Text        = "正在更新要素...";
                        Application.DoEvents();
                        //获取图层对应的要素代码值
                        string fcName = fc.AliasName;
                        if (fc is IDataset)
                        {
                            fcName = (fc as IDataset).Name;
                        }
                        foreach (ItemClass item in ItemList)
                        {
                            string txtLayerName = item.Tag.ToString();
                            //-------------------------------
                            if (cb_IsLayerLastPreStr.Checked == true)
                            {   //是后缀字符串
                                txtLayerName = txtLayerName + this.txt_LayerPreStr.Text.Trim();
                            }
                            else
                            {   //是前缀字符串
                                txtLayerName = this.txt_LayerPreStr.Text.Trim() + txtLayerName;
                            }
                            //-------------------------------
                            if (fcName.ToUpper() == txtLayerName.ToUpper())
                            {
                                YSDM = item.Value.ToString();
                                break;
                            }
                        }
                        //
                        IFeatureCursor fcur = fc.Update(null, false);
                        IFeature       feat = fcur.NextFeature();
                        while (feat != null)
                        {
                            featIndex += 1;
                            if (featIndex % 200 == 0)
                            {
                                pb2.Caption2.Text      = "正在更新图层:" + fc.AliasName + "(当前:" + featIndex.ToString() + "/" + featCount.ToString() + ")";
                                pb2.progressBar2.Value = featIndex;
                                Application.DoEvents();
                                fcur.Flush();
                            }
                            zhfeat = new ZHFeaturePoint(feat);
                            zhfeat.setFieldValue("YSDM", YSDM);
                            fcur.UpdateFeature(feat);
                            //
                            feat = fcur.NextFeature();
                        }
                        fcur.Flush();
                        if (fcur != null)
                        {
                            TokayWorkspace.ComRelease(fcur);
                            fcur = null;
                        }
                    }
                    if (pb2 != null)
                    {
                        pb2.Close();
                        pb2.Dispose();
                        pb2 = null;
                    }
                    MessageBox.Show("更新YSDM完毕!", "提示");
                }
            }
            catch (Exception ee)
            {
                Log.WriteLine(ee);
                MessageBox.Show(ee.Message, "提示");
            }
            finally
            {
                this.BtnUpdate.Enabled = true;
                this.Cursor            = Cursors.Default;
                if (pb2 != null)
                {
                    pb2.Close();
                    pb2.Dispose();
                    pb2 = null;
                }
            }
        }
Example #10
0
        //开始批量更新 事件
        private void BtnUpdate_Click(object sender, EventArgs e)
        {
            frmProgressBar2 pb2 = null;

            try
            {
                this.BtnUpdate.Enabled = false;
                this.Cursor            = Cursors.WaitCursor;
                string LineText = "";

                if (MessageBox.Show("请确认是否要对选中项进行批量更新BSM字段的值操作?", "提示", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel)
                {
                    this.BtnUpdate.Enabled = true;
                    this.Cursor            = Cursors.Default;
                    return;
                }

                //获取选中的要素类
                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);
                    }
                }
                if (fcList != null && fcList.Count > 0)
                {
                    pb2      = new frmProgressBar2();
                    pb2.Text = "批量更新BSM字段进度...";
                    pb2.progressBar1.Maximum = fcList.Count + 1;
                    pb2.progressBar1.Value   = 0;
                    pb2.Caption1.Text        = "正在更新...";
                    pb2.Show(this);
                    Application.DoEvents();
                    //
                    ZHFeaturePoint zhfeat    = null;
                    int            featIndex = 0;
                    int            featCount = 0;
                    //
                    int BSMIndex = 0;
                    for (int i = 0; i < fcList.Count; i++)
                    {
                        featIndex = 0;
                        IFeatureClass fc = fcList[i];
                        pb2.Caption1.Text      = "正在更新图层:" + fc.AliasName + "...";
                        pb2.progressBar1.Value = i;
                        Application.DoEvents();
                        //
                        featCount = fc.FeatureCount(null);
                        pb2.progressBar2.Value   = 0;
                        pb2.progressBar2.Maximum = featCount + 1;
                        pb2.Caption2.Text        = "正在更新要素...";
                        Application.DoEvents();
                        //
                        IFeatureCursor fcur = fc.Update(null, false);
                        IFeature       feat = fcur.NextFeature();
                        while (feat != null)
                        {
                            featIndex += 1;
                            //---
                            BSMIndex += 1;
                            //---
                            if (featIndex % 200 == 0)
                            {
                                pb2.Caption2.Text      = "正在更新图层:" + fc.AliasName + "(当前:" + featIndex.ToString() + "/" + featCount.ToString() + ")";
                                pb2.progressBar2.Value = featIndex;
                                Application.DoEvents();
                                fcur.Flush();
                            }
                            zhfeat = new ZHFeaturePoint(feat);
                            zhfeat.setFieldValue("BSM", BSMIndex);
                            fcur.UpdateFeature(feat);
                            //
                            feat = fcur.NextFeature();
                        }
                        fcur.Flush();
                        if (fcur != null)
                        {
                            TokayWorkspace.ComRelease(fcur);
                            fcur = null;
                        }
                    }
                    if (pb2 != null)
                    {
                        pb2.Close();
                        pb2.Dispose();
                        pb2 = null;
                    }
                    MessageBox.Show("更新BSM完毕!", "提示");
                }
            }
            catch (Exception ee)
            {
                Log.WriteLine(ee);
                MessageBox.Show(ee.Message, "提示");
            }
            finally
            {
                this.BtnUpdate.Enabled = true;
                this.Cursor            = Cursors.Default;
                if (pb2 != null)
                {
                    pb2.Close();
                    pb2.Dispose();
                    pb2 = null;
                }
            }
        }
        //快速叠加传值功能
        private void QuickOverlapTranValue()
        {
            IFeatureCursor      fcur  = null;
            mdbAccessLayerClass mdbOp = null;
            frmProgressBar1     pb    = null;

            try
            {
                this.button1.Enabled = false;
                this.Cursor          = Cursors.WaitCursor;

                //获取参数
                string updateField  = this.CB_Fields1.Text.Trim();
                string valFromField = this.CB_Fields2.Text.Trim();

                pb                      = new frmProgressBar1();
                pb.Text                 = "空间叠加传值进度...";
                pb.Caption1.Text        = "预处理中...";
                pb.progressBar1.Maximum = 10;
                pb.progressBar1.Value   = 0;
                pb.Show(this);
                Application.DoEvents();

                //1 获取和生成临时空间数据库
                string tmpdir = Application.StartupPath + "\\TmpDir";
                if (System.IO.Directory.Exists(tmpdir) == false)
                {
                    System.IO.Directory.CreateDirectory(tmpdir);
                }
                this.tmpMdbFilePath = tmpdir + "\\GeoTransValue.mdb";
                if (System.IO.File.Exists(this.tmpMdbFilePath) == true)
                {
                    CommonClass.DeleteFile(this.tmpMdbFilePath);
                }
                //--
                TokayWorkspace.CreateGeodatabase(this.tmpMdbFilePath);
                //2 开始空间叠加操作
                pb.Caption1.Text       = "空间叠加中...";
                pb.progressBar1.Value += 1;
                Application.DoEvents();
                //两个图层作叠加相交运算输出到一个mdb空间数据库中
                string        FID_fcName1   = "";
                string        fcName1       = "";
                string        fcName2       = "";
                string        fd_Shape_Area = "shape_area";
                IFeatureClass fc1           = null;
                IFeatureClass fc2           = null;
                //目标图层
                object obj = this.CB_LayerList1.SelectedItem;
                if (obj != null && obj is CommonComboBoxItem)
                {
                    CommonComboBoxItem item = obj as CommonComboBoxItem;
                    fc1     = item.Tag as IFeatureClass;
                    fcName1 = (fc1 as IDataset).Name;
                }
                //源图层
                obj = this.CB_LayerList2.SelectedItem;
                if (obj != null && obj is CommonComboBoxItem)
                {
                    CommonComboBoxItem item = obj as CommonComboBoxItem;
                    fc2           = item.Tag as IFeatureClass;
                    fcName2       = (fc2 as IDataset).Name;
                    fd_Shape_Area = fc2.ShapeFieldName + "_area";
                }
                //生成的相交图层名称
                tmpLayerName = fcName1 + "_" + fcName2;
                FID_fcName1  = "FID_" + fcName1;

                double TopoTolerance             = 0.0001;
                IntersectCalculateMdbEx mdbIsCal = new IntersectCalculateMdbEx();
                if (mdbIsCal.Execute(fc1, fc2, this.tmpMdbFilePath + "\\" + tmpLayerName, "INPUT", TopoTolerance) == true)
                {
                    #region 空间传值中
                    pb.Caption1.Text       = "空间传值中...";
                    pb.progressBar1.Value += 1;
                    Application.DoEvents();
                    //
                    ZhFeature zhfeat    = null;
                    int       index_fc1 = fc1.Fields.FindField(valFromField);
                    if (index_fc1 >= 0)
                    {
                        valFromField = valFromField + "_1";
                    }

                    mdbOp = new mdbAccessLayerClass(this.tmpMdbFilePath);
                    string x = "select " + FID_fcName1 + "," + valFromField + ",sum(" + fd_Shape_Area + ") as geo_area ";
                    x += " from " + tmpLayerName + " ";
                    x += " group by " + FID_fcName1 + "," + valFromField + "";
                    DataTable dt = mdbOp.GetMdbDB.ExecuteDataTable(x);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        #region  值中
                        string oid          = "";
                        int    fc1_count    = 0;
                        int    index        = 0;
                        string objval       = "";
                        double geo_area     = 0.0;
                        double geo_area_max = 0.0;
                        //更新值
                        fc1_count               = fc1.FeatureCount(null);
                        pb.progressBar1.Value   = 0;
                        pb.progressBar1.Maximum = fc1_count + 1;
                        Application.DoEvents();
                        //
                        fcur = fc1.Update(null, false);
                        IFeature feat = fcur.NextFeature();
                        while (feat != null)
                        {
                            index += 1;
                            if (index % 50 == 0)
                            {
                                pb.Caption1.Text      = "空间叠加传值中...第[" + index + "]个/共[" + fc1_count + "]个";
                                pb.progressBar1.Value = index;
                                Application.DoEvents();
                                fcur.Flush();
                            }
                            zhfeat = new ZHFeaturePolygon(feat);
                            oid    = zhfeat.getObjectID();
                            //
                            DataRow[] drArray = dt.Select(FID_fcName1 + "=" + oid);
                            if (drArray != null && drArray.Length >= 1)
                            {
                                objval       = "";
                                geo_area     = 0.0;
                                geo_area_max = 0.0;
                                //获取面积最大的面积值
                                foreach (DataRow dr in drArray)
                                {
                                    geo_area = CommonClass.TNum(dr["geo_area"].ToString());
                                    if (geo_area >= geo_area_max)
                                    {
                                        objval       = dr[valFromField].ToString();
                                        geo_area_max = geo_area;
                                    }
                                }
                                //设置值
                                zhfeat.setFieldValue(updateField, objval);
                                fcur.UpdateFeature(feat);
                            }
                            feat = fcur.NextFeature();
                        }
                        fcur.Flush();
                        if (fcur != null)
                        {
                            TokayWorkspace.ComRelease(fcur);
                            fcur = null;
                        }
                        #endregion
                    }
                    if (mdbOp != null)
                    {
                        mdbOp.GetMdbDB.Dispose();
                        mdbOp = null;
                    }
                    #endregion
                    if (pb != null)
                    {
                        pb.Close();
                        pb.Dispose();
                        pb = null;
                    }
                    MessageBox.Show("传值完毕!", "提示");
                }
                else
                {
                    MessageBox.Show("空间叠加失败!" + mdbIsCal.Message, "提示");
                }
            }
            catch (Exception ee)
            {
                Log.WriteLine(ee);
                MessageBox.Show(ee.Message, "提示");
            }
            finally
            {
                this.button1.Enabled = true;
                this.Cursor          = Cursors.Default;

                if (fcur != null)
                {
                    TokayWorkspace.ComRelease(fcur);
                    fcur = null;
                }
                if (mdbOp != null)
                {
                    mdbOp.GetMdbDB.Dispose();
                    mdbOp = null;
                }
                if (pb != null)
                {
                    pb.Close();
                    pb.Dispose();
                    pb = null;
                }
            }
        }
Example #12
0
        //开始平移 事件
        private void Btn_MapMove_Click(object sender, EventArgs e)
        {
            frmProgressBar2 pb2 = null;

            try
            {
                this.Btn_MapMove.Enabled = false;
                this.Cursor = Cursors.WaitCursor;
                string LineText = "";

                double dx = 0.0;
                double dy = 0.0;

                dx = CommonClass.TNum(this.numericBox1.Text.Trim());
                dy = CommonClass.TNum(this.numericBox2.Text.Trim());

                if (MessageBox.Show("请确认是否要对选中项进行整体平移操作?", "提示", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel)
                {
                    this.Btn_MapMove.Enabled = true;
                    this.Cursor = Cursors.Default;
                    return;
                }

                //获取选中的要素类
                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);
                    }
                }
                if (fcList != null && fcList.Count > 0)
                {
                    pb2      = new frmProgressBar2();
                    pb2.Text = "平移进度...";
                    pb2.progressBar1.Maximum = fcList.Count + 1;
                    pb2.progressBar1.Value   = 0;
                    pb2.Caption1.Text        = "正在平移...";
                    pb2.Show(this);
                    Application.DoEvents();
                    //
                    ZHFeaturePoint zhfeat    = null;
                    int            featIndex = 0;
                    int            featCount = 0;
                    for (int i = 0; i < fcList.Count; i++)
                    {
                        featIndex = 0;
                        IFeatureClass fc = fcList[i];
                        pb2.Caption1.Text      = "正在平移图层:" + fc.AliasName + "...";
                        pb2.progressBar1.Value = i;
                        Application.DoEvents();
                        //
                        featCount = fc.FeatureCount(null);
                        pb2.progressBar2.Value   = 0;
                        pb2.progressBar2.Maximum = featCount + 1;
                        pb2.Caption2.Text        = "正在平移要素...";
                        Application.DoEvents();
                        //
                        IFeatureCursor fcur = fc.Update(null, false);
                        IFeature       feat = fcur.NextFeature();
                        while (feat != null)
                        {
                            featIndex += 1;
                            if (featIndex % 200 == 0)
                            {
                                pb2.Caption2.Text      = "正在平移图层:" + fc.AliasName + "(当前:" + featIndex.ToString() + "/" + featCount.ToString() + ")";
                                pb2.progressBar2.Value = featIndex;
                                Application.DoEvents();
                                fcur.Flush();
                            }
                            zhfeat = new ZHFeaturePoint(feat);
                            if (fc.FeatureType == esriFeatureType.esriFTAnnotation)
                            {   //注记要素移动 OK
                                IAnnotationFeature anFeat = feat as IAnnotationFeature;
                                IElement           TextEl = (IElement)((IClone)anFeat.Annotation).Clone();
                                ITransform2D       trans  = TextEl as ITransform2D;
                                trans.Move(dx, dy);
                                anFeat.Annotation = TextEl;
                                fcur.UpdateFeature(feat);
                            }
                            else
                            {   //一般要素移动 OK
                                zhfeat.Move(dx, dy);
                                fcur.UpdateFeature(feat);
                            }
                            //
                            feat = fcur.NextFeature();
                        }
                        fcur.Flush();
                        if (fcur != null)
                        {
                            TokayWorkspace.ComRelease(fcur);
                            fcur = null;
                        }
                        pb2.Caption2.Text = "正在重新计算Extent范围...";
                        Application.DoEvents();
                        //重新计算Extent范围
                        TokayWorkspace.UpdateExtent(fc);
                    }
                    if (pb2 != null)
                    {
                        pb2.Close();
                        pb2.Dispose();
                        pb2 = null;
                    }
                    MessageBox.Show("地图平移完毕!", "提示");
                }
            }
            catch (Exception ee)
            {
                Log.WriteLine(ee);
                MessageBox.Show(ee.Message, "提示");
            }
            finally
            {
                this.Btn_MapMove.Enabled = true;
                this.Cursor = Cursors.Default;
                if (pb2 != null)
                {
                    pb2.Close();
                    pb2.Dispose();
                    pb2 = null;
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ProgressDialog pd = null;

            try
            {
                CommonComboBoxItem item = this.comboBox1.SelectedItem as CommonComboBoxItem;
                if (item == null)
                {
                    MessageBox.Show("请先选择要计算的图层", "提示");
                    return;
                }
                string fd_item = this.CB_Fields.Text;
                if (fd_item == "")
                {
                    MessageBox.Show("请先选择要计算的字段", "提示");
                    return;
                }
                //ILayer layer = item.Tag as ILayer;
                //IFeatureLayer featLayer = layer as IFeatureLayer;
                IFeatureClass fc = item.Tag as IFeatureClass;
                //
                string fdName = this.CB_Fields.Text;
                //
                int fCount = fc.FeatureCount(null);
                if (fCount > 0)
                {
                    IFeatureCursor pcursor = fc.Update(null, false);
                    IFeature       pf      = pcursor.NextFeature();
                    int            index   = fc.FindField(fdName);
                    pd         = new ProgressDialog();
                    pd.Text    = "进度";
                    pd.Message = "计算字段图形面积中......";
                    pd.Minimum = 0;
                    pd.Maximum = fCount;
                    pd.Show(this);
                    //
                    Application.DoEvents();
                    double t_area = 0.0;
                    int    n      = 0;
                    while (pf != null)
                    {
                        n = n + 1;
                        if (n % 200 == 0)
                        {
                            pd.Value   = n;
                            pd.Message = "计算字段图形面积中......" + pd.Value.ToString() + "/" + pd.Maximum.ToString();
                            Application.DoEvents();
                            pcursor.Flush();
                        }
                        IArea area = (pf.Shape as IArea);
                        if (area != null)
                        {
                            t_area = area.Area;
                            pf.set_Value(index, t_area);
                            //
                            pcursor.UpdateFeature(pf);
                        }
                        //
                        pf = pcursor.NextFeature();
                    }
                    pcursor.Flush();
                    if (pcursor != null)
                    {
                        TokayWorkspace.ComRelease(pcursor);
                        pcursor = null;
                    }
                    if (pd != null)
                    {
                        pd.Dispose();
                        pd = null;
                    }
                    MessageBox.Show("计算完毕!", "提示");
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.StackTrace, "提示");
            }
            finally
            {
                if (pd != null)
                {
                    pd.Dispose();
                    pd = null;
                }
            }
        }
        //开始计算
        private void Btn_Compute_Click(object sender, EventArgs e)
        {
            string tpFiledName = this.CB_Fields.Text;

            object obj = this.comboBox1.SelectedItem;

            if (obj != null && obj is CommonComboBoxItem)
            {
                CommonComboBoxItem item             = obj as CommonComboBoxItem;
                IFeatureClass      pFeatureClass    = item.Tag as IFeatureClass;
                decimal            ellipseArea      = 0;
                AnyTrapeziaEllipseAreaCompute_JF jf = new AnyTrapeziaEllipseAreaCompute_JF();
                //获取坐标系
                jf.Datum = EnumProjectionDatum.CGCS2000;
                if (this.rb2000.Checked == true)
                {
                    jf.Datum = EnumProjectionDatum.CGCS2000;
                }
                if (this.rb_xian80.Checked == true)
                {
                    jf.Datum = EnumProjectionDatum.Xian80;
                }
                if (this.rb_beijing54.Checked == true)
                {
                    jf.Datum = EnumProjectionDatum.Bejing54;
                }
                //获取大数设置
                jf.IsBigNumber = false;
                if (this.CB_IsBigNumber.Checked == true)
                {
                    jf.IsBigNumber = true;
                }
                //获取分度设置
                jf.Strip = EnumStrip.Strip6;
                if (CB_FD.Checked == true)
                {
                    jf.Strip = EnumStrip.Strip3;
                }
                //获取中央子午线
                jf.L0 = CommonClass.TDec(this.txt_DD.Text) * (int)jf.Strip;

                int             fIndex    = 0;
                int             tmpFCount = pFeatureClass.FeatureCount(null);
                frmProgressBar1 pb        = new frmProgressBar1();
                pb.Text                   = "正在进行椭球面积计算...";
                pb.KDCaption1             = "正在进行椭球面积计算...";
                pb.KDProgressBar1.Maximum = tmpFCount + 1;
                pb.KDProgressBar1.Value   = 0;
                pb.Show();
                Application.DoEvents();

                IFeatureCursor fcur = pFeatureClass.Update(null, false);
                IFeature       feat = fcur.NextFeature();
                while (feat != null)
                {
                    fIndex += 1;
                    if (fIndex % 500 == 0)
                    {
                        pb.KDCaption1           = "已计算完成要素个数:" + fIndex.ToString() + "/总" + tmpFCount.ToString();
                        pb.KDProgressBar1.Value = fIndex;
                        Application.DoEvents();
                        fcur.Flush();
                    }
                    ellipseArea = jf.Compute(feat.ShapeCopy);
                    //save ellipseArea...
                    ZhFeature zhfeat = new ZHFeaturePolygon(feat);
                    zhfeat.setFieldValue(tpFiledName, ellipseArea);

                    fcur.UpdateFeature(feat);

                    feat = fcur.NextFeature();
                }
                fcur.Flush();

                TokayWorkspace.ComRelease(fcur);
                fcur = null;


                pb.Close();
                pb.Dispose();
                pb = null;

                MessageBox.Show(this, "计算椭球面积完毕!", "提示");
            }
        }
Example #15
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;
                }
            }
        }
        //自定义叠加传值
        private void CustomOverlapTranValue()
        {
            frmProgressBar1 pb = null;
            //
            IFeatureCursor fCur     = null;
            IFeatureCursor fCur_fc2 = null;

            //
            try
            {
                this.button1.Enabled = false;
                this.Cursor          = Cursors.WaitCursor;

                //获取参数
                string updateField  = this.CB_Fields1.Text.Trim();
                string valFromField = this.CB_Fields2.Text.Trim();

                pb                      = new frmProgressBar1();
                pb.Text                 = "空间叠加传值进度";
                pb.Caption1.Text        = "预处理中......";
                pb.progressBar1.Maximum = 10;
                pb.progressBar1.Value   = 0;
                pb.Show(this);
                Application.DoEvents();

                //2 开始空间叠加操作
                pb.Caption1.Text       = "空间叠加中...";
                pb.progressBar1.Value += 1;
                Application.DoEvents();
                //
                IFeatureClass fc1 = null;
                IFeatureClass fc2 = null;
                //
                object objval       = "";
                double geo_area     = 0.0;
                double geo_area_max = 0.0;
                //目标图层
                object obj = this.CB_LayerList1.SelectedItem;
                if (obj != null && obj is CommonComboBoxItem)
                {
                    CommonComboBoxItem item = obj as CommonComboBoxItem;
                    fc1 = item.Tag as IFeatureClass;
                }
                //源图层
                obj = this.CB_LayerList2.SelectedItem;
                if (obj != null && obj is CommonComboBoxItem)
                {
                    CommonComboBoxItem item = obj as CommonComboBoxItem;
                    fc2 = item.Tag as IFeatureClass;
                }
                //
                if (fc1 != null && fc2 != null)
                {
                    pb.progressBar1.Maximum = fc1.FeatureCount(null);
                    Application.DoEvents();
                    //目标图层
                    fCur = fc1.Update(null, false);
                    if (fCur != null)
                    {
                        int      recIndex = 0;
                        IFeature feat_fc1 = fCur.NextFeature();
                        while (feat_fc1 != null)
                        {
                            ZhFeature zhfeat_fc1 = new ZHFeaturePolygon(feat_fc1);
                            objval       = "";
                            geo_area     = 0.0;
                            geo_area_max = 0.0;
                            //获取面积最大的面积值
                            #region //与fc2相交运算功能
                            ISpatialFilter sFilter = new SpatialFilterClass();
                            sFilter.Geometry      = feat_fc1.ShapeCopy;
                            sFilter.GeometryField = fc2.ShapeFieldName;
                            sFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                            fCur_fc2 = fc2.Search(sFilter, false);
                            IFeature feat_fc2 = fCur_fc2.NextFeature();
                            while (feat_fc2 != null)
                            {
                                ZhFeature zhfeat_fc2 = new ZHFeaturePolygon(feat_fc2);
                                IGeometry t_geo      = null;
                                #region //获取相交对象
                                IGeometry            topGeo      = feat_fc1.ShapeCopy;
                                IGeometry            topGeo2     = feat_fc2.ShapeCopy;
                                ITopologicalOperator Topoperator = (ITopologicalOperator)topGeo;
                                Topoperator.Simplify();
                                ITopologicalOperator TopGeometry = (ITopologicalOperator)topGeo2;
                                TopGeometry.Simplify();
                                try
                                {
                                    t_geo = Topoperator.Intersect(topGeo2, topGeo.Dimension);
                                }
                                catch (Exception ee)
                                {
                                    t_geo = null;
                                }
                                #endregion
                                if (t_geo is IArea)
                                {   //面积
                                    geo_area = (t_geo as IArea).Area;
                                }
                                else if (t_geo is ICurve)
                                {   //长度
                                    geo_area = (t_geo as ICurve).Length;
                                }
                                if (geo_area >= geo_area_max)
                                {
                                    objval       = zhfeat_fc2.getFieldValue(valFromField);
                                    geo_area_max = geo_area;
                                }
                                //下一个要素
                                feat_fc2 = fCur_fc2.NextFeature();
                            }
                            if (fCur_fc2 != null)
                            {
                                TokayWorkspace.ComRelease(fCur_fc2);
                                fCur_fc2 = null;
                            }
                            #endregion
                            //设置值
                            zhfeat_fc1.setFieldValue(updateField, objval);
                            fCur.UpdateFeature(feat_fc1);
                            //
                            recIndex += 1;
                            pb.progressBar1.Value = recIndex;
                            pb.Caption1.Text      = "正在叠加传值......... 第" + pb.progressBar1.Value + "个/共" + pb.progressBar1.Maximum + "个";
                            Application.DoEvents();
                            //
                            //下一个要素
                            feat_fc1 = fCur.NextFeature();
                        }
                    }
                    if (fCur != null)
                    {
                        fCur.Flush();
                    }
                    if (fCur != null)
                    {
                        TokayWorkspace.ComRelease(fCur);
                        fCur = null;
                    }
                    if (pb != null)
                    {
                        pb.Close();
                        pb.Dispose();
                        pb = null;
                    }
                    MessageBox.Show("传值完毕!", "提示");
                }
            }
            catch (Exception ee)
            {
                Log.WriteLine(ee);
                MessageBox.Show(ee.Message, "提示");
            }
            finally
            {
                this.button1.Enabled = true;
                this.Cursor          = Cursors.Default;

                if (fCur != null)
                {
                    TokayWorkspace.ComRelease(fCur);
                    fCur = null;
                }
                if (fCur_fc2 != null)
                {
                    TokayWorkspace.ComRelease(fCur_fc2);
                    fCur_fc2 = null;
                }
                if (pb != null)
                {
                    pb.Close();
                    pb.Dispose();
                    pb = null;
                }
            }
        }
Example #17
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;
                }
            }
        }
        private void Btn_PreHandle_Click(object sender, EventArgs e)
        {
            //完成导出为mdb空间库中
            try
            {
                //this.Btn_PreHandle.Enabled = false;
                this.Cursor = Cursors.WaitCursor;

                #region     //两个图层作叠加相交运算输出到一个mdb空间数据库中
                string        fcName1 = "";
                string        fcName2 = "";
                IFeatureClass fc1     = null;
                IFeatureClass fc2     = null;
                object        obj     = this.CB_LayerList1.SelectedItem;
                if (obj != null && obj is CommonComboBoxItem)
                {
                    CommonComboBoxItem item = obj as CommonComboBoxItem;
                    fc1     = item.Tag as IFeatureClass;
                    fcName1 = (fc1 as IDataset).Name;
                }
                obj = this.CB_LayerList2.SelectedItem;
                if (obj != null && obj is CommonComboBoxItem)
                {
                    CommonComboBoxItem item = obj as CommonComboBoxItem;
                    fc2     = item.Tag as IFeatureClass;
                    fcName2 = (fc2 as IDataset).Name;
                }
                tmpLayerName = fcName1 + "_" + fcName2;

                double TopoTolerance             = 0.0001;
                IntersectCalculateMdbEx mdbIsCal = new IntersectCalculateMdbEx();
                if (mdbIsCal.Execute(fc1, fc2, this.tmpMdbFilePath + "\\" + tmpLayerName, "INPUT", TopoTolerance) == true)
                {
                    gdbUtil sic = new gdbUtil();
                    sic.enumSDEServer = EnumSDEServer.Access;
                    sic.SDE_DataBase  = this.tmpMdbFilePath;
                    sic.OpenSDEConnection();

                    IFeatureClass mdbFc = sic.getFeatureClass(tmpLayerName);
                    if (mdbFc != null)
                    {
                        this.GetFields(mdbFc);
                    }
                    TokayWorkspace.ComRelease(mdbFc);
                    mdbFc = null;
                    sic.Dispose();
                    sic = null;
                }


                #endregion
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message, "提示");
            }
            finally
            {
                //this.Btn_PreHandle.Enabled = true;
                this.Cursor = Cursors.Default;
            }
        }