HowTo Perform the spatial selection 'Share a line segment with' using ArcObjects
HowTo Perform the spatial selection 'Share a line segment with' using ArcObjects
Article ID: |
26528 |
Software: |
ArcGIS - ArcEditor 8.1, 8.1.2, 8.2, 8.3 ArcGIS - ArcInfo 8.1, 8.1.2, 8.2, 8.3 ArcGIS - ArcView 8.1, 8.1.2, 8.2, 8.3 |
Platforms: |
Windows NT 4.0, 2000, XP |
Summary
Instructions provided illustrate how to duplicate the functionality of ArcMap's spatial selection 'share a line segment with' through ArcObjects code.
Procedure
- Start ArcMap.
- Open the Visual Basic Editor. -show me-
- In the Project Explorer window, expand Project.mxt and select ArcMap Objects > ThisDocument. Right-click and select .-show me-
Code in the Project's ThisDocument code module will only run in the current map document. If you want to store the code in all map documents open the Normal.mxt ThisDocument code module.
- Copy/Paste the following code into the code module.
- Option Explicit
- Public Sub SelectPolyAsSharesSegementWith()
- Dim pMxDoc As IMxDocument
- Set pMxDoc = ThisDocument
- Dim pMap As IMap
- Set pMap = pMxDoc.FocusMap
- ' Union all of the search features into one geometry and strip off
- ' it's boundary for use in the search. Since we are only interested
- ' in shared segments, not areas, the boundary is all that is needed.
- ' Get search layer
- Dim pPolygonLyr As IFeatureLayer
- Set pPolygonLyr = pMap.Layer(1)
- Dim pLFeatClass As IFeatureClass
- Set pLFeatClass = pPolygonLyr.FeatureClass
- ' Loop through the polygons, simplify them and then
- ' add them to a Geometry Bag.
- Dim pFeatureCursor As IFeatureCursor
- Set pFeatureCursor = pLFeatClass.Search(Nothing, True)
- Dim pFeature As IFeature
- Set pFeature = pFeatureCursor.NextFeature
- Dim pGeometryCollection As IGeometryCollection
- Set pGeometryCollection = New GeometryBag
- Dim pTopologicalOperator2 As ITopologicalOperator2
- Do While Not pFeature Is Nothing
- Set pTopologicalOperator2 = pFeature.ShapeCopy
- pTopologicalOperator2.IsKnownSimple = False
- pTopologicalOperator2.Simplify
- pGeometryCollection.AddGeometry pTopologicalOperator2
- Set pFeature = pFeatureCursor.NextFeature
- Loop
- ' Union all the polygons
- Dim pTopologicalOperator1 As ITopologicalOperator2
- Set pTopologicalOperator1 = New Polygon
- pTopologicalOperator1.ConstructUnion pGeometryCollection
- ' Construct the boundary of the unioned polygons
- Dim pTopologicalOperator3 As ITopologicalOperator2
- Set pTopologicalOperator3 = New Polyline
- Set pTopologicalOperator3 = pTopologicalOperator1.Boundary
- ' Use the boundary to find the candidate features
- ' Get the target FeatureClass
- Dim pFeatureLayer As IFeatureLayer
- Set pFeatureLayer = pMap.Layer(0)
- Dim pFeatureClass As IFeatureClass
- Set pFeatureClass = pFeatureLayer.FeatureClass
- ' Set up a scratch workspace to use for the selection
- Dim pScratchWorkspace As IWorkspace
- Dim pScratchWorkspaceFactory As IScratchWorkspaceFactory
- Set pScratchWorkspaceFactory = New ScratchWorkspaceFactory
- Set pScratchWorkspace = pScratchWorkspaceFactory.DefaultScratchWorkspace
- ' Setup the spatial filter
- Dim pSpatialFilter As ISpatialFilter
- Set pSpatialFilter = New SpatialFilter
- With pSpatialFilter
- Set .Geometry = pTopologicalOperator3
- .GeometryField = "SHAPE"
- .SpatialRel = esriSpatialRelIntersects
- End With
- ' Perform the search and create a selection set
- Dim pTempSelection As ISelectionSet
- Set pTempSelection = pFeatureClass.Select(pSpatialFilter, esriSelectionTypeIDSet, esriSelectionOptionNormal, pScratchWorkspace)
- ' Loop through the features and check to see if they share a segment
- ' with the search geometry. If they don't, remove them from the selection
- ' set.
- ' Create a feature cursor to allow us the examine the candidate features
- Dim pTempFeatCur As IFeatureCursor
- pTempSelection.Search Nothing, True, pTempFeatCur
- Dim iOIDList(1) As Long
- Dim iOIDListCount As Long
- iOIDListCount = 1
- Dim pGeometry As IPolyline
- Dim pTempFeat As IFeature
- ' Fetch the first feature
- Set pTempFeat = pTempFeatCur.NextFeature
- Dim pTempPolyline As IPolyline
- ' Check for the one dimentional intersection of the geometries.
- ' If there is no intersection the returned geometry will be empty. If
- ' it is, remove it from the selection set.
- Dim pTopologicalOperator4 As ITopologicalOperator2
- Set pTopologicalOperator4 = New Polygon
- Do
- iOIDList(0) = pTempFeat.OID
- Set pTopologicalOperator4 = pTempFeat.ShapeCopy
- pTopologicalOperator4.IsKnownSimple = False
- pTopologicalOperator4.Simplify
- Set pTempPolyline = pTopologicalOperator4.Boundary
- Set pGeometry = pTopologicalOperator3.Intersect(pTempPolyline, esriGeometry1Dimension)
- If pGeometry.IsEmpty Then
- pTempSelection.RemoveList iOIDListCount, iOIDList(0)
- End If
- Set pTempFeat = pTempFeatCur.NextFeature
- Loop Until pTempFeat Is Nothing
- ' Set the feature selection
- Dim pFeatureSelection As IFeatureSelection
- Set pFeatureSelection = pFeatureLayer
- Set pFeatureSelection.SelectionSet = pTempSelection
- ' Display the selected features.
- Dim pdoc As IMxDocument
- Set pdoc = ThisDocument
- pdoc.ActiveView.Refresh
End Sub
- Close the Visual Basic Editor.
Created: 4/1/2004
Last Modified: 7/1/2008
Article Rating: (1)
If you would like to post a comment, please login
Comments
By Anonymous - 07/20/2005 7:47 AM
Hello, The sample code to select polygons that share a segment with the selected polygon did not work for me. Although I tested it in 9.1, no library is explicitly defined so I don't think this is the problem. http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=26528 Sincerely, Valentina
HowTo Perform the spatial selection 'Share a line segment with' using ArcObjects的更多相关文章
- Division of Line Segment
Division of Line Segment /** */ void Line::EqualDivision(int nCount, QLineF fline, QList<QPointF& ...
- 目标检测之线段检测---lsd line segment detector
(1)线段检测应用背景 (2)线段检测原理简介 (3)线段检测实例 a line segment detector (4)hough 变换和 lsd 的区别 --------------------- ...
- HDU 1542/POJ 1151 Atlantis (scaning line + segment tree)
A template of discretization + scaning line + segment tree. It's easy to understand, but a little di ...
- Line segment matching
FMII2方法:FMII方法的轻微的修改.有限线段和无限线段(直线)的匹配. 求解方法: SVD分解 Unit Quaternion 协方差矩阵: 通过对C进行SVD分解得到R,根据R求得T. 算法流 ...
- Android OpenGL ES(九)绘制线段Line Segment .
创建一个DrawLine Activity,定义四个顶点: float vertexArray[] = { -0.8f, -0.4f * 1.732f, 0.0f, -0.4f, 0.4f * 1.7 ...
- 用ArcGIS?37个Arcmap常用操作技巧可能帮到您
1. 要素的剪切与延伸 实用工具 TASK 任务栏 Extend/Trim feature 剪切所得内容与你画线的方向有关. 2. 自动捕捉跟踪工具 点击Editor工具栏中Snapping来打开Sn ...
- ArcGIS中的查询
最近身体不适,静下心来看了一下以前收集的电子书.下面是<ArcGIS地理信息系统教程_第5版>(李玉龙)第5章“查询”的读书笔记. 1.查询的常见应用: 选择感兴趣的要素:查找哪些要素满足 ...
- 2016-2017 National Taiwan University World Final Team Selection Contest C - Crazy Dreamoon
题目:Statements Dreamoon likes algorithm competitions very much. But when he feels crazy because he ca ...
- 2016-2017 National Taiwan University World Final Team Selection Contest A - Hacker Cups and Balls
题目: Dreamoon likes algorithm competitions very much. But when he feels crazy because he cannot figur ...
随机推荐
- ubuntu 常用命令
此处为使用ubuntu中常用的命令,不会全面深入讲解命令,仅供日常使用查看,以备遗忘. 不定时更新! 1.远程传输文件(小文件) scp [user@源文件地址:/目录/.../file] [目的地址 ...
- [转载]MCU DSP ARM 嵌入式 之间的区别
2016-06-28 10:31:24) 嵌入式"这是个概念,准确的定义没有,各个书上都有各自的定义.但是主要思想是一样的,就是相比较PC机这种通用系统来说,嵌入式系统是个专用系统,结构精简 ...
- applicationContext.xml和web.xml的一些配置
applicationContext.xml <!-- test环境 --> <beans profile="test"> <context:prop ...
- TP代码
<?php// 本类由系统自动生成,仅供测试用途class IndexAction extends Action { public function index(){ $th ...
- 关于SCRUM站立会议
查询过后对SCRUM站立会议有了初步的了解 站立会议:在敏捷流程的冲刺阶段中,每一天都会举行项目状况会议,强迫每个人向同伴报告进度,迫使大家把问题摆在明面上,这个会议被称为“scrum”或“每日站立会 ...
- 【转载】ANSYS的APDL与C语言混合编程(实例)
原文地址:http://www.cnblogs.com/lyq105/archive/2010/05/04/1727557.html 本文讨论的不是利用C语言为ANSYS写扩展(或者说是用户子程序), ...
- 安装配置sock5代理
环境准备及安装 yum -y install pam-devel openldap-devel cyrus-sasl-devel yum -y install openssl-devel.x86_64 ...
- MySQL性能优化总结(转)https://yq.aliyun.com/articles/24249
摘要: 一.MySQL的主要适用场景 1.Web网站系统 2.日志记录系统 3.数据仓库系统 4.嵌入式系统 二.MySQL架构图: 三.MySQL存储引擎概述 1)MyISAM存储引擎 MyIS ...
- SpringMVC学习系列(2) 之 经典的HelloWorld实现
前一篇简单介绍了Spring MVC的一些知识,下面就要开始学习如何把Spring MVC运用到具体的项目中去. 首先还是从一个简单的Hello World项目说起: 我机器的开发环境为: Ubunt ...
- 无法作为数据库主体执行,因为主体 "dbo" 不存在、无法模拟这种类型的主体,或您没有所需的权限。 已将数据库上下文更改为
右键删除发布时报错信息: 其他信息:执行 Transact-SQL 语句或批处理时发生了异常. (Microsoft.SqlServer.ConnectionInfo)——————————无法作为数据 ...