Esempio n. 1
0
        /// <summary>
        /// 拷贝属性字段 this.Fields->tpObjectFeature.Fields
        /// </summary>
        /// <param name="tpObjectZHFeature"></param>
        public virtual void CopyField(ref IFeature tpObjectFeature)
        {
            //属性
            this.preGetFeatureFieldNames();
            ZHFeaturePoint tpObjectZHFeature = new ZHFeaturePoint(tpObjectFeature);

            foreach (string fdName in this.FieldNames)
            {
                if (fdName != "OBJECTID" &&
                    fdName != "FID" &&
                    this.getFieldValue(fdName) != null)
                {
                    tpObjectZHFeature.setFieldValue(fdName, this.getFieldValue(fdName));
                }
            }
        }
Esempio n. 2
0
        public virtual void Update(string WhereClause, string fieldNames, object[] objValues)
        {
            IQueryFilter oQf = new QueryFilterClass();

            oQf.WhereClause = WhereClause;
            oQf.SubFields   = fieldNames;

            IFeatureCursor oFCursor = this.featureClass.Update(oQf, false);
            IFeature       pFeat    = oFCursor.NextFeature();
            ZhFeature      pZHFeat  = null;

            while (pFeat != null)
            {
                pZHFeat          = new ZHFeaturePoint();
                pZHFeat.pFeature = pFeat;
                this.Update(pZHFeat, fieldNames, objValues);
                pFeat = oFCursor.NextFeature();
            }
            pFeat    = null;
            pZHFeat  = null;
            oFCursor = null;
            oQf      = null;
        }
Esempio n. 3
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;
                }
            }
        }
Esempio n. 4
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;
                }
            }
        }
