Я сам разбираюсь.Почему вы дали мне отрицательный голос?
import os
import datetime
import zipfile
arcpy.CheckOutExtension('Spatial')
# adjust your filepath
filepath = r'E:/Southern_Kentucky/'
# setting up the environment
arcpy.env.workspace = filepath
#creating the list from the .txt file
def creating_tile_list():
filepath_l = r"E:/Southern_Kentucky/Kentucky_South_Tiles.txt"
# divide to lines, lines to items(elements)
# fill the lists with tile_number
tile_list = []
with open(filepath_l) as f_obj:
for line in f_obj:
line_elements = line.split(',')
tile_list.append(line_elements[2])
tile_list = set(tile_list)
tile_list = sorted(tile_list)
tile_list = tile_list[:-1]
print("tile count: " + str(len(tile_list)))
return tile_list
# finding tiles with null values
def error_tiles(tile_number):
os.chdir(filepath)
outIsNull = arcpy.sa.IsNull(filepath + tile_number + '_DEM_DSM.img')
rows = arcpy.SearchCursor(outIsNull, "", "", "VALUE; COUNT", "")
for r in rows:
v = r.getValue("VALUE")
c = r.getValue("COUNT")
if v == 1 and c > 0:
with open(filepath + 'Error_Tiles_List_South.txt', 'a') as f_obj:
f_obj.writelines(tile_number + '\n')
print(str(n) + ". tile: *******" + tile_number + " ******* has NULL value")
else:
pass
# decompressing zip files
def zip_to_img_dem_dsm(tile_number):
os.chdir(r'E:/Kentucky_DSM/')
zip_DEM_DSM = zipfile.ZipFile(filepath + tile_number + '_DEM_DSM.zip', 'r')
zip_DEM_DSM.extractall(r'E:/Southern_Kentucky/')
zip_DEM_DSM.close()
# deleting decompressed images
def delete_deflated(tile_number):
arcpy.Delete_management(tile_number + "_DEM_DSM.img")
arcpy.Delete_management(tile_number + "_DEM_DSM.img.aux.xml")
arcpy.Delete_management(tile_number + "_DEM_DSM.img.xml")
# Listing tiles and downloading them
all_tiles = creating_tile_list()
n = 0
for tile_number in all_tiles:
try:
if tile_number:
zip_to_img_dem_dsm(tile_number)
print(str(n) + ". tile: *******" + tile_number + " ******* file deflated")
error_tiles(tile_number)
print(str(n) + ". tile: *******" + tile_number + " ******* checked")
delete_deflated(tile_number)
print(str(n) + ". tile: *******" + tile_number + " ******* deflated files deleted")
print('Tile Succesful Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()))
n += 1
else:
pass
except OSError:
print('OS_ERROR >>>>>> Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()))
continue
except RuntimeError:
print('RuntimeError >>>>>> Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()))
continue
except StandardError:
print('StandardError >>>>>> Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()))
continue