AnsweredAssumed Answered

Linear Events and Select By Location

Question asked by wmarcell on May 29, 2013
Latest reply on May 31, 2013 by wmarcell
I am working on a script to check some linear events at my current job.  I have been having some issues, and it is frustrating because the process I am attempting would work for regular features, and works when you manually run it through GIS, but it does not work programatically in python.  FYI I am using ArcGIS 10.0 for this process.

Basically I am attempting to check two fields "From_Milepost" and "To_Milepost" to ensure that the events are going from low to high (M values should work also).  My problem is that for our workflow, we are only checking events that fall withing a certian division of the data.  Our SDE data often includes several divisions, so I am attempting a SBL before checking the Milepost values.

Here is a list of the different things I have attempted:

1. Select By Location (Linear event that falls within division) > Check that Milepost order is correct
    Result: Count on linear event is 140 (expected) when run through the check MP order section only four features are processed.

2. Select By Location > Create Feature Layer > Check MP order is correct
    Result: Count on linear event is 140 (expected) when run through the check MP order section only four features are processed.

3. Select By Location > Create Table View > Check MP order is correct
    Result: Count (6612) does not match, selection ignored when creating Table view
    All events are processed through MP loop (6612 records)

4. Select By Location > Create Feature Layer > Create Table View > Check MP order loop
    Results: Count of Feature layer 140, count of Table view 6612, all 6612 records looped through

And finally this workflow works, but not as I would like it to (OID's not retained, my data does not have unique identifiers)
5. Select by location > Copy Features management > Loop through MP check section
    Results: Count matches, only 140 features looped through.  OIDs renumbered 1-140

I have attached code below with the above numbered and commented out.  If anyone can help it would be appreciated.  What I am hoping is to get the 140 selected events to go through the loop.  I would like to retain the OID's if at all possible.  If there is a way to do this without creating Table views/feature layers that is great.  If there is a way to retain the original OID's when you run the CopyFeatures_management that would also be great.  My last idea is to create a FGDB and only write the errors to a feature class.  This would allow the user to zoom to the area and find the feature.  Retaining OID's however would be the best solution.  Any feedback is greatly appreciated.  I do not have much experience using Event Layers, and have even less experience attempting to program python using events.

Here is some delicious code goodness!!!
import arcpy from arcpy import mapping from arcpy import env  arcpy.env.overwriteOutput = True SUBDIVISION = "NCS_SUB_CODE_EVT Events" OPCODE = "NCS_OP_CODE_EVT Events"  ##Check MP Order NCS_OP_CODE_EVT arcpy.AddMessage("***Checking MP order - NCS_OP_CODE_EVT***") arcpy.SelectLayerByLocation_management(OPCODE, "INTERSECT", SUBDIVISION, "", "NEW_SELECTION")  ######1. This will run a loop on the data.  Count matches, but only four results are looped through#### ##arcpy.AddMessage("OPCODE = " + str(arcpy.GetCount_management(OPCODE))) ##rows = arcpy.SearchCursor(OPCODE)  ######2. This creates Feature Layer and then loops through.  Counts match, only four records looped#### ##arcpy.MakeFeatureLayer_management(OPCODE, "OPCODE_F") ##arcpy.AddMessage("OPCODE_FeatureLyr Count = " + str(arcpy.GetCount_management("OPCODE_F"))) ##rows = arcpy.SearchCursor("OPCODE_F")  ####3. This creates a Table View and then loops.  Counts match only four records looped#### ##arcpy.MakeTableView_management(OPCODE, "OPCODE_T") ##arcpy.AddMessage("OPCODE_TblView Count = " + str(arcpy.GetCount_management("OPCODE_T"))) ##rows = arcpy.SearchCursor("OPCODE_T")  ####4. This will combine above.  Create Feature Layer then send to Table view, then loop#### ##arcpy.MakeFeatureLayer_management(OPCODE, "OPCODE_F") ##arcpy.MakeTableView_management("OPCODE_F", "OPCODE_T") ##arcpy.AddMessage("OPCODE_FeatureLyr Count = " + str(arcpy.GetCount_management("OPCODE_F"))) ##arcpy.AddMessage("OPCODE_TblView Count = " + str(arcpy.GetCount_management("OPCODE_T"))) ##rows = arcpy.SearchCursor("OPCODE_T")  ####5. Copy features out.  Does not retain OID's arcpy.CopyFeatures_management(OPCODE, "OPCODE_SEL") arcpy.AddMessage(arcpy.GetCount_management("OPCODE_SEL")) rows = arcpy.SearchCursor("OPCODE_SEL")  for row in rows:         MP = (row.To_Milepost - row.From_Milepost)         arcpy.AddMessage("OID = " + str(row.OBJECTID) + " MP = " + str(MP))         if MP < 0:             arcpy.AddMessage("ObjectID: " + str(row.OBJECTID)+ " has decreasing Mileposts")