ArcGIS Pro SDK (八)地理数据库 8 拓扑

ArcGIS Pro SDK (八)地理数据库 8 拓扑

文章目录

  • ArcGIS Pro SDK (八)地理数据库 8 拓扑
    • 1 开放拓扑和进程定义
    • 2 获取拓扑规则
    • 3 验证拓扑
    • 4 获取拓扑错误
    • 5 标记和不标记为错误
    • 6 探索拓扑图
    • 7 找到最近的元素

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

1 开放拓扑和进程定义

public void OpenTopologyAndProcessDefinition()
{// 从文件地理数据库中打开拓扑并处理拓扑定义。using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))using (Topology topology = geodatabase.OpenDataset<Topology>("Backcountry_Topology")){ProcessDefinition(geodatabase, topology);}// 打开要素服务拓扑并处理拓扑定义。const string TOPOLOGY_LAYER_ID = "0";using (Geodatabase geodatabase = new Geodatabase(new ServiceConnectionProperties(new Uri("https://sdkexamples.esri.com/server/rest/services/GrandTeton/FeatureServer"))))using (Topology topology = geodatabase.OpenDataset<Topology>(TOPOLOGY_LAYER_ID)){ProcessDefinition(geodatabase, topology);}
}private void ProcessDefinition(Geodatabase geodatabase, Topology topology)
{// 类似于Core.Data API中其余Definition对象,打开数据集的定义有两种方式 -- 通过拓扑数据集本身或通过地理数据库。using (TopologyDefinition definitionViaTopology = topology.GetDefinition()){OutputDefinition(geodatabase, definitionViaTopology);}using (TopologyDefinition definitionViaGeodatabase = geodatabase.GetDefinition<TopologyDefinition>("Backcountry_Topology")){OutputDefinition(geodatabase, definitionViaGeodatabase);}
}private void OutputDefinition(Geodatabase geodatabase, TopologyDefinition topologyDefinition)
{Console.WriteLine($"拓扑聚类容差 => {topologyDefinition.GetClusterTolerance()}");Console.WriteLine($"拓扑Z值聚类容差 => {topologyDefinition.GetZClusterTolerance()}");IReadOnlyList<string> featureClassNames = topologyDefinition.GetFeatureClassNames();Console.WriteLine($"有 {featureClassNames.Count} 个要素类参与了拓扑:");foreach (string name in featureClassNames){// 打开每个参与拓扑的要素类。using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>(name))using (FeatureClassDefinition featureClassDefinition = featureClass.GetDefinition()){Console.WriteLine($"\t{featureClass.GetName()} ({featureClassDefinition.GetShapeType()})");}}
}

2 获取拓扑规则

using (TopologyDefinition topologyDefinition = topology.GetDefinition())
{IReadOnlyList<TopologyRule> rules = topologyDefinition.GetRules();Console.WriteLine($"拓扑定义了 {rules.Count} 条拓扑规则:");Console.WriteLine("ID \t 源类 \t 源子类 \t 目标类 \t 目标子类 \t 规则类型");foreach (TopologyRule rule in rules){Console.Write($"{rule.ID}");Console.Write(!String.IsNullOrEmpty(rule.OriginClass) ? $"\t{rule.OriginClass}" : "\t\"\"");Console.Write(rule.OriginSubtype != null ? $"\t{rule.OriginSubtype.GetName()}" : "\t\"\"");Console.Write(!String.IsNullOrEmpty(rule.DestinationClass) ? $"\t{rule.DestinationClass}" : "\t\"\"");Console.Write(rule.DestinationSubtype != null ? $"\t{rule.DestinationSubtype.GetName()}" : "\t\"\"");Console.Write($"\t{rule.RuleType}");Console.WriteLine();}
}

3 验证拓扑

public void ValidateTopology()
{using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))using (Topology topology = geodatabase.OpenDataset<Topology>("Backcountry_Topology")){// 如果拓扑当前没有脏区域,调用Validate()将返回一个空的包络线。ValidationResult result = topology.Validate(new ValidationDescription(topology.GetExtent()));Console.WriteLine($"在未编辑的拓扑上验证后的'受影响区域' => {result.AffectedArea.ToJson()}");// 现在创建一个故意违反“PointProperlyInsideArea”拓扑规则的要素。这个动作将创建脏区域。Feature newFeature = null;try{// 获取Campsite要素类中ObjectID为2的要素。然后从这个要素稍微修改后创建一个新的几何体,并用它创建一个新的要素。using (Feature featureViaCampsites2 = GetFeature(geodatabase, "Campsites", 2)){Geometry currentGeometry = featureViaCampsites2.GetShape();Geometry newGeometry = GeometryEngine.Instance.Move(currentGeometry, (currentGeometry.Extent.XMax / 8),(currentGeometry.Extent.YMax / 8));using (FeatureClass campsitesFeatureClass = featureViaCampsites2.GetTable())using (FeatureClassDefinition definition = campsitesFeatureClass.GetDefinition())using (RowBuffer rowBuffer = campsitesFeatureClass.CreateRowBuffer()){rowBuffer[definition.GetShapeField()] = newGeometry;geodatabase.ApplyEdits(() =>{newFeature = campsitesFeatureClass.CreateRow(rowBuffer);});}}// 在'Campsites'参与要素类中创建新要素后,拓扑的状态应为“未分析”,因为尚未验证。Console.WriteLine($"应用编辑后拓扑状态 => {topology.GetState()}");// 现在验证拓扑。结果包络线对应于脏区域。result = topology.Validate(new ValidationDescription(topology.GetExtent()));Console.WriteLine($"在刚编辑后验证的拓扑上的'受影响区域' => {result.AffectedArea.ToJson()}");// 在Validate()之后,拓扑的状态应为“有错误的分析”,因为拓扑当前存在错误。Console.WriteLine($"验证拓扑后的拓扑状态 => {topology.GetState()}");// 如果没有脏区域,则结果包络线应为空。result = topology.Validate(new ValidationDescription(topology.GetExtent()));Console.WriteLine($"在刚验证过的拓扑上的'受影响区域' => {result.AffectedArea.ToJson()}");}finally{if (newFeature != null){geodatabase.ApplyEdits(() =>{newFeature.Delete();});newFeature.Dispose();}}// 删除新创建的要素后再次验证。topology.Validate(new ValidationDescription(topology.GetExtent()));}
}private Feature GetFeature(Geodatabase geodatabase, string featureClassName, long objectID)
{using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>(featureClassName)){QueryFilter queryFilter = new QueryFilter(){ObjectIDs = new List<long>() { objectID }};using (RowCursor cursor = featureClass.Search(queryFilter)){System.Diagnostics.Debug.Assert(cursor.MoveNext());return (Feature)cursor.Current;}}
}

