Auto connect points with a line?

3865
8
Jump to solution
04-05-2016 07:24 AM
DanielNilsson1
New Contributor II

Need help to find out the best way to draw a line between points from different layers to show how the points have moved and save the line in a new layer.

Layer 1 - points that shows the positions hour 1.

Layer 2 - same points that shows the positions hour 2.

The points keep their ID in the attribute table.

Need a quick way to generate the lines as the data changes (eg. new layers are created)

Thanks!

1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

This should work.  The merged layer can just be intermediate data.  Ex:

Screen1.PNG

View solution in original post

8 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Daniel,

Take a look at the Points to Line tool. This may provide the solution you're looking for.

DanielNilsson1
New Contributor II

The points are in different layers and the output should be a layer with lines (keeping the ID as an identifier for the line). I can´t see how to use two layers as inputs in Points to Line tool.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Can you merge the two layers together and then execute the tool using the ID field?  You can easily create a model that could automate this procedure.

DanielNilsson1
New Contributor II

resulting_line.png

0 Kudos
DanielNilsson1
New Contributor II

Prefer to keep the existing layers (shape files) and only get the "line file". If I merge the data I need to create an identifier that tells the "time".

I´ll give it a try.

Thanks Jake

0 Kudos
JakeSkinner
Esri Esteemed Contributor

This should work.  The merged layer can just be intermediate data.  Ex:

Screen1.PNG

DarrenWiens2
MVP Honored Contributor

If you're dead set against creating an intermediate feature class, you can do so using Python:

>>> points1 = 'Layer1' # input layer 1
... points2 = 'Layer2' # input layer 2
... sr = arcpy.Describe(points1).spatialReference # CRS of layer 1
... lines = [] # temp line list
... dict1 = {row[1]:row[0].centroid for row in arcpy.da.SearchCursor(points1,['SHAPE@','NAME'],spatial_reference=sr)} # load layer 1 to dictionary
... dict2 = {row[1]:row[0].centroid for row in arcpy.da.SearchCursor(points2,['SHAPE@','NAME'],spatial_reference=sr)} # load layer 2 to dictionary
... for k1,v1 in dict1.iteritems(): # loop dictionary 1
...    if k1 in dict2: # see if key exists in dictionary 2
...        new_line = arcpy.Polyline(arcpy.Array([v1,dict2[k1]]),sr) # create line
...        lines.append(new_line) # add to line list
... arcpy.CopyFeatures_management(lines,r'in_memory\lines') # write lines to feature class
DanielNilsson1
New Contributor II

Thanks Jake and Darren.

I had some problems that I did not understand at first. Got out bounds and som errors. The - cause - Point ZM. Used ET Wizards to save the data as regular points insted and the problems were gone.

(could the point ZM to point be done in the model with a ArcGIS Basic licens?)

The Python script will have to wait - one step at a time. 

0 Kudos