Guest User

Untitled

a guest
Jul 23rd, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. Private Function fFlipPC(ByRef InPointColl As IPointCollection) As IPointCollection
  2. Dim pOutPC As IPointCollection
  3. Dim cnt As Long
  4.  
  5. pOutPC = New Path
  6. 'pOutPc.RemovePoints 0, InPointColl.PointCount - 1
  7.  
  8. For cnt = InPointColl.PointCount - 1 To 0 Step -1
  9. pOutPC.AddPoint(InPointColl.Point(cnt))
  10. Next cnt
  11. fFlipPC = pOutPC
  12. End Function
  13. Private Function fJoinPC(ByRef FirstPointColl As IPointCollection, ByRef SecondPointColl As IPointCollection) As IPointCollection
  14. Dim pOutPC As IPointCollection
  15. Dim cnt As Long
  16.  
  17. pOutPC = FirstPointColl
  18. For cnt = 1 To SecondPointColl.PointCount - 1
  19. pOutPC.AddPoint(SecondPointColl.Point(cnt))
  20. Next cnt
  21. fJoinPC = pOutPC
  22. End Function
  23. Private Sub UnsplitAllLayer0()
  24. Dim pLayer As ILayer = My.ArcMap.Document.FocusMap.Layer(0)
  25. If Not (TypeOf pLayer Is IFeatureLayer) Then Exit Sub ' must be a feature layer
  26.  
  27. Dim pFtLayer As IFeatureLayer = CType(pLayer, IFeatureLayer)
  28. ' step one: find the likely locations..
  29. Dim pLikelyLocations As IMultipoint = New MultipointClass()
  30. Dim pLikelyPC As IPointCollection = CType(pLikelyLocations, IPointCollection)
  31.  
  32. ' get a cursor on all your lines
  33. Dim pFtCur As IFeatureCursor = pFtLayer.Search(Nothing, True)
  34. Dim pFeat As IFeature = pFtCur.NextFeature()
  35.  
  36. Dim pTopOp As ITopologicalOperator
  37. Dim pBoundary As IGeometry
  38. Dim pBoundaryPC As IPointCollection
  39. Dim pSpatFlt As ISpatialFilter = New SpatialFilterClass()
  40. pSpatFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
  41. Dim pSrchGeom As IGeometry
  42.  
  43. Do Until pFeat Is Nothing
  44. pTopOp = pFeat.ShapeCopy
  45. pBoundary = pTopOp.Boundary ' both ends
  46. pBoundaryPC = CType(pBoundary, IPointCollection)
  47.  
  48. For pPntCnt As Integer = 0 To pBoundaryPC.PointCount - 1
  49. pTopOp = pBoundaryPC.Point(pPntCnt)
  50. pSpatFlt.Geometry = pTopOp.Buffer(0.01) ' use a suitable small number here
  51. If pFtLayer.FeatureClass.FeatureCount(pSpatFlt) = 2 Then
  52. pLikelyPC.AddPoint(pBoundaryPC.Point(pPntCnt)) ' store this point to go back later
  53. ' add some code here for checking attributes
  54. ' if that's important to your network
  55. End If
  56. Next
  57.  
  58. pFeat = pFtCur.NextFeature() ' go next..
  59. Loop
  60.  
  61. Dim pEd As IEditor = pApplication.FindExtensionByName("ESRI Object Editor") 'http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000004nn000000
  62. pEd.StartOperation()
  63.  
  64. ' now go through the likely locations and dissolve
  65. For pLikelyCnt As Integer = 0 To pLikelyPC.PointCount - 1
  66. pTopOp = pLikelyPC.Point(pLikelyCnt)
  67. pSpatFlt.Geometry = pTopOp.Buffer(0.01) ' use a suitable small number here
  68. Dim pUpCur As IFeatureCursor = pFtLayer.FeatureClass.Update(pSpatFlt, False) ' must be false here
  69. Dim pFtInto As IFeature = pUpCur.NextFeature() ' the one that will get the shape
  70. Dim pFtRem As IFeature = pUpCur.NextFeature() ' the one that will be removed
  71.  
  72. Dim pIntoPC As IPointCollection = pFtInto.ShapeCopy
  73. Dim pRemPC As IPointCollection = pFtRem.ShapeCopy
  74.  
  75. ' there are 4 possibilites for line orientation:
  76. Dim pProxOp As IProximityOperator = pIntoPC.Point(0) ' start point
  77. Dim pFromFromDist = pProxOp.ReturnDistance(pRemPC.Point(0)) 'distance start-start
  78. Dim pFromToDist = pProxOp.ReturnDistance(pRemPC.Point(pRemPC.PointCount - 1)) ' distance start-end
  79. pProxOp = pIntoPC.Point(pIntoPC.PointCount - 1)
  80. Dim pToFromDist = pProxOp.ReturnDistance(pRemPC.Point(0)) 'distance end-start
  81. Dim pToToDist = pProxOp.ReturnDistance(pRemPC.Point(pRemPC.PointCount - 1)) ' distance end-end
  82.  
  83. Dim pOutPolyLine As IGeometryCollection = New PolylineClass()
  84. Dim pOutPath As IPointCollection = New PathClass()
  85. If pToFromDist < 0.01 Then
  86. ' simplest case just extend
  87. pOutPath.AddPointCollection(fJoinPC(pIntoPC, pRemPC))
  88. ElseIf pFromFromDist < 0.01 Then
  89. ' flip first then join
  90. pOutPath.AddPointCollection(fJoinPC(fFlipPC(pRemPC), pIntoPC))
  91. ElseIf pFromToDist < 0.01 Then
  92. ' Extend first
  93. pOutPath.AddPointCollection(fJoinPC(pRemPC, pIntoPC))
  94. ElseIf pToToDist < 0.01 Then
  95. ' flip second then join
  96. pOutPath.AddPointCollection(fJoinPC(pIntoPC, fFlipPC(pRemPC)))
  97. End If
  98.  
  99. pOutPolyLine.AddGeometry(pOutPath)
  100. Dim pOutShape As IGeometry = pOutPolyLine
  101. pOutShape.SpatialReference = pFtInto.ShapeCopy.SpatialReference
  102.  
  103. ' update one and remove the other
  104. pFtInto.Shape = pOutShape
  105. pUpCur.UpdateFeature(pFtInto)
  106. pFtRem.Delete()
  107. Next
  108.  
  109. pEd.StopOperation("Unsplit")
  110. End Sub
Advertisement
Add Comment
Please, Sign In to add comment