Esempio n. 5
0
        //
        //输出外环面 shape
        public bool OutPutPolygonExteriorRing(IFeatureClass featclass, string outShapeFilePath, bool IsGetExtRingOfHaveInnerRing)
        {
            bool rbc = false;

            if (System.IO.File.Exists(outShapeFilePath) == true)
            {   //输出Shape文件
                LocalShapeFileOperator delshpOp = new LocalShapeFileOperator();
                delshpOp.LocalShapePathFileName = outShapeFilePath;
                delshpOp.DeleteShapeFile();
                delshpOp.Dispose();
            }

            esriGeometryType geoType = featclass.ShapeType;

            //创建新的Shape文件
            LocalShapeFileOperator shpOp = new LocalShapeFileOperator();

            shpOp.LocalShapePathFileName = outShapeFilePath;

            string dir  = shpOp.getDir(outShapeFilePath);
            string name = shpOp.getFileName(outShapeFilePath);
            ShapefileWorkspaceFactoryClass objwsf = new ShapefileWorkspaceFactoryClass();
            IWorkspace        objws    = objwsf.OpenFromFile(dir, 0);
            IFeatureWorkspace feaureWS = objws as IFeatureWorkspace;
            //设置投影
            ISpatialReference sr = (featclass as IGeoDataset).SpatialReference;

            shpOp.ShapeSpatialReference = sr;
            //设置shp文件的oid字段和几何字段
            if (IsObjGeo == false)
            {
                if (featclass.HasOID == true)
                {
                    this.OIDFieldName = featclass.OIDFieldName;
                }
                this.GeometryFieldName = featclass.ShapeFieldName;
            }
            shpOp.OIDFieldName      = this.OIDFieldName;
            shpOp.GeometryFieldName = this.GeometryFieldName;
            //创建要素类
            IFeatureClass fc = shpOp.CreateFeatureClass(feaureWS, name, esriFeatureType.esriFTSimple, geoType);

            if (fc != null)
            {
                TokayWorkspace.ComRelease(fc);
                fc  = null;
                rbc = true;
            }
            TokayWorkspace.ComRelease(objws);
            feaureWS = null;
            objws    = null;
            objwsf   = null;
            //拷贝字段结构
            IFeatureClass  Dfeatclass   = shpOp.getIFeatureClass();
            ZhFeatureClass Szhfeatclass = new ZhPointFeatureClass(featclass);

            Szhfeatclass.CopyFieldsToObjectFeatureClass(Dfeatclass);

            //拷贝几何对象和属性数据
            ZhFeature      Szhfeat       = null;
            IFeatureBuffer DfeatBuffer   = null;
            IFeatureCursor featCurInsert = Dfeatclass.Insert(true);

            //获取总要素个数
            int             fIndex    = 0;
            int             tmpFCount = Szhfeatclass.FeatureClass.FeatureCount(null);
            frmProgressBar1 pb        = new frmProgressBar1();

            pb.Text                 = "正在输出shp文件...";
            pb.Caption1.Text        = "正在输出shp文件...";
            pb.progressBar1.Maximum = tmpFCount + 1;
            pb.progressBar1.Value   = 0;
            pb.Show(this.ParentForm);
            Application.DoEvents();

            object   refobj = Type.Missing;
            IPolygon s_p    = null;

            IRing[] ExtRingArray   = null;
            IRing[] InnerRingArray = null;


            IFeatureCursor featcur = Szhfeatclass.FeatureClass.Search(null, false);
            IFeature       feat    = featcur.NextFeature();

            while (feat != null)
            {
                fIndex += 1;
                if (fIndex % 200 == 0)
                {
                    pb.Caption1.Text      = "已输出要素个数:" + fIndex.ToString() + "/总" + tmpFCount.ToString();
                    pb.progressBar1.Value = fIndex;
                    Application.DoEvents();
                    featCurInsert.Flush();
                }
                s_p = feat.ShapeCopy as IPolygon;
                //获取外环面几何对象
                ExtRingArray = PolygonHelper.GetExteriorRings(s_p);
                if (ExtRingArray != null && ExtRingArray.Length > 0)
                {
                    foreach (IRing r in ExtRingArray)
                    {
                        if (IsGetExtRingOfHaveInnerRing == true)
                        {
                            InnerRingArray = PolygonHelper.GetInteriorRingsByExterior(r, s_p);
                            if (InnerRingArray != null && InnerRingArray.Length > 0)
                            {   //有内环
                                //外环构面并输出保存
                                DfeatBuffer = Dfeatclass.CreateFeatureBuffer();

                                PolygonClass pclass = new PolygonClass();
                                pclass.AddGeometry(r, ref refobj, ref refobj);
                                pclass.SimplifyPreserveFromTo();
                                pclass.SpatialReference = sr;

                                DfeatBuffer.Shape = pclass;

                                //拷贝属性数据
                                Szhfeat = new ZHFeaturePoint(feat);
                                Szhfeat.CopyField(ref DfeatBuffer);

                                featCurInsert.InsertFeature(DfeatBuffer);
                                //
                            }
                        }
                        else
                        {
                            //外环构面并输出保存
                            DfeatBuffer = Dfeatclass.CreateFeatureBuffer();

                            PolygonClass pclass = new PolygonClass();
                            pclass.AddGeometry(r, ref refobj, ref refobj);
                            pclass.SimplifyPreserveFromTo();
                            pclass.SpatialReference = sr;

                            DfeatBuffer.Shape = pclass;

                            //拷贝属性数据
                            Szhfeat = new ZHFeaturePoint(feat);
                            Szhfeat.CopyField(ref DfeatBuffer);

                            featCurInsert.InsertFeature(DfeatBuffer);
                            //
                        }
                    }
                }
                feat = featcur.NextFeature();
            }
            featCurInsert.Flush();
            TokayWorkspace.ComRelease(featcur);
            featcur = null;
            TokayWorkspace.ComRelease(featCurInsert);
            featCurInsert = null;
            rbc           = true;

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

            return(rbc);
        }
