def main(): try: import arcpy, sys, traceback polygon = r"C:\tmp\Test.gdb\PolygonWithInnerRings" txtFile = open(r"C:\tmp\PolygonToTXT.txt","w") headerLine = (", ").join(["VertObjID", "X", "Y", "InRing"]) txtFile.write(headerLine + "\n") rows = arcpy.SearchCursor(polygon) for row in rows: feature = row.SHAPE #get the geometry into variable featureID = row.OBJECTID #adjust this if not in geodatabase partNum = 0 #feature can have multiple parts - first goes iteration through parts for featurePart in feature: part = feature.getPart(partNum) #the output is Array of points isInnerRing = "0" linesLst = [] #iterate through points for pnt in part: if pnt: vertexLine = (", ").join([str(featureID), str(pnt.X), str(pnt.Y), isInnerRing]) linesLst.append(vertexLine) else: isInnerRing = "1" linesLst.append("InRing") #remove duplicated point and write to file linesLst.pop(linesLst.index("InRing")-1) for line in linesLst: if line != "InRing": txtFile.write(line + "\n") partNum += 1 del rows, row txtFile.close() except: print arcpy.GetMessages() # Get the traceback object tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] # Concatenate information together concerning the error into a # message string pymsg = tbinfo + "\n" + str(sys.exc_type)+ ": " + str(sys.exc_value) # Return python error messages for use with a script tool arcpy.AddError(pymsg) # Print Python error messages for use in Python/PythonWin print pymsg if __name__ == '__main__': main()
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.