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

  1. Start ArcMap.
  2. Open the Visual Basic Editor. -show me-
  3.  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.

     

  4. Copy/Paste the following code into the code module. 
  5. Option Explicit
  6.  
  7. Public Sub SelectPolyAsSharesSegementWith()
  8.  
  9. Dim pMxDoc As IMxDocument
  10. Set pMxDoc = ThisDocument
  11. Dim pMap As IMap
  12. Set pMap = pMxDoc.FocusMap
  13.  
  14. ' Union all of the search features into one geometry and strip off
  15. ' it's boundary for use in the search. Since we are only interested
  16. ' in shared segments, not areas, the boundary is all that is needed.
  17.  
  18. ' Get search layer
  19. Dim pPolygonLyr As IFeatureLayer
  20. Set pPolygonLyr = pMap.Layer(1)
  21. Dim pLFeatClass As IFeatureClass
  22. Set pLFeatClass = pPolygonLyr.FeatureClass
  23.  
  24. ' Loop through the polygons, simplify them and then
  25. ' add them to a Geometry Bag.
  26. Dim pFeatureCursor As IFeatureCursor
  27. Set pFeatureCursor = pLFeatClass.Search(Nothing, True)
  28. Dim pFeature As IFeature
  29. Set pFeature = pFeatureCursor.NextFeature
  30. Dim pGeometryCollection As IGeometryCollection
  31. Set pGeometryCollection = New GeometryBag
  32. Dim pTopologicalOperator2 As ITopologicalOperator2
  33.  
  34. Do While Not pFeature Is Nothing
  35. Set pTopologicalOperator2 = pFeature.ShapeCopy
  36. pTopologicalOperator2.IsKnownSimple = False
  37. pTopologicalOperator2.Simplify
  38. pGeometryCollection.AddGeometry pTopologicalOperator2
  39. Set pFeature = pFeatureCursor.NextFeature
  40. Loop
  41.  
  42. ' Union all the polygons
  43. Dim pTopologicalOperator1 As ITopologicalOperator2
  44. Set pTopologicalOperator1 = New Polygon
  45. pTopologicalOperator1.ConstructUnion pGeometryCollection
  46.  
  47. ' Construct the boundary of the unioned polygons
  48. Dim pTopologicalOperator3 As ITopologicalOperator2
  49. Set pTopologicalOperator3 = New Polyline
  50. Set pTopologicalOperator3 = pTopologicalOperator1.Boundary
  51.  
  52. ' Use the boundary to find the candidate features
  53.  
  54. ' Get the target FeatureClass
  55. Dim pFeatureLayer As IFeatureLayer
  56. Set pFeatureLayer = pMap.Layer(0)
  57. Dim pFeatureClass As IFeatureClass
  58. Set pFeatureClass = pFeatureLayer.FeatureClass
  59.  
  60. ' Set up a scratch workspace to use for the selection
  61. Dim pScratchWorkspace As IWorkspace
  62. Dim pScratchWorkspaceFactory As IScratchWorkspaceFactory
  63. Set pScratchWorkspaceFactory = New ScratchWorkspaceFactory
  64. Set pScratchWorkspace = pScratchWorkspaceFactory.DefaultScratchWorkspace
  65.  
  66. ' Setup the spatial filter
  67. Dim pSpatialFilter As ISpatialFilter
  68. Set pSpatialFilter = New SpatialFilter
  69. With pSpatialFilter
  70. Set .Geometry = pTopologicalOperator3
  71. .GeometryField = "SHAPE"
  72. .SpatialRel = esriSpatialRelIntersects
  73. End With
  74.  
  75. ' Perform the search and create a selection set
  76. Dim pTempSelection As ISelectionSet
  77. Set pTempSelection = pFeatureClass.Select(pSpatialFilter, esriSelectionTypeIDSet, esriSelectionOptionNormal, pScratchWorkspace)
  78.  
  79. ' Loop through the features and check to see if they share a segment
  80. ' with the search geometry. If they don't, remove them from the selection
  81. ' set.
  82.  
  83. ' Create a feature cursor to allow us the examine the candidate features
  84. Dim pTempFeatCur As IFeatureCursor
  85. pTempSelection.Search Nothing, True, pTempFeatCur
  86.  
  87. Dim iOIDList(1) As Long
  88. Dim iOIDListCount As Long
  89. iOIDListCount = 1
  90. Dim pGeometry As IPolyline
  91. Dim pTempFeat As IFeature
  92.  
  93. ' Fetch the first feature
  94. Set pTempFeat = pTempFeatCur.NextFeature
  95. Dim pTempPolyline As IPolyline
  96.  
  97. ' Check for the one dimentional intersection of the geometries.
  98. ' If there is no intersection the returned geometry will be empty. If
  99. ' it is, remove it from the selection set.
  100.  
  101. Dim pTopologicalOperator4 As ITopologicalOperator2
  102. Set pTopologicalOperator4 = New Polygon
  103.  
  104. Do
  105. iOIDList(0) = pTempFeat.OID
  106.  
  107. Set pTopologicalOperator4 = pTempFeat.ShapeCopy
  108.  
  109. pTopologicalOperator4.IsKnownSimple = False
  110. pTopologicalOperator4.Simplify
  111.  
  112. Set pTempPolyline = pTopologicalOperator4.Boundary
  113.  
  114. Set pGeometry = pTopologicalOperator3.Intersect(pTempPolyline, esriGeometry1Dimension)
  115. If pGeometry.IsEmpty Then
  116. pTempSelection.RemoveList iOIDListCount, iOIDList(0)
  117. End If
  118.  
  119. Set pTempFeat = pTempFeatCur.NextFeature
  120. Loop Until pTempFeat Is Nothing
  121.  
  122. ' Set the feature selection
  123. Dim pFeatureSelection As IFeatureSelection
  124. Set pFeatureSelection = pFeatureLayer
  125. Set pFeatureSelection.SelectionSet = pTempSelection
  126.  
  127. ' Display the selected features.
  128. Dim pdoc As IMxDocument
  129. Set pdoc = ThisDocument
  130. pdoc.ActiveView.Refresh
  131.  

    End Sub

     

  132. 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的更多相关文章

  1. Division of Line Segment

    Division of Line Segment /** */ void Line::EqualDivision(int nCount, QLineF fline, QList<QPointF& ...

  2. 目标检测之线段检测---lsd line segment detector

    (1)线段检测应用背景 (2)线段检测原理简介 (3)线段检测实例 a line segment detector (4)hough 变换和 lsd 的区别 --------------------- ...

  3. 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 ...

  4. Line segment matching

    FMII2方法:FMII方法的轻微的修改.有限线段和无限线段(直线)的匹配. 求解方法: SVD分解 Unit Quaternion 协方差矩阵: 通过对C进行SVD分解得到R,根据R求得T. 算法流 ...

  5. Android OpenGL ES(九)绘制线段Line Segment .

    创建一个DrawLine Activity,定义四个顶点: float vertexArray[] = { -0.8f, -0.4f * 1.732f, 0.0f, -0.4f, 0.4f * 1.7 ...

  6. 用ArcGIS?37个Arcmap常用操作技巧可能帮到您

    1. 要素的剪切与延伸 实用工具 TASK 任务栏 Extend/Trim feature 剪切所得内容与你画线的方向有关. 2. 自动捕捉跟踪工具 点击Editor工具栏中Snapping来打开Sn ...

  7. ArcGIS中的查询

    最近身体不适,静下心来看了一下以前收集的电子书.下面是<ArcGIS地理信息系统教程_第5版>(李玉龙)第5章“查询”的读书笔记. 1.查询的常见应用: 选择感兴趣的要素:查找哪些要素满足 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. [原创] 聊聊X-Forwared-For和关于他的几种非主流安全问题

    关于这个X-FORWARED-FOR 有很多非主流漏洞都和他有关  之前我和我的基友misty以为关于这个标头的漏洞会有很多会被很多开发者忽视 会出现很多关于他的安全漏洞 可是由于我精力不足 就没继续 ...

  2. tomcat切割日志的shell脚本

    #!/bin/bash cd /usr/tomcats/ d=`date +%F` m1=`date -d'1 month ago' +%F` ` do cd tomcat808"$i&qu ...

  3. boost -- scoped_lock V.S. mutex lock/unlock —— why scoped_lock is recommanded?

    why scoped_lock is recommanded? 其实,这和RAII idiom变流行是一样的原因:因为你可以确保任何情况下离开执行范围都会解锁mutex. 注意,这不仅仅是说你可能忘记 ...

  4. 【转】C++怎么读写windows剪贴板的内容?比如说自动把一个字符串复制.

    // 复制数据至剪切板BOOL CopyToClipboard(const char* pszData, const int nDataLen){ if(::OpenClipboard(NULL)) ...

  5. LINQ查询操作符之Select、Where、OrderBy、OrderByDescending、GroupBy、Join、GroupJoin及其对应的查询语法

    介绍    ·Select - Select选择:延迟    ·Where - Where查询:延迟    ·OrderBy - 按指定表达式对集合正序排序:延迟    ·OrderByDescend ...

  6. NUnit笔记

    注意:单元测试中,Case 与 Case 之间不能有任何关系 测试方法不能有返回值,不能有参数,测试方法必须声明为 public [TestFixture] //声明测试类 [SetUp] //建立, ...

  7. JQuery Placeholder - Input提示信息

    JQuery Placeholder Placeholder属性是HTML5为Input添加的,在Input上提供一个占位符,文字形式展示输入文字预期值的提示信息. 如: 需要使用:placehold ...

  8. CSS3图片缩放

    鼠标指上去,图片放大,鼠标离开图片恢复原样,并且有放大.缩小效果            Css代码实现:

  9. MySQL绿色版5.7以上安装教程

    写在前面:5.7增加了安全性,默认root密码不在为空,而是初始化时随机生成一个root密码,改root密码的方式也不一样了 下载地址 http://dev.mysql.com/downloads/m ...

  10. yum install mysql

    rpm -qa|grep -i mysqlmysql-libs-5.1.52-1.1.alios6.1.x86_64mysql-5.1.52-1.1.alios6.1.x86_64mysql-deve ...