Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

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:

http://edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeoDatabase/IQueryFilter.htm

http://edndoc.esri.com/arcobjects/9.0/ComponentHelp/esriGeoDatabase/IRow.htm

http://resources.esri.com/help/9.3/ArcGISEngine/arcobjects/esriGeodatabase/IFeature.htm

http://edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeoDatabase/ICursor.htm

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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