# classic example of mutabilty in action a = ['spam', 'eggs', 100, 1234] b = a b.append("abc") print a # ['spam','eggs',100,1234,'abc'] # << note that a is altered when we only appended to b print b # ['spam','eggs',100,1234,'abc']
import arcpy infc = "C:/Pipeline" # Identify the geometry field # desc = arcpy.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = arcpy.SearchCursor(infc) featureList=[] array = arcpy.Array() point = arcpy.Point() # Build polyline list # for row in rows: feat = row.getValue(shapefieldname) partnum = 0 partcount = feat.partCount while partnum < partcount: part = feat.getPart(partnum) pnt = part.next() pntcount = 0 pntArray = arcpy.Array() while pnt: if pnt: point = arcpy.Point() point.X = pnt.X point.Y = pnt.Y point.ID = pnt.ID point.Z = pnt.Z point.M = pnt.M #Create an array of points representing a line pntArray.add(point) pnt = part.next() pntcount += 1 if not pnt: pnt = part.next() partnum += 1 #Create a master array of point arrays in order to sort them array.add(pntArray) # Sort polyline array # pLineMax = array.count dummyPoint = arcpy.Point() dummyArray = arcpy.Array() #Index for point arrays that needs comparison pLineIndex = 0 while pLineIndex < pLineMax - 1: #Index for point arrays that is a test comparison pLineIndex2 = pLineIndex + 2 while pLineIndex2 < pLineMax - 1: # Compare endpoint of line to endpoints of other lines tempPoint1 = array[pLineIndex].getObject(array[pLineIndex].count-1) tempPoint2 = array[pLineIndex2].getObject(0) tempPoint3 = array[pLineIndex2].getObject(array[pLineIndex2].count-1) # if endpoint matches another segment if str(tempPoint1) == str(tempPoint2): # Assign pointer to point array that needs to be moved pntArray = array.getObject(pLineIndex2) # Remove point array from master array array.remove(pLineIndex2) # Insert point array in the appropriate place array.insert(pLineIndex + 1, pntArray) # Exit the while loop pLineIndex2 = pLineMax pLineIndex2 += 1 pLineIndex +=1
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.