4 获取拓扑错误

// 获取当前与拓扑相关的所有错误和异常。IReadOnlyList<TopologyError> allErrorsAndExceptions = topology.GetErrors(new ErrorDescription(topology.GetExtent()));
Console.WriteLine($"错误和异常数目 => {allErrorsAndExceptions.Count}");Console.WriteLine("源类名称 \t 源对象ID \t 目标类名称 \t 目标对象ID \t 规则类型 \t 是否异常 \t 几何类型 \t 几何宽度 & 高度 \t 规则ID \t");foreach (TopologyError error in allErrorsAndExceptions)
{Console.WriteLine($"'{error.OriginClassName}' \t {error.OriginObjectID} \t '{error.DestinationClassName}' \t " +$"{error.DestinationObjectID} \t {error.RuleType} \t {error.IsException} \t {error.Shape.GeometryType} \t " +$"{error.Shape.Extent.Width},{error.Shape.Extent.Height} \t {error.RuleID}");
}

5 标记和不标记为错误

// 获取所有由于违反“PointProperlyInsideArea”拓扑规则而引起的错误。using (TopologyDefinition topologyDefinition = topology.GetDefinition())
{TopologyRule pointProperlyInsideAreaRule = topologyDefinition.GetRules().First(rule => rule.RuleType == TopologyRuleType.PointProperlyInsideArea);ErrorDescription errorDescription = new ErrorDescription(topology.GetExtent()){TopologyRule = pointProperlyInsideAreaRule};IReadOnlyList<TopologyError> errorsDueToViolatingPointProperlyInsideAreaRule = topology.GetErrors(errorDescription);Console.WriteLine($"有 {errorsDueToViolatingPointProperlyInsideAreaRule.Count} 个要素违反了'PointProperlyInsideArea'拓扑规则.");// 将违反“PointProperlyInsideArea”拓扑规则的所有错误标记为异常。foreach (TopologyError error in errorsDueToViolatingPointProperlyInsideAreaRule){topology.MarkAsException(error);}// 现在验证所有违反“PointProperlyInsideArea”拓扑规则的错误是否确实已标记为异常。//// 默认情况下,ErrorDescription初始化为ErrorType.ErrorAndException。在这里我们想要ErrorType.ErrorOnly。errorDescription = new ErrorDescription(topology.GetExtent()){ErrorType = ErrorType.ErrorOnly,TopologyRule = pointProperlyInsideAreaRule};IReadOnlyList<TopologyError> errorsAfterMarkedAsExceptions = topology.GetErrors(errorDescription);Console.WriteLine($"在将所有错误标记为异常后,有 {errorsAfterMarkedAsExceptions.Count} 个要素违反了'PointProperlyInsideArea'拓扑规则.");// 最后,通过取消标记为异常将所有异常重置为错误。foreach (TopologyError error in errorsDueToViolatingPointProperlyInsideAreaRule){topology.UnmarkAsException(error);}IReadOnlyList<TopologyError> errorsAfterUnmarkedAsExceptions = topology.GetErrors(errorDescription);Console.WriteLine($"在将所有异常重置为错误后,有 {errorsAfterUnmarkedAsExceptions.Count} 个要素违反了'PointProperlyInsideArea'拓扑规则.");
}

