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.

    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
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, _
    End If
    Set pFeat = pEnumFeat.Next
pEditor.StopOperation "makeperps"
Dim pAV As IActiveView
Set pAV = pEditor.Map
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

You will need to tweak that code creating a feature.

FOr instance, imagine that you select all polylines that you wish to do that using a IQueryFilter.

For each row, you will determine the crossing geometry using your sub and you create a new record (in a certain feature class), copying the attributes.

Check these links:





Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.