您的位置:首页 > 文旅 > 旅游 > ArcGIS Pro SDK (八)地理数据库 6 版本控制

ArcGIS Pro SDK (八)地理数据库 6 版本控制

2025/3/14 4:59:35 来源:https://blog.csdn.net/szy13323042191/article/details/140348150  浏览:    关键词:ArcGIS Pro SDK (八)地理数据库 6 版本控制

ArcGIS Pro SDK (八)地理数据库 6 版本控制

文章目录

  • ArcGIS Pro SDK (八)地理数据库 6 版本控制
    • 1 连接到版本
    • 2 在单独的编辑会话中协调版本并将其与其父级进行核对和提交
    • 3 在同一编辑会话中协调版本并将其与其父级提交
    • 4 使用版本
    • 5 使用默认版本
    • 6 创建版本
    • 7 创建历史版本
    • 8 在版本之间切换
    • 9 部分过账

环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0

1 连接到版本

public Geodatabase ConnectToVersion(Geodatabase geodatabase, string versionName)
{Geodatabase connectedVersion = null;if (geodatabase.IsVersioningSupported()){using (VersionManager versionManager = geodatabase.GetVersionManager())using (Version version = versionManager.GetVersion(versionName)){connectedVersion = version.Connect();}}return connectedVersion;
}

2 在单独的编辑会话中协调版本并将其与其父级进行核对和提交

public void ReconcileAndPost(Geodatabase geodatabase)
{// 获取当前版本及其父版本的引用if (geodatabase.IsVersioningSupported()){using (VersionManager versionManager = geodatabase.GetVersionManager())using (Version currentVersion = versionManager.GetCurrentVersion())using (Version parentVersion = currentVersion.GetParent()){// 创建 ReconcileOptions 对象var reconcileOptions = new ReconcileOptions(parentVersion){ConflictResolutionMethod = ConflictResolutionMethod.Continue, // 发现冲突时继续ConflictDetectionType = ConflictDetectionType.ByRow, // 默认值ConflictResolutionType = ConflictResolutionType.FavorTargetVersion // 或者 FavorEditVersion};// 执行协调ReconcileResult reconcileResult = currentVersion.Reconcile(reconcileOptions);if (!reconcileResult.HasConflicts){// 无冲突,执行过账var postOptions = new PostOptions(parentVersion){ServiceSynchronizationType = ServiceSynchronizationType.Synchronous // 默认值};currentVersion.Post(postOptions);}}}
}

3 在同一编辑会话中协调版本并将其与其父级提交

public void ReconcileAndPost2(Geodatabase geodatabase)
{// 获取当前版本及其父版本的引用if (geodatabase.IsVersioningSupported()){using (VersionManager versionManager = geodatabase.GetVersionManager())using (Version currentVersion = versionManager.GetCurrentVersion())using (Version parentVersion = currentVersion.GetParent()){// 创建 ReconcileOptions 对象var reconcileOptions = new ReconcileOptions(parentVersion){ConflictResolutionMethod = ConflictResolutionMethod.Continue, // 发现冲突时继续ConflictDetectionType = ConflictDetectionType.ByRow, // 默认值ConflictResolutionType = ConflictResolutionType.FavorTargetVersion // 或者 FavorEditVersion};// 创建 PostOptions 对象var postOptions = new PostOptions(parentVersion){ServiceSynchronizationType = ServiceSynchronizationType.Synchronous // 默认值};// 执行协调和过账ReconcileResult reconcileResult = currentVersion.Reconcile(reconcileOptions, postOptions);if (reconcileResult.HasConflicts){// 处理冲突// TODO 解决冲突}}}
}

4 使用版本

public async Task WorkingWithVersions()
{await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>{using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))using (VersionManager versionManager = geodatabase.GetVersionManager()){IReadOnlyList<Version> versionList = versionManager.GetVersions();// 默认版本的父版本为 nullVersion defaultVersion = versionList.First(version => version.GetParent() == null);IEnumerable<Version> publicVersions = versionList.Where(version => version.GetAccessType() == VersionAccessType.Public);Version qaVersion = defaultVersion.GetChildren().First(version => version.GetName().Contains("QA"));Geodatabase qaVersionGeodatabase = qaVersion.Connect();FeatureClass currentFeatureClass = geodatabase.OpenDataset<FeatureClass>("featureClassName");FeatureClass qaFeatureClass = qaVersionGeodatabase.OpenDataset<FeatureClass>("featureClassName");}});
}

5 使用默认版本