6 探索拓扑图

public void ExploreTopologyGraph()
{using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))using (Topology topology = geodatabase.OpenDataset<Topology>("Backcountry_Topology")){// 使用拓扑数据集的范围构建拓扑图。topology.BuildGraph(topology.GetExtent(),(topologyGraph) =>{using (Feature campsites12 = GetFeature(geodatabase, "Campsites", 12)){IReadOnlyList<TopologyNode> topologyNodesViaCampsites12 = topologyGraph.GetNodes(campsites12);TopologyNode topologyNodeViaCampsites12 = topologyNodesViaCampsites12[0];IReadOnlyList<TopologyEdge> allEdgesConnectedToNodeViaCampsites12 = topologyNodeViaCampsites12.GetEdges();IReadOnlyList<TopologyEdge> allEdgesConnectedToNodeViaCampsites12CounterClockwise = topologyNodeViaCampsites12.GetEdges(false);System.Diagnostics.Debug.Assert(allEdgesConnectedToNodeViaCampsites12.Count == allEdgesConnectedToNodeViaCampsites12CounterClockwise.Count);foreach (TopologyEdge edgeConnectedToNodeViaCampsites12 in allEdgesConnectedToNodeViaCampsites12){TopologyNode fromNode = edgeConnectedToNodeViaCampsites12.GetFromNode();TopologyNode toNode = edgeConnectedToNodeViaCampsites12.GetToNode();bool fromNodeIsTheSameAsTopologyNodeViaCampsites12 = (fromNode == topologyNodeViaCampsites12);bool toNodeIsTheSameAsTopologyNodeViaCampsites12 = (toNode == topologyNodeViaCampsites12);System.Diagnostics.Debug.Assert(fromNodeIsTheSameAsTopologyNodeViaCampsites12 || toNodeIsTheSameAsTopologyNodeViaCampsites12,"连接到'topologyNodeViaCampsites12'的每个边的FromNode或ToNode应与'topologyNodeViaCampsites12'本身相同。");IReadOnlyList<FeatureInfo> leftParentFeaturesBoundedByEdge = edgeConnectedToNodeViaCampsites12.GetLeftParentFeatures();foreach (FeatureInfo featureInfo in leftParentFeaturesBoundedByEdge){System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(featureInfo.FeatureClassName));System.Diagnostics.Debug.Assert(featureInfo.ObjectID > 0);EnsureShapeIsNotEmpty(featureInfo);}IReadOnlyList<FeatureInfo> leftParentFeaturesNotBoundedByEdge = edgeConnectedToNodeViaCampsites12.GetLeftParentFeatures(false);foreach (FeatureInfo featureInfo in leftParentFeaturesNotBoundedByEdge){System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(featureInfo.FeatureClassName));System.Diagnostics.Debug.Assert(featureInfo.ObjectID > 0);EnsureShapeIsNotEmpty(featureInfo);}IReadOnlyList<FeatureInfo> rightParentFeaturesBoundedByEdge = edgeConnectedToNodeViaCampsites12.GetRightParentFeatures();foreach (FeatureInfo featureInfo in rightParentFeaturesBoundedByEdge){System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(featureInfo.FeatureClassName));System.Diagnostics.Debug.Assert(featureInfo.ObjectID > 0);EnsureShapeIsNotEmpty(featureInfo);}IReadOnlyList<FeatureInfo> rightParentFeaturesNotBoundedByEdge = edgeConnectedToNodeViaCampsites12.GetRightParentFeatures(false);foreach (FeatureInfo featureInfo in rightParentFeaturesNotBoundedByEdge){System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(featureInfo.FeatureClassName));System.Diagnostics.Debug.Assert(featureInfo.ObjectID > 0);EnsureShapeIsNotEmpty(featureInfo);}}}});}
}private void EnsureShapeIsNotEmpty(FeatureInfo featureInfo)
{using (Feature feature = featureInfo.GetFeature()){System.Diagnostics.Debug.Assert(!feature.GetShape().IsEmpty, "要素的形状不应为空。");}
}