Esempio n. 6
0
        //输出单个图层中所有要素集合到shp文件中功能 OK
        public bool OutPut(IFeatureClass featclass, string outShapeFilePath)
        {
            bool rbc = false;

            if (System.IO.File.Exists(outShapeFilePath) == true)
            {   //输出Shape文件
                LocalShapeFileOperator delshpOp = new LocalShapeFileOperator();
                delshpOp.LocalShapePathFileName = outShapeFilePath;
                delshpOp.DeleteShapeFile();
                delshpOp.Dispose();
            }

            esriGeometryType geoType = featclass.ShapeType;

            //创建新的Shape文件
            LocalShapeFileOperator shpOp = new LocalShapeFileOperator();

            shpOp.LocalShapePathFileName = outShapeFilePath;

            string dir  = shpOp.getDir(outShapeFilePath);
            string name = shpOp.getFileName(outShapeFilePath);
            ShapefileWorkspaceFactoryClass objwsf = new ShapefileWorkspaceFactoryClass();
            IWorkspace        objws    = objwsf.OpenFromFile(dir, 0);
            IFeatureWorkspace feaureWS = objws as IFeatureWorkspace;

            //设置投影
            shpOp.ShapeSpatialReference = (featclass as IGeoDataset).SpatialReference;
            //设置shp文件的oid字段和几何字段
            if (IsObjGeo == false)
            {
                if (featclass.HasOID == true)
                {
                    this.OIDFieldName = featclass.OIDFieldName;
                }
                this.GeometryFieldName = featclass.ShapeFieldName;
            }
            shpOp.OIDFieldName      = this.OIDFieldName;
            shpOp.GeometryFieldName = this.GeometryFieldName;
            //创建要素类
            IFeatureClass fc = shpOp.CreateFeatureClass(feaureWS, name, esriFeatureType.esriFTSimple, geoType);

            if (fc != null)
            {
                TokayWorkspace.ComRelease(fc);
                fc  = null;
                rbc = true;
            }
            TokayWorkspace.ComRelease(objws);
            feaureWS = null;
            objws    = null;
            objwsf   = null;
            //拷贝字段结构
            IFeatureClass  Dfeatclass   = shpOp.getIFeatureClass();
            ZhFeatureClass Szhfeatclass = new ZhPointFeatureClass(featclass);

            Szhfeatclass.CopyFieldsToObjectFeatureClass(Dfeatclass);

            //拷贝几何对象和属性数据
            ZhFeature      Szhfeat       = null;
            IFeatureBuffer DfeatBuffer   = null;
            ZhFeature      Dzhfeat       = null;
            IFeatureCursor featCurInsert = Dfeatclass.Insert(true);

            //获取总要素个数
            int             fIndex    = 0;
            int             tmpFCount = Szhfeatclass.FeatureClass.FeatureCount(null);
            frmProgressBar1 pb        = new frmProgressBar1();

            pb.Text                 = "正在输出shp文件...";
            pb.Caption1.Text        = "正在输出shp文件...";
            pb.progressBar1.Maximum = tmpFCount + 1;
            pb.progressBar1.Value   = 0;
            pb.Show(this.ParentForm);
            Application.DoEvents();
            //
            IGeometry geo = null;
            //
            IFeatureCursor featcur = Szhfeatclass.FeatureClass.Search(null, false);
            IFeature       feat    = featcur.NextFeature();

            while (feat != null)
            {
                fIndex += 1;
                if (fIndex % 500 == 0)
                {
                    pb.Caption1.Text      = "已输出要素个数:" + fIndex.ToString() + "/总" + tmpFCount.ToString();
                    pb.progressBar1.Value = fIndex;
                    Application.DoEvents();
                    featCurInsert.Flush();
                }
                DfeatBuffer = Dfeatclass.CreateFeatureBuffer();

                //拷贝几何对象
                geo = feat.ShapeCopy;
                //去掉Z值
                IZAware pZaware = geo as IZAware;
                if (pZaware.ZAware == true)
                {
                    pZaware.DropZs();
                    pZaware.ZAware = false;
                }
                //
                DfeatBuffer.Shape = geo;
                //
                //拷贝属性数据
                Szhfeat = new ZHFeaturePoint(feat);
                Szhfeat.CopyField(ref DfeatBuffer);

                featCurInsert.InsertFeature(DfeatBuffer);

                feat = featcur.NextFeature();
            }
            featCurInsert.Flush();
            TokayWorkspace.ComRelease(featcur);
            featcur = null;
            TokayWorkspace.ComRelease(featCurInsert);
            featCurInsert = null;
            rbc           = true;

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

            return(rbc);
        }
