public bool Execute(IFeatureClass fc1, IFeatureClass fc2, string outputMdbPath, string output_type, object cluster_tolerance) { bool rbc = false; MapClass map = new MapClass(); IFeatureLayer fL1 = AddFeatureClassToMap(map, fc1); IFeatureLayer fL2 = AddFeatureClassToMap(map, fc2); string pLayerName1 = fL1.Name; string pLayerName2 = fL2.Name; //[pLayerName1]与[pLayerName2]相交分析 生成 mdb file //GPUtilitiesClass gpUtil = new GPUtilitiesClass(); //gpUtil.SetInternalMap(map); //object in_features = pLayerName1 + " #;" + pLayerName2 + " #"; //string output_type = "LINE"; //string join_attributes = "ALL"; // "0.0001 Meters"; // Meters IntersectCalculateMdbEx interclass = new IntersectCalculateMdbEx(); bool ret = interclass.Execute(pLayerName1, pLayerName2, outputMdbPath, output_type, cluster_tolerance, map); //IntersectClass cls = new IntersectClass(); //cls.SetValue(in_features, outputMdbPath, output_type, join_attributes, cluster_tolerance); if (ret == true) { //执行成功 rbc = true; } else { rbc = false; } this.Message = interclass.Message; return(rbc); }
private void Btn_PreHandle_Click(object sender, EventArgs e) { //完成导出为mdb空间库中 try { //this.Btn_PreHandle.Enabled = false; this.Cursor = Cursors.WaitCursor; #region //两个图层作叠加相交运算输出到一个mdb空间数据库中 string fcName1 = ""; string fcName2 = ""; IFeatureClass fc1 = null; IFeatureClass fc2 = null; object obj = this.CB_LayerList1.SelectedItem; if (obj != null && obj is CommonComboBoxItem) { CommonComboBoxItem item = obj as CommonComboBoxItem; fc1 = item.Tag as IFeatureClass; fcName1 = (fc1 as IDataset).Name; } obj = this.CB_LayerList2.SelectedItem; if (obj != null && obj is CommonComboBoxItem) { CommonComboBoxItem item = obj as CommonComboBoxItem; fc2 = item.Tag as IFeatureClass; fcName2 = (fc2 as IDataset).Name; } tmpLayerName = fcName1 + "_" + fcName2; double TopoTolerance = 0.0001; IntersectCalculateMdbEx mdbIsCal = new IntersectCalculateMdbEx(); if (mdbIsCal.Execute(fc1, fc2, this.tmpMdbFilePath + "\\" + tmpLayerName, "INPUT", TopoTolerance) == true) { gdbUtil sic = new gdbUtil(); sic.enumSDEServer = EnumSDEServer.Access; sic.SDE_DataBase = this.tmpMdbFilePath; sic.OpenSDEConnection(); IFeatureClass mdbFc = sic.getFeatureClass(tmpLayerName); if (mdbFc != null) { this.GetFields(mdbFc); } TokayWorkspace.ComRelease(mdbFc); mdbFc = null; sic.Dispose(); sic = null; } #endregion } catch (Exception ee) { MessageBox.Show(ee.Message, "提示"); } finally { //this.Btn_PreHandle.Enabled = true; this.Cursor = Cursors.Default; } }
//快速叠加传值功能 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; } } }