Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Function fFlipPC(ByRef InPointColl As IPointCollection) As IPointCollection
- Dim pOutPC As IPointCollection
- Dim cnt As Long
- pOutPC = New Path
- 'pOutPc.RemovePoints 0, InPointColl.PointCount - 1
- For cnt = InPointColl.PointCount - 1 To 0 Step -1
- pOutPC.AddPoint(InPointColl.Point(cnt))
- Next cnt
- fFlipPC = pOutPC
- End Function
- Private Function fJoinPC(ByRef FirstPointColl As IPointCollection, ByRef SecondPointColl As IPointCollection) As IPointCollection
- Dim pOutPC As IPointCollection
- Dim cnt As Long
- pOutPC = FirstPointColl
- For cnt = 1 To SecondPointColl.PointCount - 1
- pOutPC.AddPoint(SecondPointColl.Point(cnt))
- Next cnt
- fJoinPC = pOutPC
- End Function
- Private Sub UnsplitAllLayer0()
- Dim pLayer As ILayer = My.ArcMap.Document.FocusMap.Layer(0)
- If Not (TypeOf pLayer Is IFeatureLayer) Then Exit Sub ' must be a feature layer
- Dim pFtLayer As IFeatureLayer = CType(pLayer, IFeatureLayer)
- ' step one: find the likely locations..
- Dim pLikelyLocations As IMultipoint = New MultipointClass()
- Dim pLikelyPC As IPointCollection = CType(pLikelyLocations, IPointCollection)
- ' get a cursor on all your lines
- Dim pFtCur As IFeatureCursor = pFtLayer.Search(Nothing, True)
- Dim pFeat As IFeature = pFtCur.NextFeature()
- Dim pTopOp As ITopologicalOperator
- Dim pBoundary As IGeometry
- Dim pBoundaryPC As IPointCollection
- Dim pSpatFlt As ISpatialFilter = New SpatialFilterClass()
- pSpatFlt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
- Dim pSrchGeom As IGeometry
- Do Until pFeat Is Nothing
- pTopOp = pFeat.ShapeCopy
- pBoundary = pTopOp.Boundary ' both ends
- pBoundaryPC = CType(pBoundary, IPointCollection)
- For pPntCnt As Integer = 0 To pBoundaryPC.PointCount - 1
- pTopOp = pBoundaryPC.Point(pPntCnt)
- pSpatFlt.Geometry = pTopOp.Buffer(0.01) ' use a suitable small number here
- If pFtLayer.FeatureClass.FeatureCount(pSpatFlt) = 2 Then
- pLikelyPC.AddPoint(pBoundaryPC.Point(pPntCnt)) ' store this point to go back later
- ' add some code here for checking attributes
- ' if that's important to your network
- End If
- Next
- pFeat = pFtCur.NextFeature() ' go next..
- Loop
- Dim pEd As IEditor = pApplication.FindExtensionByName("ESRI Object Editor") 'http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000004nn000000
- pEd.StartOperation()
- ' now go through the likely locations and dissolve
- For pLikelyCnt As Integer = 0 To pLikelyPC.PointCount - 1
- pTopOp = pLikelyPC.Point(pLikelyCnt)
- pSpatFlt.Geometry = pTopOp.Buffer(0.01) ' use a suitable small number here
- Dim pUpCur As IFeatureCursor = pFtLayer.FeatureClass.Update(pSpatFlt, False) ' must be false here
- Dim pFtInto As IFeature = pUpCur.NextFeature() ' the one that will get the shape
- Dim pFtRem As IFeature = pUpCur.NextFeature() ' the one that will be removed
- Dim pIntoPC As IPointCollection = pFtInto.ShapeCopy
- Dim pRemPC As IPointCollection = pFtRem.ShapeCopy
- ' there are 4 possibilites for line orientation:
- Dim pProxOp As IProximityOperator = pIntoPC.Point(0) ' start point
- Dim pFromFromDist = pProxOp.ReturnDistance(pRemPC.Point(0)) 'distance start-start
- Dim pFromToDist = pProxOp.ReturnDistance(pRemPC.Point(pRemPC.PointCount - 1)) ' distance start-end
- pProxOp = pIntoPC.Point(pIntoPC.PointCount - 1)
- Dim pToFromDist = pProxOp.ReturnDistance(pRemPC.Point(0)) 'distance end-start
- Dim pToToDist = pProxOp.ReturnDistance(pRemPC.Point(pRemPC.PointCount - 1)) ' distance end-end
- Dim pOutPolyLine As IGeometryCollection = New PolylineClass()
- Dim pOutPath As IPointCollection = New PathClass()
- If pToFromDist < 0.01 Then
- ' simplest case just extend
- pOutPath.AddPointCollection(fJoinPC(pIntoPC, pRemPC))
- ElseIf pFromFromDist < 0.01 Then
- ' flip first then join
- pOutPath.AddPointCollection(fJoinPC(fFlipPC(pRemPC), pIntoPC))
- ElseIf pFromToDist < 0.01 Then
- ' Extend first
- pOutPath.AddPointCollection(fJoinPC(pRemPC, pIntoPC))
- ElseIf pToToDist < 0.01 Then
- ' flip second then join
- pOutPath.AddPointCollection(fJoinPC(pIntoPC, fFlipPC(pRemPC)))
- End If
- pOutPolyLine.AddGeometry(pOutPath)
- Dim pOutShape As IGeometry = pOutPolyLine
- pOutShape.SpatialReference = pFtInto.ShapeCopy.SpatialReference
- ' update one and remove the other
- pFtInto.Shape = pOutShape
- pUpCur.UpdateFeature(pFtInto)
- pFtRem.Delete()
- Next
- pEd.StopOperation("Unsplit")
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment