4

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__
    self.set_hub_attributes(self.hublayer.currentText())
  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

GeorgeC
  • 8,228
  • 7
  • 52
  • 136
  • 1
    This is one of those rare times when I can think of a way to do this in MapInfo but not in ESRI or QGIS. That script would be the way to go if it worked. What is the exact error you're getting in 10.2? – Fezter Feb 27 '14 at 06:54
  • Do you have access to Business Analyst? You could try this: http://resources.arcgis.com/en/help/main/10.2/index.html#//000z00000043000000 – Fezter Feb 27 '14 at 06:58
  • Or ET Geowizards: http://www.ian-ko.com/. Looks like there's a function there which could work. – Fezter Feb 27 '14 at 07:00
  • Mapinfo would be fine as well... – GeorgeC Feb 27 '14 at 07:00
  • MapInfo has a distance tool: http://www.pbinsight.com/support/education/video-tutorials/detail/distance-calculation/. It's in the Tool Manager. – Fezter Feb 27 '14 at 07:00
  • For the crux of the Question, if ArcGIS is preferred, I would use 2 x arcpy.da.SearchCursor to read the two input point feature classes and an arcpy.da.InsertCursor to write the output line feature class. I think the coordinate system issues should be dealt with in a separate Question. – PolyGeo Feb 27 '14 at 07:04
  • We don't have business analyst. One issue is that the points are across the 54S and 55S boundary and I am using GDA94 but then arcgis won't Calculate Geometry of the line as it's Geographic. I looked at ET Geowizards but can't find an appropriate tool. The Mapinfo distance tool suggested does the same as the point distance tool. – GeorgeC Feb 27 '14 at 23:09
  • I have posted the coord system issue to http://gis.stackexchange.com/questions/88025/calculate-length-of-line-across-zones-with-at-least-m-accuracy – GeorgeC Feb 28 '14 at 00:57

3 Answers3

1

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.Delete_management(outLines)
arcpy.CreateFeatureclass_management(os.path.dirname(outLines), os.path.basename(outLines),"POLYLINE","","","",SR1)
arcpy.AddField_management(outLines,'DISTANCE','DOUBLE')

# 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 
phloem
  • 4,678
  • 15
  • 30
1

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

enter image description here

Nathan W
  • 34,706
  • 5
  • 97
  • 148
  • thanks but the 2 tools are giving errors. See updated q. Do you know what I should do to fix this? – GeorgeC Feb 27 '14 at 22:58
0

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)

klewis
  • 7,475
  • 17
  • 19