ArcGIS Engine开发的ArcGIS 版本管理的功能

时间:2021-11-21 15:43:50

原文:ArcGIS Engine开发的ArcGIS 版本管理的功能

转自:http://blog.csdn.net/linghe301/article/details/7965901

这是以前的ArcGIS Engine开发成果,主要是Geodatabase方面的,模仿ArcGIS版本的流程
系统环境:

VS2010、ArcGIS Engine10、DevExpress721(第三方控件,比较常用易于下载)

------------------------------------------------------------------

我跟大家分享了存在#百度网盘#上的文件,“DXperienceEval-7.2.1.exe”,点击链接进行查看和下载。 http://t.cn/zWsdZRY  (分享自 @百度网盘官方微博)
------------------------------------------------------------------

系统的连接参数都写在代码里面了,如果有问题,跟踪一下代码即可解决

相关功能:

1:打开ArcSDE版本数据

2:切换版本

3:创建新版本

4:查看版本信息

5:协调版本

6:冲突解决

7:提交版本

8:历史归档管理

因为这是很早的东西了,是自己兴趣开发的,会有相关bug,如果有一定基础肯定可以顺利的进行参考!希望能给大家带来帮助!

仅供参考!

下图为系统界面

ArcGIS Engine开发的ArcGIS 版本管理的功能

下图为创建子版本

ArcGIS Engine开发的ArcGIS 版本管理的功能

下图为协调版本

ArcGIS Engine开发的ArcGIS 版本管理的功能

下图为冲突对话框

ArcGIS Engine开发的ArcGIS 版本管理的功能

