Good morning.
I'm trying to create a OD matrix shapefile using Python. I can't use Network Analyst since I am using about 3100 Origin points and Destiny points. What I want is just the line shapefile, I don't care about distance or time travels.
I have used a script I found in this thread: https://community.esri.com/t5/data-management-questions/is-there-a-way-to-connect-all-points-in-a/td-p/367939
While it works and I have my OD matrix, it has no data from the centroids, and then preparing the data for the analysis I'm working I find the problem that spatial join with the centroids to enrich data generates two flows from point 1 to point 9 instead a flow from 1-9 and the other one to 9-1.
What I thought is to directly enrich the data in the step that creates the lines, so I can have a column with the name of the origin centroid and another one with the name of the destination centroid.
In my case, the fields I want to add to the OD matrix are called 'ID_GRUPO','SUM_POB_AS','NOMBRE_CEL'. I tried this script but the result I got is again a OD matrix with just a field called ID which has always a value 0.
fc = 'celdas_centroids' # feature class
sr = arcpy.Describe(fc).spatialReference # spatial reference
lines = [] # output line list
geoms = [i[0] for i in arcpy.da.SearchCursor(fc,['SHAPE@','ID_GRUPO','SUM_POB_AS','NOMBRE_CEL'],spatial_reference=sr)] # point geometries
for geom1 in geoms: # loop through points
for geom2 in geoms: # compare to points
lines.append(arcpy.Polyline(arcpy.Array([[geom1.centroid,geom2.centroid]]),sr)) # create line
arcpy.CopyFeatures_management(lines,r'F:\matriz_celdas_od.shp') # output to feature class
Thank you very much for the help.