7 找到最近的元素

public void FindClosestElement()
{using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))using (Topology topology = geodatabase.OpenDataset<Topology>("Backcountry_Topology")){// 使用拓扑数据集的范围构建拓扑图。topology.BuildGraph(topology.GetExtent(), (topologyGraph) =>{MapPoint queryPointViaCampsites12 = null;using (Feature campsites12 = GetFeature(geodatabase, "Campsites", 12)){queryPointViaCampsites12 = campsites12.GetShape() as MapPoint;}double searchRadius = 1.0;TopologyElement topologyElementViaCampsites12 = topologyGraph.FindClosestElement<TopologyElement>(queryPointViaCampsites12, searchRadius);System.Diagnostics.Debug.Assert(topologyElementViaCampsites12 != null, "在searchRadius范围内应该有一个与'queryPointViaCampsites12'对应的拓扑元素.");IReadOnlyList<FeatureInfo> parentFeatures = topologyElementViaCampsites12.GetParentFeatures();Console.WriteLine("生成'topologyElementViaCampsites12'的父要素:");foreach (FeatureInfo parentFeature in parentFeatures){Console.WriteLine($"\t{parentFeature.FeatureClassName}; OID: {parentFeature.ObjectID}");}TopologyNode topologyNodeViaCampsites12 = topologyGraph.FindClosestElement<TopologyNode>(queryPointViaCampsites12, searchRadius);if (topologyNodeViaCampsites12 != null){// 在searchRadius单位内存在一个最近的TopologyNode。}TopologyEdge topologyEdgeViaCampsites12 = topologyGraph.FindClosestElement<TopologyEdge>(queryPointViaCampsites12, searchRadius);if (topologyEdgeViaCampsites12 != null){// 在searchRadius单位内存在一个最近的TopologyEdge。}});}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/44718.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++11中重要的新特性之 lambda表达式 Part two

序言 在上一篇文章中&#xff0c;我们主要介绍了 C11 中的新增的关键词&#xff0c;以及 范围for循环 这类语法糖的使用和背后的逻辑。在这篇文章中我们会继续介绍一个特别重要的新特性分别是 lambda表达式 。 1. lambda表达式 1.1 lambda的定义 C11 中的 lambda表达式 是一种…

昇思25天学习打卡营第19天 | ResNet50迁移学习再续

训练模型部分代码解析 构建Resnet50网络 两行初始化代码 weight_init Normal(mean0, sigma0.02)这行代码定义了一个初始化器weight_init&#xff0c;它将使用均值为0&#xff0c;标准差为0.02的正态分布来初始化网络中的权重。这种初始化策略有助于在网络的初始阶段避免梯度…

Java基础之集合

集合和数组的类比 数组: 长度固定可以存基本数据类型和引用数据类型 集合: 长度可变只能存引用数据类型存储基本数据类型要把他转化为对应的包装类 ArrayList集合 ArrayList成员方法 添加元素 删除元素 索引删除 查询 遍历数组

day30【LeetCode力扣】18.四数之和

day30【LeetCode力扣】18.四数之和 1.题目描述 给你一个由 n 个整数组成的数组 nums &#xff0c;和一个目标值 target 。请你找出并返回满足下述全部条件且不重复的四元组 [nums[a], nums[b], nums[c], nums[d]] &#xff08;若两个四元组元素一一对应&#xff0c;则认为两个…

Linux: Mysql环境安装

Mysql环境安装&#xff08;Centos&#xff09; 前言一、卸载多余环境1.1 卸载mariadb1.2 查看并卸载系统mysql和mariadb安装包 二、换取mysql官方yum源三、安装并启动mysql服务3.1 yum源加载3.2 安装yum源3.3 安装mysql服务3.3.1 安装指令3.3.2 GPG密钥问题解决方法3.3.3 查看是…

循环结构(一)——for语句【互三互三】

文章目录 &#x1f341; 引言 &#x1f341; 一、语句格式 &#x1f341; 二、语句执行过程 &#x1f341; 三、语句格式举例 &#x1f341;四、例题 &#x1f449;【例1】 &#x1f680;示例代码: &#x1f449;【例2】 【方法1】 &#x1f680;示例代码: 【方法2】…

【C++ 编程】引用 - 给变量起别名、浅复制

基本语法&#xff1a;数据类型 &别名 原名int a 10; int &b a;引用必须初始化 (❌ int &b;)&#xff0c;初始化后不可改变 (int c 5; b c&#xff1a;b 没有变成c的别名&#xff0c;而是 a、b 对应的值变更为了 c 的值)本质是指针常量, 浅复制 【黑马程序员匠…

Cartographer重入门到精通(二):运行作者demo及自己的数据集

在demo数据包上运行cartographer 现在Cartographer和Cartographer的Ros包已经都安装好了&#xff0c;你可以下载官方的数据集到指定的目录&#xff08;比如在Deutsches Museum用背包采集的2D和3D 数据&#xff09;&#xff0c;然后使用roslauch来启动demo。 注&#xff1a;la…

IO半虚拟化-Virtio学习笔记

参考&#xff1a;《深入浅出DPDK》及大佬们的各种博客 Virtio简介&运行环境 Virtio 是一种用于虚拟化环境中的半虚拟化 I/O 框架&#xff0c;目的是在虚拟机和主机之间提供一种高效的 I/O 机制。关于什么是半虚拟化和全虚拟化&#xff1a;见SR-IOV学习笔记。 YES&#xf…

PDMS二次开发(二十二)——关于1.0.3.1版本升级内容的说明

目录 1.更新内容介绍2.效果演示3.关于重构自动添加焊口功能的说明3.1错误示例 3.问题交流1.创建焊口提示失败2.程序崩溃 1.更新内容介绍 在添加焊口之前先清除当前branch已有焊口&#xff1b;显示清除焊口的个数和添加焊口的个数&#xff1b;重构了自动添加焊口功能&#xff0…

值得关注的数据资产入表

不错的讲解视频&#xff0c;来自&#xff1a;第122期-杜海博士-《数据资源入表及数据资产化》-大数据百家讲坛-厦门大学数据库实验室主办第122期-杜海博士-《数据资源入表及数据资产化》-大数据百家讲坛-厦门大学数据库实验室主办-20240708_哔哩哔哩_bilibili

《A++ 敏捷开发》- 10 二八原则

团队成员协作&#xff0c;利用项目数据&#xff0c;分析根本原因&#xff0c;制定纠正措施&#xff0c;并立马尝试&#xff0c;判断是否有效&#xff0c;是改善的“基本功”。10-12章会探索里面的注意事项&#xff0c;13章会看两家公司的实施情况和常见问题。 如果已经获得高层…

Linq的常用方法

LINQ&#xff08;Language Integrated Query&#xff09;是.NET Framework中用于数据查询的组件&#xff0c;它将查询功能集成到C#等.NET语言中。LINQ提供了丰富的查询操作符&#xff0c;这些操作符可以应用于各种数据源&#xff0c;如内存中的集合、数据库、XML等。以下是一些…

java中的String 以及其方法(超详细!!!)

文章目录 一、String类型是什么String不可变的原因(经典面试题)String不可变的好处 二、String的常用构造形式1.使用常量串构造2.使用newString对象构造3.字符串数组构造 三、常用方法1. length() 获取字符串的长度2. charAt() 获取字符串中指定字符的值 (代码单元)3. codePoin…

水的几个科学问题及引发的思考

水的几个科学问题及引发的思考 两个相同的容器A和B&#xff0c;分别装有同质量的水&#xff0c;然后&#xff0c;在A容器中加入水&#xff0c;在B容器中加入冰&#xff0c;如果加入水和冰的质量相同。问&#xff0c;容器B的水位将与容器A的水位相同吗&#xff08;假设冰未融化时…

Log4j的原理及应用详解(二)

本系列文章简介&#xff1a; 在软件开发的广阔领域中&#xff0c;日志记录是一项至关重要的活动。它不仅帮助开发者追踪程序的执行流程&#xff0c;还在问题排查、性能监控以及用户行为分析等方面发挥着不可替代的作用。随着软件系统的日益复杂&#xff0c;对日志管理的需求也日…

MySQL和SQlServer的区别

MySQL和SQlServer的区别 说明&#xff1a;在一些常用的SQL语句中&#xff0c;MySQL和SQLServer存在有一些区别&#xff0c;后续我也会将我遇到的不同点持续更新在这篇博客中。 1. 获取当前时间 SQLServer&#xff1a; -- SQLServer -- 1.获取当前时间 SELECT GETDATE(); --…

Vue2切换图片小案例

代码中 v-show "index>0",是表示下标只有大于零时上一页按钮才会显示v-show "index<list.length-1",是表示下标只有小于list数组的最大值才会显示&#xff0c;反之隐藏。click "index--"和click "index",是点击按钮后加减数…

【ZooKeeper学习笔记】

1. ZooKeeper基本概念 Zookeeper官网&#xff1a;https://zookeeper.apache.org/index.html Zookeeper是Apache Hadoop项目中的一个子项目&#xff0c;是一个树形目录服务Zookeeper翻译过来就是动物园管理员&#xff0c;用来管理Hadoop&#xff08;大象&#xff09;、Hive&…

AR0132AT 1/3 英寸 CMOS 数字图像传感器可提供百万像素 HDR 图像处理(器件编号包含:AR0132AT6R、AR0132AT6C)

AR0132AT 1/3 英寸 CMOS 数字图像传感器&#xff0c;带 1280H x 960V 有效像素阵列。它能在线性或高动态模式下捕捉图像&#xff0c;且带有卷帘快门读取。它包含了多种复杂的摄像功能&#xff0c;如自动曝光控制、开窗&#xff0c;以及视频和单帧模式。它适用于低光度和高动态范…