i,
I am using ArcGIS 9.2 and am desperately trying to create perpendicular polylines to existing polylines that I have. I would want the perpendicular lines to cross the original lines at their midpoint and I want the perpendicular lines to maintain the attributes of the original lines and finally I'd like to be able to control how long I want the perpendicular lines to be (eg. 50 metres)
A script I found and which I've pasted below, takes me a good part of the way there in that it creates perpendicular lines at the midpoints but it doesn't retain the attributes or allow me to set the length. Can anyone suggest what I need to change to bring over the attributes and let me set the length of lines that are drawn. Thank you very much for any help that you can give me. I'm new at this so I apologize if I haven't passted the code in the propoer formatting
Option Explicit
Sub Test()
Dim pEditor As IEditor
Set pEditor = Application.FindExtensionByName("ESRI Object Editor")
If pEditor.EditState <> esriStateEditing Then
MsgBox "start editing first"
Exit Sub
End If
Dim pEL As IEditLayers
Set pEL = pEditor
If pEL.CurrentLayer.FeatureClass.ShapeType <> esriGeometryPolyline Then
MsgBox "target layer must be polyline"
Exit Sub
End If
If pEditor.Map.SelectionCount = 0 Then
MsgBox "nothing selected"
Exit Sub
End If
Dim pEnumFeat As IEnumFeature
Set pEnumFeat = pEditor.Map.FeatureSelection
pEnumFeat.Reset
pEditor.StartOperation
Dim pFeat As IFeature
Set pFeat = pEnumFeat.Next
Do Until pFeat Is Nothing
If pFeat.Shape.GeometryType = esriGeometryPolyline Then
Dim pNewFeat As IFeature
Set pNewFeat = pEL.CurrentLayer.FeatureClass.CreateFeature
Set pNewFeat.Shape = MakePerp(pFeat.Shape, _
GetLength(pFeat.Shape))
pNewFeat.Store
End If
Set pFeat = pEnumFeat.Next
Loop
pEditor.StopOperation "makeperps"
Dim pAV As IActiveView
Set pAV = pEditor.Map
pAV.Refresh
End Sub
Function GetLength(pPolyline As IPolyline) As Double
GetLength = pPolyline.Length
End Function
Function MakePerp(pBaseLine As IPolyline, ByVal dLen As Double) As IPolyline
Dim pPointColl As IPointCollection
Set pPointColl = New Polyline
Dim pPerpLine As ILine
Set pPerpLine = New Line
pBaseLine.QueryNormal esriNoExtension, 0.5, True, dLen / 2#, pPerpLine
pPointColl.AddPoint pPerpLine.ToPoint
pBaseLine.QueryNormal esriNoExtension, 0.5, True, dLen / -2#, pPerpLine
pPointColl.AddPoint pPerpLine.ToPoint
Set MakePerp = pPointColl
End Function