I am trying desperately to grab records in a shapefile's attribute table and copy them, with additional formatting to a txt file. Below is the code I have developed thus far:
I have used the following post (Using SearchCursor to access & export values in a raster table) for guidance but for some reason python has issues with my declared output file, f.
# Import arcpy and the SeachCursor functionimport arcpy# Find the target shapefile in memoryshapefile = "C:/Users/user/Dropbox/CE 691/GI/GISData/ExampleEPANETNetwork.mdb/Nodes"# Create the Text File to write the Indicated Valuesf = open("C:/Users/user/Desktop/test.txt", "w")# Use SearchCursor to Identify the necessary fieldsfind_junction = arcpy.SearchCursor(shapefile, "", "", "Elevation;Demand;X_Coord;Y_Coord","")# Convert Found Field to Text and Place in Text Filefor row in find_junction: get_elevation = row.getValue("Elevation") get_demand = row.getValue("Demand") get_x_coord = row.getValue("X_Coord") get_y_coord = row.getValue("Y_Coord") print get_elevation, get_demand, get_x_coord, get_y_coord f.write(str(get_elevation + " " + get_demand + " " + get_x_coord + " " + get_y_coord)# Close the output text filef.close()# Delete all variables utilizeddel find_junction, get_elevation, get_demand, get_x_coord, get_y_coordAny advice would be very much appreciated!
Thanks!
أكثر...
I have used the following post (Using SearchCursor to access & export values in a raster table) for guidance but for some reason python has issues with my declared output file, f.
# Import arcpy and the SeachCursor functionimport arcpy# Find the target shapefile in memoryshapefile = "C:/Users/user/Dropbox/CE 691/GI/GISData/ExampleEPANETNetwork.mdb/Nodes"# Create the Text File to write the Indicated Valuesf = open("C:/Users/user/Desktop/test.txt", "w")# Use SearchCursor to Identify the necessary fieldsfind_junction = arcpy.SearchCursor(shapefile, "", "", "Elevation;Demand;X_Coord;Y_Coord","")# Convert Found Field to Text and Place in Text Filefor row in find_junction: get_elevation = row.getValue("Elevation") get_demand = row.getValue("Demand") get_x_coord = row.getValue("X_Coord") get_y_coord = row.getValue("Y_Coord") print get_elevation, get_demand, get_x_coord, get_y_coord f.write(str(get_elevation + " " + get_demand + " " + get_x_coord + " " + get_y_coord)# Close the output text filef.close()# Delete all variables utilizeddel find_junction, get_elevation, get_demand, get_x_coord, get_y_coordAny advice would be very much appreciated!
Thanks!
أكثر...