-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldMapsPhotoBulkDownloader
More file actions
199 lines (155 loc) · 8.22 KB
/
FieldMapsPhotoBulkDownloader
File metadata and controls
199 lines (155 loc) · 8.22 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#polygon photos
import arcpy
import os
# Set variables
fc = r"\\neo\Terra\ClientFiles\U-Z\YN_Reach_Assessments_2024_240213\GIS\PRO\Icicle_Geomorph\IcicleGeomorphProcessed.gdb\Geomorphology_Survey"
output_base_folder = r"\\neo\Terra\ClientFiles\U-Z\YN_Reach_Assessments_2024_240213\Photos\2024\Icicle_Geom_2024\Icicle_GISPhotoData_Aug-Sept2024\FieldMapsPhotosCategories"
# Create a dictionary to store the mapping of GLOBALID to required fields
fields = ["GLOBALID", "RMFlip", "Reach", "TypeGeomorphicFeature"]
field_data_dict = {}
# Retrieve the RMFlip and Reach values for each feature
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
GLOBALID = row[0] # Unique identifier
RMFlip = round(row[1], 2) # Ensure RMFlip is rounded to two decimal places
Reach = row[2]
TypeGeomorphicFeature = row[3]
# Store values in a dictionary using GLOBALID as key
field_data_dict[GLOBALID] = {"RMFlip": RMFlip, "Reach": Reach, "TypeGeomorphicFeature": TypeGeomorphicFeature}
# Use the Attachments table to process photos
attachment_table = fc + "__ATTACH"
# Log missing photos and keep count of downloaded photos
missing_photos = []
downloaded_photos_count = 0
total_photos_count = 0 # Unique identifier for each photo
# Process attachments
with arcpy.da.SearchCursor(attachment_table, ["REL_GLOBALID", "DATA", "ATT_NAME"]) as attachment_cursor:
for attachment in attachment_cursor:
rel_globalid = attachment[0] # Linking GLOBALID
photo = attachment[1] # Binary photo data
# Retrieve RMFlip and Reach values for this feature
field_values = field_data_dict.get(rel_globalid)
if field_values:
RMFlip = field_values["RMFlip"]
Reach = field_values["Reach"]
TypeGeomorphicFeature = field_values["TypeGeomorphicFeature"]
# Increment total photo counter for a globally unique number
total_photos_count += 1
# Construct the unique photo filename
unique_photo_name = f"RM{RMFlip}_Reach{Reach}_Photo{total_photos_count}_{TypeGeomorphicFeature}.jpg"
photo_path = os.path.join(output_base_folder, unique_photo_name)
# Write the photo to the output folder
with open(photo_path, 'wb') as file:
file.write(photo)
downloaded_photos_count += 1
else:
# Log missing photos where REL_GLOBALID does not match
missing_photos.append(attachment[2])
# Summary of download results
print(f"Total photos processed: {total_photos_count}")
print(f"Photos successfully downloaded: {downloaded_photos_count}")
print(f"Photos not downloaded: {len(missing_photos)}")
#line photos
import arcpy
import os
#line downloading
# Set variables
fc = r"\\neo\Terra\ClientFiles\U-Z\YN_Reach_Assessments_2024_240213\GIS\PRO\Icicle_Geomorph\IcicleGeomorphProcessed.gdb\Geomorphology_Survey_line" # Update this to your new file
output_base_folder = r"\\neo\Terra\ClientFiles\U-Z\YN_Reach_Assessments_2024_240213\Photos\2024\Icicle_Geom_2024\Icicle_GISPhotoData_Aug-Sept2024\FieldMapsPhotosCategories"
# Create a dictionary to store the mapping of GLOBALID to required fields
fields = ["GLOBALID", "RM_Flip", "Reach", "TypeGeomorphicFeature"]
field_data_dict = {}
# Retrieve the RMFlip and Reach values for each feature
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
GLOBALID = row[0] # Unique identifier
RMFlip = round(row[1], 2) # Ensure RMFlip is rounded to two decimal places
Reach = row[2]
TypeGeomorphicFeature = row[3]
# Store values in a dictionary using GLOBALID as key
field_data_dict[GLOBALID] = {"RM_Flip": RMFlip, "Reach": Reach, "TypeGeomorphicFeature": TypeGeomorphicFeature}
# Use the Attachments table to process photos
attachment_table = fc + "__ATTACH"
# Log missing photos and keep count of downloaded photos
missing_photos = []
downloaded_photos_count = 0
total_photos_count = 50 # Start numbering photos from 50
# Process attachments
with arcpy.da.SearchCursor(attachment_table, ["REL_GLOBALID", "DATA", "ATT_NAME"]) as attachment_cursor:
for attachment in attachment_cursor:
rel_globalid = attachment[0] # Linking GLOBALID
photo = attachment[1] # Binary photo data
# Retrieve RMFlip and Reach values for this feature
field_values = field_data_dict.get(rel_globalid)
if field_values:
RMFlip = field_values["RM_Flip"]
Reach = field_values["Reach"]
TypeGeomorphicFeature = field_values["TypeGeomorphicFeature"]
# Increment total photo counter for a globally unique number
total_photos_count += 1
# Construct the unique photo filename
unique_photo_name = f"RM{RMFlip}_Reach{Reach}_Photo{total_photos_count}_{TypeGeomorphicFeature}.jpg"
photo_path = os.path.join(output_base_folder, unique_photo_name)
# Write the photo to the output folder
with open(photo_path, 'wb') as file:
file.write(photo)
downloaded_photos_count += 1
else:
# Log missing photos where REL_GLOBALID does not match
missing_photos.append(attachment[2])
# Summary of download results
print(f"Total photos processed: {total_photos_count - 50}") # Adjusted to show only new photos
print(f"Photos successfully downloaded: {downloaded_photos_count}")
print(f"Photos not downloaded: {len(missing_photos)}")
#download point photos
import arcpy
import os
#line downloading
# Set variables
fc = r"\\neo\Terra\ClientFiles\U-Z\YN_Reach_Assessments_2024_240213\GIS\PRO\Icicle_Geomorph\IcicleGeomorphProcessed.gdb\Geomorph_Survey_Point_WithRMs" # Update this to your new file
output_base_folder = r"\\neo\Terra\ClientFiles\U-Z\YN_Reach_Assessments_2024_240213\Photos\2024\Icicle_Geom_2024\Icicle_GISPhotoData_Aug-Sept2024\FieldMapsPhotosCategories"
# Create a dictionary to store the mapping of GLOBALID to required fields
fields = ["GLOBALID", "RM_Flip", "Reach", "TypeGeomorphicFeature"]
field_data_dict = {}
# Retrieve the RMFlip and Reach values for each feature
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
GLOBALID = row[0] # Unique identifier
RM_Flip = round(row[1], 2) # Ensure RMFlip is rounded to two decimal places
Reach = row[2]
TypeGeomorphicFeature = row[3]
# Store values in a dictionary using GLOBALID as key
field_data_dict[GLOBALID] = {"RM_Flip": RM_Flip, "Reach": Reach, "TypeGeomorphicFeature": TypeGeomorphicFeature}
# Use the Attachments table to process photos
attachment_table = fc + "__ATTACH"
# Log missing photos and keep count of downloaded photos
missing_photos = []
downloaded_photos_count = 0
total_photos_count = 190 # Start numbering photos from 50
# Process attachments
with arcpy.da.SearchCursor(attachment_table, ["REL_GLOBALID", "DATA", "ATT_NAME"]) as attachment_cursor:
for attachment in attachment_cursor:
rel_globalid = attachment[0] # Linking GLOBALID
photo = attachment[1] # Binary photo data
# Retrieve RMFlip and Reach values for this feature
field_values = field_data_dict.get(rel_globalid)
if field_values:
RM_Flip = field_values["RM_Flip"]
Reach = field_values["Reach"]
TypeGeomorphicFeature = field_values["TypeGeomorphicFeature"]
# Increment total photo counter for a globally unique number
total_photos_count += 1
# Construct the unique photo filename
unique_photo_name = f"RM{RM_Flip}_Reach{Reach}_Photo{total_photos_count}_{TypeGeomorphicFeature}.jpg"
photo_path = os.path.join(output_base_folder, unique_photo_name)
# Write the photo to the output folder
with open(photo_path, 'wb') as file:
file.write(photo)
downloaded_photos_count += 1
else:
# Log missing photos where REL_GLOBALID does not match
missing_photos.append(attachment[2])
# Summary of download results
print(f"Total photos processed: {total_photos_count - 190}") # Adjusted to show only new photos
print(f"Photos successfully downloaded: {downloaded_photos_count}")
print(f"Photos not downloaded: {len(missing_photos)}")