Esempio n. 7
0
        //输出通过一个图层已选中的要素去选择输出其他图层shp文件功能 OK
        public bool OutPutSelectedFeatureByOverlap(IFeatureLayer SelectedFeatLayer, IFeatureClass outFeatClass, string outShapeFilePath)
        {
            bool rbc = false;

            if (System.IO.File.Exists(outShapeFilePath) == true)
            {   //输出Shape文件
                LocalShapeFileOperator delshpOp = new LocalShapeFileOperator();
                delshpOp.LocalShapePathFileName = outShapeFilePath;
                delshpOp.DeleteShapeFile();
                delshpOp.Dispose();
            }

            esriGeometryType geoType = outFeatClass.ShapeType;

            //创建新的Shape文件
            LocalShapeFileOperator shpOp = new LocalShapeFileOperator();

            shpOp.LocalShapePathFileName = outShapeFilePath;
            shpOp.GeometryType           = geoType;
            //
            string dir  = shpOp.getDir(outShapeFilePath);
            string name = shpOp.getFileName(outShapeFilePath);
            ShapefileWorkspaceFactoryClass objwsf = new ShapefileWorkspaceFactoryClass();
            IWorkspace        objws    = objwsf.OpenFromFile(dir, 0);
            IFeatureWorkspace feaureWS = objws as IFeatureWorkspace;

            //设置投影
            shpOp.ShapeSpatialReference = (outFeatClass as IGeoDataset).SpatialReference;
            //设置shp文件的oid字段和几何字段
            if (IsObjGeo == false)
            {
                if (outFeatClass.HasOID == true)
                {
                    this.OIDFieldName = outFeatClass.OIDFieldName;
                }
                this.GeometryFieldName = outFeatClass.ShapeFieldName;
            }
            shpOp.OIDFieldName      = this.OIDFieldName;
            shpOp.GeometryFieldName = this.GeometryFieldName;
            //创建要素类
            IFeatureClass fc = shpOp.CreateFeatureClass(feaureWS, name, esriFeatureType.esriFTSimple, geoType);

            if (fc != null)
            {
                TokayWorkspace.ComRelease(fc);
                fc  = null;
                rbc = true;
            }
            TokayWorkspace.ComRelease(objws);
            feaureWS = null;
            objws    = null;
            objwsf   = null;
            //拷贝字段结构
            IFeatureClass  Dfeatclass   = shpOp.getIFeatureClass();
            ZhFeatureClass Szhfeatclass = new ZhPointFeatureClass(outFeatClass);

            Szhfeatclass.CopyFieldsToObjectFeatureClass(Dfeatclass);

            //拷贝几何对象和属性数据
            ZhFeature      Szhfeat       = null;
            IFeatureBuffer DfeatBuffer   = null;
            ZhFeature      Dzhfeat       = null;
            IFeatureCursor featCurInsert = Dfeatclass.Insert(true);

            //获取总要素个数
            int             fIndex    = 0;
            int             tmpFCount = Szhfeatclass.FeatureClass.FeatureCount(null);
            frmProgressBar1 pb        = new frmProgressBar1();

            pb.Text                 = "正在输出shp文件...";
            pb.Caption1.Text        = "正在输出shp文件...";
            pb.progressBar1.Maximum = tmpFCount + 1;
            pb.progressBar1.Value   = 0;
            pb.Show(this.ParentForm);
            Application.DoEvents();

            //获取已选择要的要素集合
            IFeatureSelection featSel     = SelectedFeatLayer as IFeatureSelection;
            ICursor           SelectedCur = null;

            featSel.SelectionSet.Search(null, false, out SelectedCur);
            if (SelectedCur != null)
            {
                IFeatureCursor Selectedfeatcur = SelectedCur as IFeatureCursor;// Szhfeatclass.FeatureClass.Search(null, false);
                if (Selectedfeatcur != null)
                {
                    IFeature Selectedfeat = Selectedfeatcur.NextFeature();
                    while (Selectedfeat != null)
                    {
                        ISpatialFilter sFilter = new SpatialFilterClass();
                        sFilter.Geometry      = Selectedfeat.ShapeCopy;
                        sFilter.GeometryField = Szhfeatclass.FeatureClass.ShapeFieldName;
                        sFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects; //相交
                        //总个数
                        pb.progressBar1.Maximum = Szhfeatclass.FeatureClass.FeatureCount(sFilter);
                        pb.progressBar1.Value   = 0;
                        Application.DoEvents();
                        fIndex = 0;
                        //
                        IFeatureCursor featcur = Szhfeatclass.FeatureClass.Search(sFilter, false);
                        IFeature       feat    = featcur.NextFeature();
                        while (feat != null)
                        {
                            fIndex += 1;
                            //
                            pb.Caption1.Text      = "已输出要素个数... 第" + fIndex.ToString() + "个/总" + pb.progressBar1.Maximum.ToString() + "个";
                            pb.progressBar1.Value = fIndex;
                            Application.DoEvents();
                            if (fIndex % 500 == 0)
                            {
                                featCurInsert.Flush();
                            }
                            //
                            DfeatBuffer = Dfeatclass.CreateFeatureBuffer();
                            //拷贝几何对象
                            DfeatBuffer.Shape = feat.ShapeCopy;
                            //拷贝属性数据
                            Szhfeat = new ZHFeaturePoint(feat);
                            Szhfeat.CopyField(ref DfeatBuffer);
                            //
                            featCurInsert.InsertFeature(DfeatBuffer);
                            //下一个要素
                            feat = featcur.NextFeature();
                        }
                        featCurInsert.Flush();
                        if (featcur != null)
                        {
                            TokayWorkspace.ComRelease(featcur);
                            featcur = null;
                        }
                        //下一个选中的要素
                        Selectedfeat = Selectedfeatcur.NextFeature();
                    }
                    if (Selectedfeatcur != null)
                    {
                        TokayWorkspace.ComRelease(Selectedfeatcur);
                        Selectedfeatcur = null;
                    }
                }
                if (featCurInsert != null)
                {
                    TokayWorkspace.ComRelease(featCurInsert);
                    featCurInsert = null;
                }
                rbc = true;
            }
            pb.Close();
            pb.Dispose();
            pb = null;
            //
            return(rbc);
        }
