//开始计算
        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, "计算椭球面积完毕!", "提示");
            }
        }
示例#2
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;
            }
        }