Hello, I have been trying to fill a shapefile with EXIF data from pictures taken by a drone.
I was able to create the shapefile and the desired fields in the attribute table, but I failed to populate the fields with the data. The script below always returns UpdateCursor() takes no arguments.
As I wrote this script with the input from other people on the internet (suggestions and actual scripts), I have no idea what to do next and how to resolve this issue. I welcome any advice and will appreciate the help.
import os
import arcpy
from pathlib import Path
IMAGE_FOLDER = Path(
r"\\...\InspectionServicesData\DRONE_INSPECTION_SERVICE\01_Projects\...\2_FIELD-WORK\DATA-DUMP\2022-08-13...\DJI_202208131356_022")
img_path = r"\\...\InspectionServicesData\DRONE_INSPECTION_SERVICE\01_Projects\...\2_FIELD-WORK\DATA-DUMP\2022-08-13...\DJI_202208131356_022"
image_path = os.listdir(img_path)
for img in image_path:
full_image_path = os.path.join(img_path, img)
exif_properties = {}
output_shpdata = r"C:\Users\...\OneDrive...\Desktop\EXIF_TEST\output_shpdata.shp"
shp_data = []
spatial_ref = arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(4326)
for image in IMAGE_FOLDER.glob("*.jpg"):
exif_properties[image.name] = arcpy.GetImageEXIFProperties(image)
for name in exif_properties:
target_data = exif_properties[name][3]
root_path = r"\\...\InspectionServicesData\DRONE_INSPECTION_SERVICE\01_Projects\...\2_FIELD-WORK\DATA-DUMP\2022-08-13..."
full_path = "".join([root_path, "\\", name])
targlong = target_data['XMP:drone-dji:LRFTargetLon']
tarlat = target_data['XMP:drone-dji:LRFTargetLat']
tardist = target_data['XMP:drone-dji:LRFTargetDistance']
gimbalyaw = target_data['XMP:drone-dji:GimbalYawDegree']
shp_data.append([name, tardist, gimbalyaw, full_path, targlong, tarlat])
def output_shpdata_creator():
pt = arcpy.Point()
ptGeoms = []
for p in shp_data:
pt.X = p[4]
pt.Y = p[5]
ptGeoms.append(arcpy.PointGeometry(pt, spatial_ref))
arcpy.CopyFeatures_management(ptGeoms, output_shpdata)
arcpy.AddField_management(output_shpdata, "Name", "TEXT", 9, "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddField_management(output_shpdata, "Distance", "DOUBLE", 9, "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddField_management(output_shpdata, "YawDegree", "FLOAT", 9, "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddField_management(output_shpdata, "ImagePath", "TEXT", 9, "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddXY_management(output_shpdata)
count = 0
with arcpy.da.UpdateCursor(output_shpdata, ['Name', 'Distance', 'YawDegree', 'ImagePath']) as cursor:
for r in cursor:
r[0] = shp_data[count][0]
r[1] = shp_data[count][1]
r[2] = shp_data[count][2]
r[3] = shp_data[count][3]
cursor.updateRow(r)
count += 1
print(shp_data)
output_shpdata_creator()