Exemple #1
0
        public static IKDProgressBar getInstance(int BarNum)
        {
            IKDProgressBar tppb = null;

            switch (BarNum)
            {
            case 1:
                tppb = new frmProgressBar1();
                break;

            case 2:
                tppb = new frmProgressBar2();
                break;

            case 3:
                tppb = new frmProgressBar3();
                break;

            case 4:
                tppb = new frmProgressBar4();
                break;

            default:
                tppb = new frmProgressBar4();
                break;
            }
            return(tppb);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
        //开始计算
        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, "计算椭球面积完毕!", "提示");
            }
        }
Exemple #6
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;
                }
            }
        }
Exemple #7
0
        //开始计算
        private void Btn_Compute_Click(object sender, EventArgs e)
        {
            try
            {
                this.Btn_Compute.Enabled = false;
                this.Cursor = Cursors.WaitCursor;

                string tpFileName = this.textBox1.Text;
                if (tpFileName == "" || System.IO.File.Exists(tpFileName) == false)
                {
                    MessageBox.Show("需先选择一个shp文件", "提示");
                    return;
                }

                string tpFiledName = this.CB_Fields.Text;

                string[] sArray   = tpFileName.Split('\\');
                string   filename = sArray[sArray.Length - 1];
                string   url      = "";
                for (int i = 0; i < sArray.Length - 1; i++)
                {
                    url = url + sArray[i] + "\\";
                }
                string[] sFile    = filename.Split('.');
                string   file_ext = "";
                if (sFile.Length > 0)
                {
                    file_ext = sFile[sFile.Length - 1];
                }
                file_ext = file_ext.ToLower();
                //----
                ShapefileWorkspaceFactoryClass wsf = new ShapefileWorkspaceFactoryClass();
                IWorkspace ws = wsf.OpenFromFile(url, 0);

                IFeatureWorkspace pFeatureWorkspace;
                pFeatureWorkspace = (IFeatureWorkspace)ws;

                IFeatureClass pFeatureClass = null;
                pFeatureClass = pFeatureWorkspace.OpenFeatureClass(filename);

                decimal ellipseArea = 0;
                AnyTrapeziaEllipseAreaCompute_JF jf = new AnyTrapeziaEllipseAreaCompute_JF();
                jf.Datum = EnumProjectionDatum.Bejing54;
                if (CB_Datum.Checked == true)
                {
                    jf.Datum = EnumProjectionDatum.Xian80;
                }
                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.Caption1.Text        = "正在进行椭球面积计算...";
                pb.progressBar1.Maximum = tmpFCount + 1;
                pb.progressBar1.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.Caption1.Text      = "已计算完成要素个数:" + fIndex.ToString() + "/总" + tmpFCount.ToString();
                        pb.progressBar1.Value = fIndex;
                        Application.DoEvents();
                        fcur.Flush();
                    }
                    ellipseArea = jf.Compute(feat.ShapeCopy);
                    //save ellipseArea...
                    ZhFeature zhfeat = new ZHFeaturePolygon(feat);
                    zhfeat.setFieldValue(tpFiledName, ellipseArea);
                    zhfeat.setFieldValue("TXMJ", zhfeat.GeometryArea);

                    fcur.UpdateFeature(feat);
                    //zhfeat.SaveFeature();

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

                TokayWorkspace.ComRelease(fcur);
                fcur = null;

                TokayWorkspace.ComRelease(ws);
                ws = null;

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

                MessageBox.Show(this, "计算椭球面积完毕!", "提示");
            }
            catch (Exception ee)
            {
                Log.WriteLine(ee);
                MessageBox.Show(this, ee.Message, "提示");
            }
            finally
            {
                this.Btn_Compute.Enabled = true;
                this.Cursor = Cursors.Default;
            }
        }
Exemple #8
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 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;
                }
            }
        }
        //快速叠加传值功能
        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;
                }
            }
        }