0

I have a multipoint feature class and a polyline feature class (transects) filled with the same number of objects. Basically, each set of points corresponds to a single transect.

I want to run the intersect analysis tool for each individual set of rows, so each transect and set of points should have an output. The output would be a set points that is "snapped" to the transect polyline. Then at the end of the code, I have as many intersect outputs as I do transects.

How can I get two search cursors to run simultaneously? I need a search cursor that can take one row from each file, run the intersect tool, and then move to the next set of rows.

A nested loop does not work (unsurprisingly). Is there a workaround for this?

EDIT: I don't want to compare two datasets, I actually want to analyze corresponding features of both. The formatting here didn't copy well... apologies.

# Import system modules
  import arcpy
  import numpy as np
  import sys, os, string, arcgisscripting
  arcpy.env.overwriteOutput=True

  #Define local variables
  workspace=
  transect=
  point_file=
  output_file="clusters.shp"

  sr=arcpy.Describe(point_file).spatialReference
  arcpy.env.overwriteOutput=True

  gp=arcgisscripting.create()
  output_fc=gp.CreateFeatureClass_management(workspace,output_file,     "MULTIPOINT", "#", "DISABLED", "ENABLED",sr)

 #Perform fits and intersections
 with arcpy.da.SearchCursor(transect,["SHAPE@"]) as cursor1:
     for row in cursor1:
         profile=row[0]
 with arcpy.da.SearchCursor(point_file,["SHAPE@"]) as cursor2:
     for row in cursor2:
         point=row[0]

        #Create Swath Profile
        clusterTolerance=0.5
          swath_points=arcpy.Intersect_analysis([point,profile],output_fc,"",clusterTolerance,"point")
  • 2
    If you have the capacity, store them both to memory using dictionaries. – JamesLeversha Feb 2 '17 at 0:20
  • Or load one into a dictionary and just iterate through the other. – PolyGeo Feb 2 '17 at 1:16
  • 1
    It's not clear that cursors are the appropriate solution, but there is no reason that multiple cursors can't be instantiated (though the implementation will be less Pythonic). Please provide an MCVE of your non-working code. – Vince Feb 2 '17 at 1:41
  • Dictionaries are a possibility but these are large datasets. Unsure as to whether that's an efficient solution, although I'll try it if there's no other options. Vince - is there another way to call a shape geometry from a feature class? – JCH Feb 2 '17 at 18:00
0

I was able to solve my problem by adding all geometry objects to lists and then iterating. Unfortunately, the hierarchy used by Intersect Analysis didn't apply to the geometry object. To get the tool to successfully recognize type priority I had to temporarily save the objects in feature classes. Clunky but a working code.

#copy geometries into lists
line_obj=[]
with arcpy.da.SearchCursor(transect,["SHAPE@"]) as cursor1:
    for row1 in cursor1:
        profile=row1[0]
        line_obj.append(profile)

point_obj=[]
with arcpy.da.SearchCursor(point_file,["SHAPE@"]) as cursor2:
    for row2 in cursor2:
        multipoint=row2[0]
        point_obj.append(multipoint)

#calculate intersections
loop_sze=len(line_obj)
all_geom=[]
for n in range(0,loop_sze):
    #Isolate relevant objects
    profile=line_obj[n]
    point=point_obj[n]
    arcpy.CopyFeatures_management(profile,output_line)
    arcpy.CopyFeatures_management(point,output_point)
   arcpy.Intersect_analysis([output_point,output_line],output_snap,"ALL","0.5 Meters","")
    with arcpy.da.SearchCursor(output_snap,["SHAPE@"]) as cursor:
        for row in cursor:
            all_geom.append(row[0])

arcpy.CopyFeatures_management(all_geom,output_total)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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