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.

A colleague conducted a field survey and recorded the start and end points of the transects with a GPS. These points have been imported to ArcMap 9.3 as 2 point layers. Both layers have a "transect number" field where each pair shares the same value, in order to match up start and end points.

I can manually "connect the dots," but there are about 1000 pairs of points, and I am hoping there's a quicker way.

If anyone knows of a simple script to run this procedure, I would greatly appreciate it!

Thanks!

share|improve this question

6 Answers 6

ET Geo Wizards has a function that will turn a set of points into lines. It produces a unique feature for each set of values based on a unique field value. Although it's not a free program, I believe this particular function is free to use without any limitations.

share|improve this answer
    
Beat me to it ;) –  om_henners Oct 18 '10 at 11:40

I saw this old avenue script. You could open it up, and apply the same logic in VBA. It will be fairly simple to automate, but cant find the equivalent 'ready to go' script in VBA.

share|improve this answer

Here is a start. Script includes CreateLine procedure that takes in 4 parameters which are the line from and to point coordinates. For illustration purposes i added another procedure that lets you input the coordinates manually then calls the CreateLine procedure passing it the input coordinates. You must be 'editing' and the 'destination' line feature class has to be the 'target' layer.

You can modify the procedure for your purposes by adding in a loop that reads the input point features from your point features classes.

Public Sub CreateLine(From_X As Double, From_Y As Double, To_X As Double, To_Y As Double)

©Jakub Sisak, 2010

    Dim pUID As New UID
    Dim pEditor As IEditor
    Dim pEditLayers As IEditLayers
    Dim pActiveView As IActiveView
    Dim pNewFeature As IFeature

    Dim pPolyline As IPolyline5
    Dim pFromPoint As IPoint
    Dim pToPoint As IPoint
    Dim TargetFeatureClass As IFeatureClass


    pUID = "esriCore.Editor"
    Set pEditor = Application.FindExtensionByCLSID(pUID)
    Set pEditLayers = pEditor 'QI
    Set pActiveView = pEditor.Map

    If pEditor.EditState = esriStateNotEditing Then
        MsgBox "You must be editing to use this feature!"
        Exit Sub
    End If

    If Not pEditLayers.CurrentLayer.FeatureClass.ShapeType = esriGeometryPolyline Then
        MsgBox "Target layer must be a polyline type!"
        Exit Sub
    Else
        Set TargetFeatureClass = pEditLayers.CurrentLayer.FeatureClass
    End If

    pEditor.StartOperation

    Set pFromPoint = New Point
    Set pToPoint = New Point
    Set pPolyline = New Polyline

    pFromPoint.x = From_X
    pFromPoint.y = From_Y
    pPolyline.FromPoint = pFromPoint

    pToPoint.x = To_X
    pToPoint.y = To_Y
    pPolyline.ToPoint = pToPoint

    Set pNewFeature = pEditLayers.CurrentLayer.FeatureClass.CreateFeature
    Set pNewFeature.Shape = pPolyline

    pEditor.StopOperation "Create Polyline"

    pActiveView.Refresh

End Sub


Public Sub PassLineParameters()
    Dim From_X As Double, From_Y As Double, To_X As Double, To_Y As Double

    'collect coordinates
    From_X = InputBox("Enter From 'X' Coordinate:", "From X")
    From_Y = InputBox("Enter From 'Y' Coordinate:", "From Y")
    To_X = InputBox("Enter To 'X' Coordinate:", "To X")
    To_Y = InputBox("Enter To 'Y' Coordinate:", "To Y")

    CreateLine From_X, From_Y, To_X, To_Y 'call procedure to create line

End Sub
share|improve this answer

Here's a python function that does something similar. link_value is the id that the points share. lat_fc is the output line featureclass.

    def make_laterals( self ):
    """ Uses 2 input FCs - SH and BH well locations - and creates a straight 
        as-the-crow-flies lateral line from the SH to the BH. """ 
    from_sh_fc = args.surf_out_fc
    to_bh_fc = args.bott_out_fc
    lat_fc = args.laterals_output_dataset
    skip_message = 'No corresponding point for link value %s - moving on...'

    def add_print_message( msg, severity ):
        """ Adds a message based on severity """
        if severity == 0: self.gp.AddMessage(msg)
        elif severity == 1: self.gp.AddWarning(msg)
        elif severity == 2: self.gp.AddError(msg)

    def create_point( x, y ):
        """ Creates and returns point objects """
        pnt = self.gp.CreateObject('Point')
        pnt.x = x
        pnt.y = y
        return pnt

    from_desc = self.gp.Describe(from_sh_fc)
    to_desc = self.gp.Describe(to_bh_fc)
    lb, rb = self.get_field_wrapper()

    self.gp.CreateFeatureclass(os.path.split(lat_fc)[0], \
        os.path.split(lat_fc)[1], 'POLYLINE', '', 'DISABLED', \
        'DISABLED', self.spatial_ref)

    out_desc = self.gp.Describe(lat_fc)
    out_rows = self.gp.InsertCursor(lat_fc)

    from_rows = self.gp.SearchCursor(from_sh_fc)
    from_row = from_rows.Next()

    point_array = self.gp.CreateObject('Array')
    part_array = self.gp.CreateObject('Array')

    while from_row:
        from_feat = from_row.GetValue(from_desc.Shapefieldname)
        from_x, from_y = map(lambda x: float(x), from_feat.centroid.split(' '))
        from_point = create_point(from_x, from_y)

        # Get value of LATID
        link_value = from_row.GetValue(self.lat_id_field)

        where_clause = '%s%s%s = %s' % (lb, self.lat_id_field, rb, link_value)

        to_rows = self.gp.SearchCursor(to_bh_fc, where_clause)
        to_row = to_rows.Next()

        match_count = 0

        while to_row:
            to_feat = to_row.GetValue(to_desc.Shapefieldname)
            to_x, to_y = map(lambda x: float(x), to_feat.centroid.split(' '))
            to_point = create_point( to_x, to_y )

            point_array.Add(from_point)
            point_array.Add(to_point)
            part_array.Add(point_array)

            out_row = out_rows.NewRow()
            out_row.SetValue(out_desc.shapefieldname, part_array)

            out_rows.InsertRow(out_row)

            point_array.RemoveAll()
            part_array.RemoveAll()
            to_row = to_rows.Next()
            match_count+=1

        #if match_count == 0:
            #add_print_message( skip_message % link_value, 1 )

        del to_row
        del to_rows

        from_row = from_rows.Next()

    del out_row
    del out_rows
    del from_row
    del from_rows
share|improve this answer

Simon's and Don's answers look like they will work, but I have also used this ArcScript in 9.2, Points2Lines.

If you don't mind taking alittle time to convert your data to where the begin and end of the transect are in two separate vectors (i.e.

ID BeginY BeginX EndY EndX

you can draw the lines using CrimeStat. It appears the Points2Lines script and the script the others having linked to will give you what you want as is.

share|improve this answer

Hi jakub i run your coding of Public Sub CreateLine() it is running and adding record in Line feature but it is not displaying line on screen. please helpout

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.