//快速叠加传值功能 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; } } }