核心代码冲突对话框

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using DevExpress.XtraEditors;
  10. using ESRI.ArcGIS.Geometry;
  11. using ESRI.ArcGIS.Geodatabase;
  12. using ESRI.ArcGIS.esriSystem;
  13. using ESRI.ArcGIS.Display;
  14. using LSCommonHelper;
  15. using LSGISHelper;
  16. using ESRI.ArcGIS.DataSourcesGDB;
  17. using ESRI.ArcGIS.Controls;
  18. using ESRI.ArcGIS.Carto;
  19. using DevExpress.XtraGrid.Views.Grid;
  20. namespace LSVersion.Version
  21. {
  22. public partial class ConflictsForm : Form
  23. {
  24. public ConflictsForm()
  25. {
  26. InitializeComponent();
  27. }
  28. private IVersion m_peditVersion=null;
  29. public IVersion EditVersion
  30. {
  31. get { return m_peditVersion; }
  32. set { m_peditVersion = value; }
  33. }
  34. private IVersion m_ptargetVersion = null;
  35. public IVersion TargetVersion
  36. {
  37. get { return m_ptargetVersion; }
  38. set { m_ptargetVersion = value; }
  39. }
  40. private void ConflictsForm_Load(object sender, EventArgs e)
  41. {
  42. Init();
  43. }
  44. private IFeatureWorkspace featureWorkspace = null;
  45. private IFeatureWorkspace commonAncestorFWorkspace = null;
  46. private IFeatureWorkspace preReconcileFWorkspace = null;
  47. private IFeatureWorkspace reconcileFWorkspace = null;
  48. private AxMapControl m_pMapControl = null;
  49. public AxMapControl MapControl
  50. {
  51. get { return m_pMapControl; }
  52. set { m_pMapControl = value; }
  53. }
  54. IFeature featurePreReconcile = null;
  55. IFeature featureReconcile = null;
  56. IFeature featureCommonAncestor = null;
  57. private void ClickID(string sLayerName, int sOID, TreeNode sSelNode)
  58. {
  59. IFeatureClass featureClassPreReconcile =
  60. preReconcileFWorkspace.OpenFeatureClass(sLayerName);
  61. IFeatureClass featureClassReconcile =
  62. reconcileFWorkspace.OpenFeatureClass(sLayerName);
  63. IFeatureClass featureClassCommonAncestor =
  64. commonAncestorFWorkspace.OpenFeatureClass(sLayerName);
  65. this.axMapControl1.ClearLayers();
  66. this.axMapControl2.ClearLayers();
  67. this.axMapControl3.ClearLayers();
  68. this.listView1.Items.Clear();
  69. int flag = -1;
  70. if (sSelNode.Parent.Text == "更新-更新冲突")
  71. {
  72. flag = 0;
  73. }
  74. else if (sSelNode.Parent.Text == "删除-更新冲突")
  75. {
  76. flag = 1;
  77. }
  78. else if (sSelNode.Parent.Text == "更新-删除冲突")
  79. {
  80. flag = 2;
  81. }
  82. IFeatureLayer PreReconcileFL = new FeatureLayerClass();
  83. PreReconcileFL.FeatureClass = featureClassPreReconcile;
  84. IFeatureLayer ReconcileFL = new FeatureLayerClass();
  85. ReconcileFL.FeatureClass = featureClassReconcile;
  86. IFeatureLayer CommonAncestorFL = new FeatureLayerClass();
  87. CommonAncestorFL.FeatureClass = featureClassCommonAncestor;
  88. this.axMapControl1.Map.AddLayer(ReconcileFL as ILayer);
  89. this.axMapControl2.Map.AddLayer(PreReconcileFL as ILayer);
  90. this.axMapControl3.Map.AddLayer(CommonAncestorFL as ILayer);
  91. try
  92. {
  93. featurePreReconcile =
  94. featureClassPreReconcile.GetFeature(sOID);
  95. }
  96. catch { this.axMapControl2.ClearLayers(); }
  97. try
  98. {
  99. featureReconcile = featureClassReconcile.GetFeature(sOID);
  100. }
  101. catch { this.axMapControl1.ClearLayers(); }
  102. try
  103. {
  104. featureCommonAncestor =
  105. featureClassCommonAncestor.GetFeature(sOID);
  106. }
  107. catch { this.axMapControl3.ClearLayers(); }
  108. IField pField = null;
  109. if (flag == 0)
  110. {
  111. for (int i = 0; i < featureReconcile.Fields.FieldCount; i++)
  112. {
  113. pField = featureReconcile.Fields.get_Field(i);
  114. ListViewItem lv = new ListViewItem();
  115. lv.SubItems.Add(pField.AliasName);
  116. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
  117. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featurePreReconcile, pField.AliasName));
  118. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
  119. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
  120. this.listView1.Items.Add(lv);
  121. }
  122. }
  123. else if (flag == 1)
  124. {
  125. for (int i = 0; i < featureReconcile.Fields.FieldCount; i++)
  126. {
  127. pField = featureReconcile.Fields.get_Field(i);
  128. ListViewItem lv = new ListViewItem();
  129. lv.SubItems.Add(pField.AliasName);
  130. if (i == 0)
  131. {
  132. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
  133. lv.SubItems.Add("Deleted");
  134. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
  135. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
  136. }
  137. else
  138. {
  139. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
  140. lv.SubItems.Add("");
  141. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
  142. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
  143. }
  144. this.listView1.Items.Add(lv);
  145. }
  146. }
  147. else if (flag == 2)
  148. {
  149. for (int i = 0; i < featurePreReconcile.Fields.FieldCount; i++)
  150. {
  151. pField = featurePreReconcile.Fields.get_Field(i);
  152. ListViewItem lv = new ListViewItem();
  153. lv.SubItems.Add(pField.AliasName);
  154. if (i == 0)
  155. {
  156. lv.SubItems.Add("Deleted");
  157. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featurePreReconcile, pField.AliasName));
  158. lv.SubItems.Add("Deleted");
  159. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
  160. }
  161. else
  162. {
  163. lv.SubItems.Add("");
  164. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featurePreReconcile, pField.AliasName));
  165. lv.SubItems.Add("");
  166. lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
  167. }
  168. this.listView1.Items.Add(lv);
  169. }
  170. }
  171. Flash(this.axMapControl1, featureReconcile);
  172. Flash(this.axMapControl2, featurePreReconcile);
  173. Flash(this.axMapControl3, featureCommonAncestor);
  174. #region//Display
  175. pageCon = this.m_pMapControl.ActiveView.GraphicsContainer;
  176. pageCon.DeleteAllElements();
  177. Display(featureReconcile);
  178. Display(featurePreReconcile);
  179. Display(featureCommonAncestor);
  180. #endregion
  181. }
  182. IGraphicsContainer pageCon = null;
  183. private void Display(IFeature pFea)
  184. {
  185. IFillShapeElement pPEle = new PolygonElementClass();
  186. IFillSymbol pFillSym = new SimpleFillSymbolClass();
  187. RgbColorClass rgbClr = new RgbColorClass();
  188. rgbClr.Transparency = 0;
  189. ILineSymbol pLineSym = new SimpleLineSymbolClass();
  190. pLineSym.Color = LSGISHelper.ColorHelper.CreateRandomColor();
  191. pLineSym.Width = 4;
  192. pFillSym.Color = rgbClr;
  193. pFillSym.Outline = pLineSym;
  194. pPEle.Symbol = pFillSym;
  195. IElement pEle = pPEle as IElement;
  196. pEle.Geometry = pFea.ShapeCopy;
  197. this.m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
  198. pageCon.AddElement(pEle, 0);
  199. }
  200. private void Flash(AxMapControl axMapControl3, IFeature pFea)
  201. {
  202. if (pFea != null)
  203. {
  204. axMapControl3.Extent = pFea.Shape.Envelope;
  205. axMapControl3.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
  206. axMapControl3.FlashShape(pFea.ShapeCopy);
  207. }
  208. }
  209. private void Init()
  210. {
  211. this.myTreeView1.Nodes.Clear();
  212. this.listView1.Items.Clear();
  213. try
  214. {
  215. IWorkspaceEdit workspaceEdit = (IWorkspaceEdit2)m_peditVersion;
  216. IVersionEdit4 versionEdit4 = (IVersionEdit4)workspaceEdit;
  217. featureWorkspace = m_peditVersion as IFeatureWorkspace;
  218. // Get the various versions on which to output information.
  219. commonAncestorFWorkspace = (IFeatureWorkspace)
  220. versionEdit4.CommonAncestorVersion;
  221. preReconcileFWorkspace = (IFeatureWorkspace)
  222. versionEdit4.PreReconcileVersion;
  223. reconcileFWorkspace = (IFeatureWorkspace)
  224. versionEdit4.ReconcileVersion;
  225. IEnumConflictClass enumConflictClass = versionEdit4.ConflictClasses;
  226. TreeNode pRootNode = new TreeNode();
  227. pRootNode.Text = "Conflicts";
  228. this.myTreeView1.Nodes.Add(pRootNode);
  229. IConflictClass conflictClass = null;
  230. while ((conflictClass = enumConflictClass.Next()) != null)
  231. {
  232. IDataset dataset = (IDataset)conflictClass;
  233. // Make sure class is a feature class.
  234. if (dataset.Type == esriDatasetType.esriDTFeatureClass)
  235. {
  236. String datasetName = dataset.Name;
  237. TreeNode pRoot2Node = new TreeNode();
  238. pRoot2Node.Text = datasetName;
  239. this.myTreeView1.Nodes[0].Nodes.Add(pRoot2Node);
  240. IFeatureClass featureClass = featureWorkspace.OpenFeatureClass
  241. (datasetName);
  242. //  Console.WriteLine("Conflicts on feature class {0}", datasetName);
  243. // Get conflict feature classes on the three reconcile versions.
  244. // Get all UpdateUpdate conflicts.
  245. ISelectionSet updateUpdates = conflictClass.UpdateUpdates;
  246. if (updateUpdates.Count > 0)
  247. {
  248. TreeNode pUUNode = new TreeNode();
  249. pUUNode.Text = "更新-更新冲突";
  250. pRoot2Node.Nodes.Add(pUUNode);
  251. #region 更新更新
  252. // Iterate through each OID, outputting information.
  253. IEnumIDs enumIDs = updateUpdates.IDs;
  254. int oid =  enumIDs.Next();
  255. while (oid != -1)
  256. //loop through all conflicting features
  257. {
  258. // Console.WriteLine("UpdateUpdate conflicts on feature {0}", oid);
  259. // Get conflict feature on the three reconcile versions.
  260. TreeNode pOidNode = new TreeNode();
  261. pOidNode.Text ="OID:"+ oid.ToString();
  262. pUUNode.Nodes.Add(pOidNode);
  263. #region---处理
  264. // Check to make sure each shape is different than the common ancestor (conflict is on shape field).
  265. #endregion
  266. oid = enumIDs.Next();
  267. }
  268. #endregion
  269. }
  270. ISelectionSet deleteUpdates = conflictClass.DeleteUpdates;
  271. if (deleteUpdates.Count > 0)
  272. {
  273. TreeNode pDUNode = new TreeNode();
  274. pDUNode.Text = "删除-更新冲突";
  275. pRoot2Node.Nodes.Add(pDUNode);
  276. #region 删除更新
  277. // Iterate through each OID, outputting information.
  278. IEnumIDs enumIDs = deleteUpdates.IDs;
  279. int oid = enumIDs.Next();
  280. while (oid != -1)
  281. //loop through all conflicting features
  282. {
  283. // Console.WriteLine("UpdateUpdate conflicts on feature {0}", oid);
  284. // Get conflict feature on the three reconcile versions.
  285. TreeNode pOidNode = new TreeNode();
  286. pOidNode.Text = "OID:" + oid.ToString();
  287. pDUNode.Nodes.Add(pOidNode);
  288. oid = enumIDs.Next();
  289. }
  290. #endregion
  291. }
  292. ISelectionSet Updatedeletes = conflictClass.UpdateDeletes;
  293. if (Updatedeletes.Count > 0)
  294. {
  295. TreeNode pUDNode = new TreeNode();
  296. pUDNode.Text = "更新-删除冲突";
  297. pRoot2Node.Nodes.Add(pUDNode);
  298. #region 更新删除
  299. // Iterate through each OID, outputting information.
  300. IEnumIDs enumIDs = Updatedeletes.IDs;
  301. int oid = enumIDs.Next();
  302. while (oid != -1)
  303. //loop through all conflicting features
  304. {
  305. TreeNode pOidNode = new TreeNode();
  306. pOidNode.Text = "OID:" + oid.ToString();
  307. pUDNode.Nodes.Add(pOidNode);
  308. oid = enumIDs.Next();
  309. }
  310. #endregion
  311. }
  312. }
  313. }
  314. this.myTreeView1.ExpandAll();
  315. }
  316. catch (System.Runtime.InteropServices.COMException comExc)
  317. {
  318. Console.WriteLine("Error Message: {0}, Error Code: {1}", comExc.Message,
  319. comExc.ErrorCode);
  320. }
  321. }
  322. // Method to determine if shape field is in conflict.
  323. private bool IsShapeInConflict(IFeature commonAncestorFeature, IFeature
  324. preReconcileFeature, IFeature reconcileFeature)
  325. {
  326. // 1st check: Common Ancestor with PreReconcile.
  327. // 2nd check: Common Ancestor with Reconcile.
  328. // 3rd check: Reconcile with PreReconcile (case of same change on both versions)
  329. if (IsGeometryEqual(commonAncestorFeature.ShapeCopy,
  330. preReconcileFeature.ShapeCopy) || IsGeometryEqual
  331. (commonAncestorFeature.ShapeCopy, reconcileFeature.ShapeCopy) ||
  332. IsGeometryEqual(reconcileFeature.ShapeCopy, preReconcileFeature.ShapeCopy)
  333. )
  334. {
  335. return false;
  336. }
  337. else
  338. {
  339. return true;
  340. }
  341. }
  342. // Method returning if two shapes are equal to one another.
  343. private bool IsGeometryEqual(IGeometry shape1, IGeometry shape2)
  344. {
  345. if (shape1 == null & shape2 == null)
  346. {
  347. return true;
  348. }
  349. else if (shape1 == null ^ shape2 == null)
  350. {
  351. return false;
  352. }
  353. else
  354. {
  355. IClone clone1 = (IClone)shape1;
  356. IClone clone2 = (IClone)shape2;
  357. return clone1.IsEqual(clone2);
  358. }
  359. }
  360. private void myTreeView1_MouseDoubleClick(object sender, MouseEventArgs e)
  361. {
  362. if (this.myTreeView1.Nodes.Count > 0)
  363. {
  364. TreeNode sSelNode = this.myTreeView1.SelectedNode;
  365. if (sSelNode != null)
  366. {
  367. string sSel = sSelNode.Text;
  368. if (LSCommonHelper.OtherHelper.GetLeftName(sSel, ":") == "OID")
  369. {
  370. string sLayerName = sSelNode.Parent.Parent.Text;
  371. int sOID = LSCommonHelper.ConvertHelper.ObjectToInt(
  372. LSCommonHelper.OtherHelper.GetRightName(sSel, ":"));
  373. ClickID(sLayerName, sOID, sSelNode);
  374. }
  375. }
  376. }
  377. }
  378. private void ConflictsForm_FormClosing(object sender, FormClosingEventArgs e)
  379. {
  380. pageCon.DeleteAllElements();
  381. }
  382. private void replaceObjectWith(IFeature pfea,
  383. TreeNode pNode )
  384. {
  385. pageCon.DeleteAllElements();
  386. TreeNode sSelNode = this.myTreeView1.SelectedNode;
  387. if (sSelNode != null)
  388. {
  389. string sSel = sSelNode.Text;
  390. if (LSCommonHelper.OtherHelper.GetLeftName(sSel, ":") == "OID")
  391. {
  392. string sLayerName = sSelNode.Parent.Parent.Text;
  393. int sOID = LSCommonHelper.ConvertHelper.ObjectToInt(
  394. LSCommonHelper.OtherHelper.GetRightName(sSel, ":"));
  395. IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(sLayerName);
  396. IFeature feature = featureClass.GetFeature(sOID);
  397. feature.Shape = pfea.ShapeCopy;
  398. feature.Store();
  399. m_pMapControl.ActiveView.Refresh();
  400. }
  401. }
  402. }
  403. private TreeNode sSelNode = null;
  404. private void myTreeView1_MouseDown(object sender, MouseEventArgs e)
  405. {
  406. sSelNode = this.myTreeView1.GetNodeAt(e.X, e.Y);
  407. if (sSelNode == null) return;
  408. if (e.Button == MouseButtons.Left)
  409. {//左键
  410. }
  411. else
  412. {
  413. System.Drawing.Point aPt = new System.Drawing.Point(e.X, e.Y);
  414. //   TreeNode sSelNode = this.myTreeView1.SelectedNode;
  415. if (sSelNode != null)
  416. {
  417. string sSel = sSelNode.Text;
  418. if (LSCommonHelper.OtherHelper.GetLeftName(sSel, ":") == "OID")
  419. {
  420. this.contextMenuStrip1.Show(this.myTreeView1, aPt);
  421. }
  422. }
  423. }
  424. }
  425. private void replaceObjectWithCommonAncestorVersionToolStripMenuItem_Click(object sender, EventArgs e)
  426. {
  427. replaceObjectWith(featureCommonAncestor,  sSelNode);
  428. }
  429. private void replaceObjectWithPreReconcileVersionToolStripMenuItem_Click(object sender, EventArgs e)
  430. {
  431. replaceObjectWith(featurePreReconcile, sSelNode);
  432. }
  433. private void replaceObjectWithConflictsVersionToolStripMenuItem_Click(object sender, EventArgs e)
  434. {
  435. replaceObjectWith(featureReconcile, sSelNode);
  436. }
  437. private void mergeGeometryToolStripMenuItem_Click(object sender, EventArgs e)
  438. {
  439. MergeGeometry(featureCommonAncestor, featurePreReconcile, featureReconcile, sSelNode);
  440. }
  441. private void MergeGeometry(IFeature featureCommonAncestor
  442. , IFeature featurePreReconcile, IFeature featureReconcile,TreeNode pNode)
  443. {
  444. pageCon.DeleteAllElements();
  445. TreeNode sSelNode = this.myTreeView1.SelectedNode;
  446. if (sSelNode != null)
  447. {
  448. string sSel = sSelNode.Text;
  449. if (LSCommonHelper.OtherHelper.GetLeftName(sSel, ":") == "OID")
  450. {
  451. string sLayerName = sSelNode.Parent.Parent.Text;
  452. int sOID = LSCommonHelper.ConvertHelper.ObjectToInt(
  453. LSCommonHelper.OtherHelper.GetRightName(sSel, ":"));
  454. IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(sLayerName);
  455. // Check to make sure each shape is different than the common ancestor (conflict is on shape field).
  456. if (IsShapeInConflict(featureCommonAncestor,
  457. featurePreReconcile, featureReconcile))
  458. {
  459. //Console.WriteLine(
  460. //    " Shape attribute has changed on both versions...");
  461. // Geometries are in conflict ... merge geometries.
  462. try
  463. {
  464. IConstructMerge constructMerge = new
  465. GeometryEnvironmentClass();
  466. IGeometry newGeometry =
  467. constructMerge.MergeGeometries
  468. (featureCommonAncestor.ShapeCopy,
  469. featureReconcile.ShapeCopy,
  470. featurePreReconcile.ShapeCopy);
  471. // Setting new geometry as a merge between the two versions.
  472. IFeature feature = featureClass.GetFeature(sOID);
  473. feature.Shape = newGeometry;
  474. feature.Store();
  475. //updateUpdates.RemoveList(1, ref oid);
  476. //conflictsRemoved = true;
  477. }
  478. catch (System.Runtime.InteropServices.COMException comExc)
  479. {
  480. // Check if the error is from overlapping edits.
  481. if (comExc.ErrorCode == (int)
  482. fdoError.FDO_E_WORKSPACE_EXTENSION_DATASET_CREATE_FAILED || comExc.ErrorCode == (int)fdoError.FDO_E_WORKSPACE_EXTENSION_DATASET_DELETE_FAILED)
  483. {
  484. // Edited areas overlap.
  485. LSCommonHelper.MessageBoxHelper.ShowMessageBox(
  486. "Error from overlapping edits on feature {0}"+
  487. " Can't merge overlapping edits to same feature.");
  488. }
  489. else
  490. {
  491. // Unexpected COM exception, throw this to the exception handler.
  492. throw comExc;
  493. }
  494. }
  495. }
  496. }
  497. }
  498. }
  499. }
  500. }

相关代码下载地址,下载完毕后,请使用kuaiya解压即可,WINRAR不行