-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateCERES_large_pres.py
More file actions
79 lines (66 loc) · 2.73 KB
/
UpdateCERES_large_pres.py
File metadata and controls
79 lines (66 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import arcpy
import os
import glob
from datetime import datetime
from time import sleep
import numpy as np
# %%
prj_path = ""
prj_file = ""
WS_folder = ""
NDVI_folder = ""
output_path = ''
aprx = arcpy.mp.ArcGISProject(prj_path + prj_file)
maps = aprx.listMaps()
layout = aprx.listLayouts('Layout1')[0]
mapFrames = np.array(layout.listElements(element_type = 'MAPFRAME_ELEMENT'))
names = [mf.name for mf in mapFrames]
WS_names = ['WS' in name for name in names]
NDVI_names = ['NDVI' in name for name in names]
WS_mf = mapFrames[WS_names]
NDVI_mf = mapFrames[NDVI_names]
fieldCode = input('Enter field code: ').upper()
# grab eight most recent files
WS_files = [os.path.basename(x) for x in glob.glob(prj_path + WS_folder + '\\Grapery_' + fieldCode + '*.tif')]
WS_files.sort(reverse = True)
WS_files = WS_files[:8]
# grab eight most recent files (MC changed wildcard to eliminate _)
NDVI_files = [os.path.basename(x) for x in glob.glob(prj_path + NDVI_folder + '\\Grapery_' + fieldCode + '*.tif')]
NDVI_files.sort(reverse = True)
NDVI_files = NDVI_files[:8]
print("Pulling most recent images..."); sleep(3)
# ws (MC changed layer number from 0 to 2 due to irr zone layer present in maps)
for mapFrame, file in zip(WS_mf, reversed(WS_files)):
map = mapFrame.map
print(file)
lyr = map.listLayers()[2]
#print(lyr)
cp = lyr.connectionProperties
cp['connection_info']['database'] = prj_path + WS_folder
cp['dataset'] = file
lyr.name = file
# change map name using map.name = <date_of_image>
# grab image date by parsing image title
map.name = datetime.strptime(file.split('_')[2], '%Y-%m-%d').strftime('%b %d')
lyr.updateConnectionProperties(lyr.connectionProperties, cp)
# 'zooms' to extent of new layer in map frame
mapFrame.camera.setExtent(mapFrame.getLayerExtent(lyr, False, False))
# ndvi (MC changed layer number from 0 to 2 due to irr zone layer present in maps)
for mapFrame, file in zip(NDVI_mf, reversed(NDVI_files)):
map = mapFrame.map
print(file)
lyr = map.listLayers()[2]
#print(lyr)
cp = lyr.connectionProperties
cp['connection_info']['database'] = prj_path + NDVI_folder
cp['dataset'] = file
lyr.name = file
# change map name using map.name = <date_of_image>
# grab image date by parsing image title
map.name = datetime.strptime(file.split('_')[2], '%Y-%m-%d').strftime('%b %d')
lyr.updateConnectionProperties(lyr.connectionProperties, cp)
# 'zooms' to extent of new layer in map frame
mapFrame.camera.setExtent(mapFrame.getLayerExtent(lyr, False, False))
aprx.save()
layout = aprx.listLayouts('Layout1')[0]
layout.exportToPDF(f'{output_path}\\CERES_{file.split("_")[1]}.pdf')