// 检查当前版本是否为默认版本
// 适用于分支和传统版本管理
public bool IsDefaultVersion(Version version)
{Version parentVersion = version.GetParent();if (parentVersion == null){return true;}parentVersion.Dispose();return false;
}public bool IsDefaultVersion(Geodatabase geodatabase)
{if (!geodatabase.IsVersioningSupported()) return false;using (VersionManager versionManager = geodatabase.GetVersionManager())using (Version currentVersion = versionManager.GetCurrentVersion()){return IsDefaultVersion(currentVersion);}
}// 获取默认版本
// 适用于分支和传统版本管理
// 此方法依赖于 IsDefaultVersion() 方法
public Version GetDefaultVersion(Version version)
{if (IsDefaultVersion(version)){return version;}else{Version parent = version.GetParent();Version ancestor = GetDefaultVersion(parent);if (parent != ancestor){parent.Dispose(); // 如果版本树超过两层深,释放中间版本对象}return ancestor;}
}public Version GetDefaultVersion(Geodatabase geodatabase)
{if (!geodatabase.IsVersioningSupported()) return null;using (VersionManager versionManager = geodatabase.GetVersionManager()){Version currentVersion = versionManager.GetCurrentVersion();Version defaultVersion = GetDefaultVersion(currentVersion);if (currentVersion != defaultVersion){currentVersion.Dispose(); // 如果当前版本不是默认版本,释放当前版本对象}return defaultVersion;}
}

6 创建版本

public Version CreateVersion(Geodatabase geodatabase, string versionName, string description, VersionAccessType versionAccessType)
{if (!geodatabase.IsVersioningSupported()) return null;using (VersionManager versionManager = geodatabase.GetVersionManager()){VersionDescription versionDescription = new VersionDescription(versionName, description, versionAccessType);return versionManager.CreateVersion(versionDescription);}
}

7 创建历史版本

public HistoricalVersion CreateHistoricalVersion(Geodatabase geodatabase, string versionName)
{using (VersionManager versionManager = geodatabase.GetVersionManager()){HistoricalVersionDescription historicalVersionDescription = new HistoricalVersionDescription(versionName, DateTime.Now);HistoricalVersion historicalVersion = versionManager.CreateHistoricalVersion(historicalVersionDescription);return historicalVersion;}
}

8 在版本之间切换

public void ChangeVersions(Geodatabase geodatabase, string toVersionName)
{using (VersionManager versionManager = geodatabase.GetVersionManager()){VersionBaseType versionBaseType = versionManager.GetCurrentVersionBaseType();if (versionBaseType == VersionBaseType.Version){Version fromVersion = versionManager.GetCurrentVersion();Version toVersion = versionManager.GetVersion(toVersionName);// 在版本之间切换MapView.Active.Map.ChangeVersion(fromVersion, toVersion);}if (versionBaseType == VersionBaseType.HistoricalVersion){HistoricalVersion fromHistoricalVersion = versionManager.GetCurrentHistoricalVersion();HistoricalVersion toHistoricalVersion = versionManager.GetHistoricalVersion(toVersionName);// 在历史版本之间切换MapView.Active.Map.ChangeVersion(fromHistoricalVersion, toHistoricalVersion);}// 从历史版本切换到版本,反之亦然// MapView.Active.Map.ChangeVersion(fromHistoricalVersion, toVersion);// MapView.Active.Map.ChangeVersion(fromVersion, toHistoricalVersion);}
}

9 部分过账

// 部分过账允许开发人员提交版本中的部分更改。
// 一个示例用例是电力公用事业公司使用版本来设计新的住宅细分区的设施。
// 在流程的某个阶段,一个街区的新房屋已经建成,而细分区的其余部分尚未建造。
// 部分过账允许用户提交已完成的工作,同时保留版本中尚未建成的要素,以便以后提交。
// 部分过账需要使用 ArcGIS Enterprise 10.9 及更高版本的分支版本化要素服务。// 指定已构建的要素集合
QueryFilter constructedFilter = new QueryFilter()
{WhereClause = "ConstructedStatus = 'True'"
};// 此选择表示我们希望提交到支持结构要素类的插入和更新
using (Selection constructedSupportStructures = supportStructureFeatureClass.Select(constructedFilter, SelectionType.ObjectID, SelectionOption.Normal))
{// 指定要提交的删除要素稍微复杂,因为无法发出查询来获取已删除要素的集合,必须使用 ObjectIDs 的列表。using (Selection deletedSupportStructures = supportStructureFeatureClass.Select(null, SelectionType.ObjectID, SelectionOption.Empty)){deletedSupportStructures.Add(deletedSupportStructureObjectIDs);  // deletedSupportStructureObjectIDs 定义为 List<long>// 执行带有部分过账的协调// 在 2.x 版本中 -// ReconcileDescription reconcileDescription = new ReconcileDescription();// reconcileDescription.ConflictDetectionType = ConflictDetectionType.ByColumn;// reconcileDescription.ConflictResolutionMethod = ConflictResolutionMethod.Continue;// reconcileDescription.ConflictResolutionType = ConflictResolutionType.FavorEditVersion;// reconcileDescription.PartialPostSelections = new List<Selection>() { constructedSupportStructures, deletedSupportStructures };// reconcileDescription.WithPost = true;// ReconcileResult reconcileResult = designVersion.Reconcile(reconcileDescription);var reconcileOptions = new ReconcileOptions();  // 协调选项,针对默认版本reconcileOptions.ConflictDetectionType = ConflictDetectionType.ByColumn;reconcileOptions.ConflictResolutionMethod = ConflictResolutionMethod.Continue;reconcileOptions.ConflictResolutionType = ConflictResolutionType.FavorEditVersion;var postOptions = new PostOptions();  // 提交选项,针对默认版本postOptions.PartialPostSelections = new List<Selection>() { constructedSupportStructures, deletedSupportStructures };postOptions.ServiceSynchronizationType = ServiceSynchronizationType.Synchronous;var reconcileResult = designVersion.Reconcile(reconcileOptions, postOptions);// 处理结果// TODO 处理结果的逻辑}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com