I have 2 point datasets and want a tool or script to draw a line between all points in one dataset to all the points in the 2nd dataset. Is it possible? I have tried ESRI "Point Distance" and "Generate near Table" but these just give me a table of points. I need to also calculate the distance between the points and this is between MGA Zone 55S and 54S

enter image description here

I checked How to write a script that will automatically draw lines from one point to multiple destination points? (ArcMap 9.3) and tried the arcgis 10 tool but it gives me write errors in ArcGIS 10.2

An ESRI or QGIS solution is fine.

-- The MMQGIS looks perfect but I have a python error. I am using Ver 2.0.1 on a Win 7 Enterprise.

An error has occured while executing Python code:

Traceback (most recent call last):
  File "C:\Users\georgec/.qgis2/python/plugins\mmqgis\mmqgis_menu.py", line 299, in hub_lines
    dialog = mmqgis_hub_lines_dialog(self.iface)
  File "C:\Users\georgec/.qgis2/python/plugins\mmqgis\mmqgis_dialogs.py", line 1397, in __init__
  File "C:\Users\georgec/.qgis2/python/plugins\mmqgis\mmqgis_dialogs.py", line 1411, in set_hub_attributes
    for index, field in enumerate(layer.dataProvider().fields()):
AttributeError: 'NoneType' object has no attribute 'dataProvider'

Python version:
2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]

QGIS version:
2.0.1-Dufour Dufour, d94c044

Python path: ['C:/OSGEO4~1/apps/qgis/./python/plugins\\processing', 'C:/OSGEO4~1/apps/qgis/./python', 'C:\\Users\\georgec/.qgis2/python', 'C:\\Users\\georgec/.qgis2/python/plugins', 'C:/OSGEO4~1/apps/qgis/./python/plugins', 'C:\\INTERG~1\\ERDASI~1\\usr\\lib\\Win32Release\\python', 'C:\\OSGEO4~1\\bin\\python27.zip', 'C:\\OSGEO4~1\\apps\\Python27\\DLLs', 'C:\\OSGEO4~1\\apps\\Python27\\lib', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\plat-win', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\lib-tk', 'C:\\OSGEO4~1\\bin', 'C:\\OSGEO4~1\\apps\\Python27', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\PIL', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\win32', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\Shapely-1.2.18-py2.7-win-amd64.egg', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\six-1.3.0-py2.7.egg', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\xlrd-0.9.2-py2.7.egg', 'C:\\OSGEO4~1\\apps\\Python27\\lib\\site-packages\\xlwt-0.7.5-py2.7.egg', 'C:\\OSGEO4~1\\apps\\qgis\\python\\plugins\\fTools\\tools', 'C:\\Users\\georgec\\.qgis2\\python\\plugins\\mmqgis/forms']

I have moved the projection issue to Calculate length of line across zones with at least m accuracy


3 Answers 3


Here's a fairly bare-bones python script that connects all combinations of two input point files, and outputs lines with distance attribute. It follows directly from PolyGeo's comment under OP. Note: I've heard horror stories of nesting cursors, but it seems to work in this case.

# import arcpy
import arcpy, os

# set input/output parameters
points1 = arcpy.GetParameterAsText(0)    # input points1 feature class
points2 = arcpy.GetParameterAsText(1)    # input points2 feature class
outLines = arcpy.GetParameterAsText(2)   # output lines

# get spatial references
desc1 = arcpy.Describe(points1)
SR1 = desc1.spatialReference
desc2 = arcpy.Describe(points2)
SR2 = desc2.spatialReference

# set up output file
if arcpy.Exists(outLines):
arcpy.CreateFeatureclass_management(os.path.dirname(outLines), os.path.basename(outLines),"POLYLINE","","","",SR1)

# create insert cursor
cursor = arcpy.da.InsertCursor(outLines, ['SHAPE@','DISTANCE'])

# loop through points, add to output lines
for point1 in arcpy.da.SearchCursor(points1, ["SHAPE@"], "", SR1):
    for point2 in arcpy.da.SearchCursor(points2, ["SHAPE@"], "", SR2):
        cursor.insertRow([arcpy.Polyline(arcpy.Array([point1[0].centroid, point2[0].projectAs(SR1).centroid]),SR1), point1[0].distanceTo(point2[0].projectAs(SR1))])
    del point2
del point1 

In QGIS you can use the MMQGIS plugin and use the Hub Distance option, or the Hub Line tool.

enter image description here

  • thanks but the 2 tools are giving errors. See updated q. Do you know what I should do to fix this?
    – GeorgeC
    Feb 27, 2014 at 22:58

The following steps will generate Lines from one Point layer to another Point layer:

Run "Add XY Coordinates" on each Point feature class. (Basic license)
Run "Point Distance", select Input Pts and Near Pts, producing a table (Advanced License)
Join the table to Input FC
Join the table to Near FC
Run "XY to Line" (Basic license)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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