I modified the code a bit but after a few cycles in zip files loop it ended with an memory error. I think that it is not deleting sources...
import zipfile
import os
import arcpy
import datetime
dirPath = "C:/Workspace/Data/LIDAR/"
outputFileGdb = "C:/Workspace/Data/SampleLidarPoints.gdb/"
if (not arcpy.Exists(outputFileGdb + "lidarPoints")):
arcpy.CreateFeatureclass_management(outputFileGdb, "lidarPoints", "POINT", "", "DISABLED", "ENABLED")
fileInDirList = os.listdir(dirPath)
for file in fileInDirList:
if file.endswith(".zip"):
z = zipfile.ZipFile(dirPath + file, "r")
for filename in z.namelist():
if filename.endswith(".xyz"):
print datetime.datetime.now()
print "Start process " + filename
f = z.open(filename, 'r')
content = f.read()
f.close()
lines = content.splitlines(True)
tempFC = arcpy.CreateFeatureclass_management("in_memory", "tempLidarPoints", "POINT", "", "DISABLED", "ENABLED")
for line in lines:
if not "-999.999" in line:
try:
point = line.split(" ")
esriPoint = arcpy.Point()
esriPoint.X = float(point[0].strip())
esriPoint.Y = float(point[1].strip())
esriPoint.Z = float(point[2].strip())
cur = arcpy.InsertCursor(tempFC)
row = cur.newRow()
row.shape = esriPoint
cur.insertRow(row)
del cur, row
except Exception as e:
print e
arcpy.Append_management(tempFC, outputFileGdb + "lidarPoints")
arcpy.DeleteFeatures_management(tempFC)
arcpy.Delete_management(tempFC)
arcpy.Delete_management("in_memory")
print datetime.datetime.now()
print "Points added"
Please, what do you think??