Esempio n. 8
0
        //输出单个图层中已选中的要素集合到shp文件中功能 OK
        public bool OutPutSelectedFeature(IFeatureLayer featLayer, string outShapeFilePath)
        {
            IFeatureClass featclass = featLayer.FeatureClass;

            bool rbc = false;

            if (System.IO.File.Exists(outShapeFilePath) == true)
            {   //输出Shape文件
                LocalShapeFileOperator delshpOp = new LocalShapeFileOperator();
                delshpOp.LocalShapePathFileName = outShapeFilePath;
                delshpOp.DeleteShapeFile();
                delshpOp.Dispose();
            }

            esriGeometryType geoType = featclass.ShapeType;

            //创建新的Shape文件
            LocalShapeFileOperator shpOp = new LocalShapeFileOperator();

            shpOp.LocalShapePathFileName = outShapeFilePath;

            string dir  = shpOp.getDir(outShapeFilePath);
            string name = shpOp.getFileName(outShapeFilePath);
            ShapefileWorkspaceFactoryClass objwsf = new ShapefileWorkspaceFactoryClass();
            IWorkspace        objws    = objwsf.OpenFromFile(dir, 0);
            IFeatureWorkspace feaureWS = objws as IFeatureWorkspace;

            //设置投影
            shpOp.ShapeSpatialReference = (featclass as IGeoDataset).SpatialReference;
            //设置shp文件的oid字段和几何字段
            if (IsObjGeo == false)
            {
                if (featclass.HasOID == true)
                {
                    this.OIDFieldName = featclass.OIDFieldName;
                }
                this.GeometryFieldName = featclass.ShapeFieldName;
            }
            shpOp.OIDFieldName      = this.OIDFieldName;
            shpOp.GeometryFieldName = this.GeometryFieldName;
            //创建要素类
            IFeatureClass fc = shpOp.CreateFeatureClass(feaureWS, name, esriFeatureType.esriFTSimple, geoType);

            if (fc != null)
            {
                TokayWorkspace.ComRelease(fc);
                fc  = null;
                rbc = true;
            }
            TokayWorkspace.ComRelease(objws);
            feaureWS = null;
            objws    = null;
            objwsf   = null;
            //拷贝字段结构
            IFeatureClass  Dfeatclass   = shpOp.getIFeatureClass();
            ZhFeatureClass Szhfeatclass = new ZhPointFeatureClass(featclass);

            Szhfeatclass.CopyFieldsToObjectFeatureClass(Dfeatclass);

            //拷贝几何对象和属性数据
            ZhFeature      Szhfeat       = null;
            IFeatureBuffer DfeatBuffer   = null;
            ZhFeature      Dzhfeat       = null;
            IFeatureCursor featCurInsert = Dfeatclass.Insert(true);

            //获取已选择要的要素集合
            IFeatureSelection featSel = featLayer as IFeatureSelection;
            ICursor           cur     = null;

            featSel.SelectionSet.Search(null, false, out cur);
            if (cur != null)
            {
                IFeatureCursor featcur = cur as IFeatureCursor;// Szhfeatclass.FeatureClass.Search(null, false);
                if (featcur != null)
                {
                    IFeature feat = featcur.NextFeature();
                    while (feat != null)
                    {
                        DfeatBuffer = Dfeatclass.CreateFeatureBuffer();

                        //拷贝几何对象
                        DfeatBuffer.Shape = feat.ShapeCopy;

                        //拷贝属性数据
                        Szhfeat = new ZHFeaturePoint(feat);
                        Szhfeat.CopyField(ref DfeatBuffer);

                        featCurInsert.InsertFeature(DfeatBuffer);

                        feat = featcur.NextFeature();
                    }
                }
                TokayWorkspace.ComRelease(featcur);
                featcur = null;
            }
            featCurInsert.Flush();

            TokayWorkspace.ComRelease(featCurInsert);
            featCurInsert = null;
            rbc           = true;

            return(rbc);
        }
        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;
                }
            }
        }