I try to monitor the folder using the Watch Dog library, if the images are downloaded the code applies three processes:
1- Move images to the destination folder
1- extract compressed images
2-add raster to mosaic data set
- but when calling the function using arc py to add raster to the mosaic dataset in the function watch folder it stops without describing the error and gets the message window "application has stopped working"
- when calling the function to add a raster to the mosaic dataset alone with the same parameter run success
Code:
def addRasterToMosaicDataset(filePath
, nameFolder
,MD):
pathToadd=
f'{filePath
}\\{nameFolder
}'
print(
f'pathaddraster :{pathToadd
}\n\n')
count =
0
listXml = []
for dirpath
, dirnames
, filenames
in os.walk(pathToadd):
# print(f" dirpath: {dirpath} \n dirnames: {dirnames} \n filenames:{filenames}")
for file
in filenames:
if file.startswith(
'DIM'😞count +=
1
# print(f"numberfile :{count} \n file>>> {file} \n")
rasterXML =
f'{dirpath
}\\{file
}'
print(
f'raster xml {rasterXML
} \n \n ............................')
name = file[
14:
22]
# print(f"Name of raster : {file}, {name} \n")
# print(rasterXML)
listXml.append(rasterXML)
if len(listXml) >
0:
print(
f"list number item : {len(listXml)
} \n {listXml
} \n \n ")
try:
print(
f'{MD
} \n {listXml
} \n')
# Process: Add Rasters To Mosaic Dataset (Add Rasters To Mosaic Dataset) (management)Pleiades_5_
Pleiades2023 =arcpy.management.AddRastersToMosaicDataset(
in_mosaic_dataset=MD
, raster_type=
"Pleiades-1",
input_path=listXml
,
update_cellsize_ranges=
"UPDATE_CELL_SIZES",
update_boundary=
"UPDATE_BOUNDARY",
update_overviews=
"NO_OVERVIEWS",
maximum_pyramid_levels=
None, maximum_cell_size=
0,
minimum_dimension=
1500, spatial_reference=
"",
filter=
"*DIM_*.xml;*PHRDIMAP.xml", sub_folder=
"SUBFOLDERS",
duplicate_items_action=
"ALLOW_DUPLICATES",
build_pyramids=
"",
calculate_statistics=
"",
build_thumbnails=
"NO_THUMBNAILS", operation_description=
"",
force_spatial_reference=
"NO_FORCE_SPATIAL_REFERENCE",
estimate_statistics=
"ESTIMATE_STATISTICS", aux_inputs=[]
,
enable_pixel_cache=
"NO_PIXEL_CACHE",
cache_location=
"")[
0]
except:
error= arcpy.GetMessage()
print(
"error................................" , '\n', error)
listXml.clear()
def watchMove(path_to_track
, path_distantion
,outextract
,MDS):
class handler(FileSystemEventHandler):
print(
f'Work Event \n \n ')
def on_modified(
self, event):
for filename
in os.listdir(path_to_track):
src=path_to_track +
"\\" + filename
print(
"\n", src
, "\n")
file_dsit = path_distantion +
"\\" + filename
# os.rename(src , file_dsit)
print(
"\n", file_dsit
, "\n")
filenamewWX = filename.split(
'.')
nameXml = filenamewWX[
0]
if not is_file_open(src):
# File copying is complete, proceed with moving the file
shutil.move(src
, file_dsit)
print(
f"Moved file: {file_dsit
}")
extractFiles(file_dsit
, outextract)
print(
f".......................Done.ExtractFiles..............................")
addRasterToMosaicDataset(outextract
, nameXml
, MDS)
else:
# File is still being written, skip moving for now
print(
f"File still being written: {src
}")
observ = Observer()
eventHandler = handler()
observ.schedule(eventHandler
, path_to_track
, recursive=
True)
observ.start()
print(
f'Work Event start \n \n ')
try:
while True:
print(
f'Timer \n \n ')
time.sleep(
60)
except KeyboardInterrupt:
observ.stop()
observ.join()