Hi all
I am stuck with how to loop through a folder containing numerous text files containing lat and long values. The idea is to open a text file, create an XY layer and then append the result into a layer within a geodatabase. I can do the following which takes a single text file, creates the xy layer and then appends this xy layer to the geodatabase layer:
# XYTableToPoint.py
# Description: Creates a point feature class from input table
# import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = r"C:\Projects\points\test.gdb"
# Set the local variables
in_table = r"D:\points\split_data\file_1.txt"
out_feature_class = "file1"
x_coords = "field7"
y_coords = "field6"
z_coords = ""
# Make the XY event layer...
arcpy.management.XYTableToPoint(in_table, out_feature_class,x_coords, y_coords, z_coords,
arcpy.SpatialReference(4326))
# Print the total rows
print(arcpy.GetCount_management(out_feature_class))
arcpy.management.Append("file1", r"C:\Projects\points\test.gdb\all_Points", "NO_TEST", 'id "id" true true false 25 Text 0 0,First,#,file1,Field1,0,8000;individualCount "individualCount" true true false 15 Text 0 0,First,#,file1,Field2,0,8000;year "year" true true false 4 Long 0 0,First,#,file1,Field3,-1,-1;month "month" true true false 2 Short 0 0,First,#,file1,Field4,-1,-1;country "country" true true false 255 Text 0 0,First,#,file1,Field5,0,8000;decimalLatitude "decimalLatitude" true true false 8 Double 0 0,First,#,file1,Field6,-1,-1;decimalLongitude "decimalLongitude" true true false 8 Double 0 0,First,#,file1,Field7,-1,-1;Name "Name" true true false 100 Text 0 0,First,#,file1,Field8,0,8000', '', '')
This works fine but this would be tedious to do edit and rerun manually for each file (potentially over a 1000 files).
Any advice most welcome.
Mark
Solved! Go to Solution.
Hi David
I finally managed to get this working. I needed to modify the following lines
out_fc = os.path.join("in_memory",name) this doesn't work so changed to
out_fc = os.path.join(r"memory",name)
arcpy.Merge(path_list,merged_fc)
this doesn't work so changed to
arcpy.management.Merge(path_list,merged_fc) Many thanks for your assistance! Best, Mark
Just for reference, the old style of calling geoprocessing tools like Merge was:
arcpy.Merge_management()
and the new style is:
arcpy.management.Merge()
Both styles have worked since the beginning, but Esri is now focusing/transitioning more to the "new" style, which is definitely more Pythonic.
Mark Balman, have any of the suggestions helped?