try: # Open an insert cursor for the new feature class # cur = arcpy.InsertCursor(fcname) # Create an array and point object needed to create features # lineArray = arcpy.Array() pnt = arcpy.Point() # Initialize a variable for keeping track of a feature's ID. # ID = -1 for line in coordList: # Open the input file # set the point's ID, X and Y properties # FeatID, pnt.ID, pnt.X, pnt.Y = string.split(line,",") print FeatID, pnt.ID, pnt.X, pnt.Y if ID == -1: ID = pnt.ID FeatID_load = FeatID # Add the point to the feature's array of points # If the ID has changed, create a new feature # #print ID, pnt.ID if ID != pnt.ID: # Create a new row or feature, in the feature class # feat = cur.newRow() feat.setValue("OW_ID", FeatID) # Set the geometry of the new feature to the array of points # feat.shape = lineArray # Insert the feature # cur.insertRow(feat) lineArray.removeAll() lineArray.add(pnt) ID = pnt.ID FeatID_load = FeatID # Add the last feature # feat = cur.newRow() feat.setValue("OW_ID", FeatID_load) feat.shape = lineArray cur.insertRow(feat) lineArray.removeAll() del cur except Exception as e: print e.message
try: # Open an insert cursor for the new feature class # cur = arcpy.InsertCursor(fcname) # Create an array and point object needed to create features # lineArray = arcpy.Array() pnt = arcpy.Point() # Initialize a variable for keeping track of a feature's ID. # ID = -1 for line in coordList: # Open the input file # set the point's ID, X and Y properties # pnt.ID, pnt.X, pnt.Y = string.split(line,",") #print pnt.ID, pnt.X, pnt.Y if ID == -1: ID = pnt.ID # Add the point to the feature's array of points # If the ID has changed, create a new feature # #print ID, pnt.ID if ID != pnt.ID: # Create a new row or feature, in the feature class # feat = cur.newRow() # Set the geometry of the new feature to the array of points # feat.shape = lineArray # Insert the feature # cur.insertRow(feat) lineArray.removeAll() lineArray.add(pnt) ID = pnt.ID # Add the last feature # feat = cur.newRow() feat.shape = lineArray cur.insertRow(feat) lineArray.removeAll() del cur except Exception as e: print e.message
try: # Open an insert cursor for the new feature class # cur = arcpy.InsertCursor(fcname) # Create an array and point object needed to create features # lineArray = arcpy.Array() pnt = arcpy.Point() # Initialize a variable for keeping track of a feature's ID. # ID = -1 for line in coordList: # Open the input file # set the point's ID, X and Y properties # FeatID, pnt.ID, pnt.X, pnt.Y = string.split(line,",") print FeatID, pnt.ID, pnt.X, pnt.Y if ID == -1: ID = pnt.ID # Add the point to the feature's array of points # If the ID has changed, create a new feature # #print ID, pnt.ID if ID != pnt.ID: # Create a new row or feature, in the feature class # feat = cur.newRow() feat.setValue("OW_ID", FeatID) # Set the geometry of the new feature to the array of points # feat.shape = lineArray # Insert the feature # cur.insertRow(feat) lineArray.removeAll() lineArray.add(pnt) ID = pnt.ID # Add the last feature # feat = cur.newRow() feat.setValue("OW_ID", FeatID) feat.shape = lineArray cur.insertRow(feat) lineArray.removeAll() del cur except Exception as e: print e.message
IDLE 2.6.5 >>> import arcpy >>> coordList = ['10953.36724322,20031.2536665', '10997.81733525,20052.4203769', '10993.08806586,20039.092436', '10948.63797384,20017.9257255', '10953.36724322,20031.2536665'] >>> array = arcpy.Array() >>> point = arcpy.Point() >>> featureList = [] >>> for each in coordList: XYpair = each.split(',') point.X = XYpair[0] point.Y = XYpair[1] featureList.append(point) array.add(point) >>> array.add(featureList[0]) >>> polygon = arcpy.Polygon(array) >>> arcpy.CopyFeatures_management(polygon, r'C:\testCopyPoly.shp') <Result 'C:\\testCopyPoly.shp'>
for each in coordList: XYpair = each.split(',') pnt.X = XYpair[0] pnt.Y = XYpair[1] # load pnt object into array, etc.
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.