Skip to content

Instantly share code, notes, and snippets.

@srkirkland
Last active November 4, 2020 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srkirkland/0c30412b9387f316986243359cb7cf76 to your computer and use it in GitHub Desktop.
Save srkirkland/0c30412b9387f316986243359cb7cf76 to your computer and use it in GitHub Desktop.
convert and merge csv in arcgis
import arcpy
import pandas as pd
import os
import re
homepath=r"C:\Users\postit\Downloads\testing"
output_path = os.path.join(homepath,"features")
arcpy.env.workspace = output_path
if not os.path.exists(output_path):
os.makedirs(output_path)
for file in os.listdir(homepath):
# if file ends with csv, process it
regex = re.search('^(.*)(\.\w*)$', file)
if regex != None and regex.group(2) == '.csv':
fileName = regex.group(1)
print('processing: ' + file)
in_table = os.path.join(homepath,file)
out_feature_class = fileName
# TODO what coords do we want to use, landing or center?
x_coords = "landing_lng"
y_coords = "landing_lat"
z_coords = "landing_elevation"
# Make the XY event layer...
arcpy.management.XYTableToPoint(in_table, out_feature_class,
x_coords, y_coords, z_coords)
print('All Done')
import arcpy
import os
# location of all features in one folder
mainLoc=r"C:\Users\postit\Downloads\testing\features"
output_path = os.path.join(mainLoc, "combined")
if not os.path.exists(output_path):
os.makedirs(output_path)
arcpy.env.workspace = mainLoc
fcs = arcpy.ListFeatureClasses()
print(fcs)
if len(fcs) > 0:
arcpy.Merge_management(fcs, os.path.join(output_path, "all_features"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment