'''Usingthisscriptprovideasabaseline.Expandthescriptasfollows:...

'''Usingthisscriptprovideasabaseline.Expandthescriptasfollows:
1)Allowtheusertoenterapathtoadirectorycontainingjpegfiles.2)Usingthatpath,processallthe.jpgfilescontainedinthatfolder(usethetestimages.zipsetofimages)3)ExtracttheGPSCoordinatesforeachjpg(iftheyexist)andthenmapthecoordinates
NOTE:Thereareseveralwaystodothis,however,theeasiestmethodwouldbetousetheMapMakerApp,athttps;//mapmakerapp.com/youcaneithermanuallyenterthelat/lonvaluesyourscriptgeneratesoryoucanplaceyourresultsinaCSVfileanduploadthedatatothemap.
'''#UsageExample:#pythonAssignment6##Requirement:Python3.x##Requirement:3rdPartyLibrarythatisutilizedis:PILLOW#pipinstallPILLOWfromthecommandline#thisisalreadyinstalledintheVirtualDesktop
'''LIBRARYIMPORTSECTION'''
importos#PythonStandardLibrary:OperatingSystemMethodsimportsys#PythonStandardLibrary:SystemMethodsfromdatetimeimportdatetime#PythonStandardLibarydatetimemethodfromStandardLibrary
#importthePythonImageLibrary#alongwithTAGSandGPSrelatedTAGS#NoteyoumustinstallthePILLOWModule#pipinstallPILLOW
fromPILimportImagefromPIL.ExifTagsimportTAGS,GPSTAGS
#importtheprettytablelibraryfromprettytableimportPrettyTable
defExtractGPSDictionary(fileName):'''FunctiontoExtractGPSDictionary'''try:pilImage=Image.open(fileName)exifData=pilImage._getexif()
exceptException:#IfexceptionoccursfromPILprocessing#ReportthereturnNone,None
#InteratethroughtheexifData#SearchingforGPSTags
imageTimeStamp="NA"cameraModel="NA"cameraMake="NA"gpsData=False
gpsDictionary={}
ifexifData:
fortag,theValueinexifData.items():
#obtainthetagtagValue=TAGS.get(tag,tag)print(tagValue)#Collectbasicimagedataifavailable
iftagValue=='DateTimeOriginal':imageTimeStamp=exifData.get(tag).strip()
iftagValue=="Make":cameraMake=exifData.get(tag).strip()
iftagValue=='Model':cameraModel=exifData.get(tag).strip()
#checkthetagforGPSiftagValue=="GPSInfo":
gpsData=True;
#Foundit!#NowcreateaDictionarytoholdtheGPSData
#LoopthroughtheGPSInformationforcurTagintheValue:gpsTag=GPSTAGS.get(curTag,curTag)gpsDictionary[gpsTag]=theValue[curTag]
basicExifData=[imageTimeStamp,cameraMake,cameraModel]
returngpsDictionary,basicExifData
else:returnNone,None
#EndExtractGPSDictionary============================
defExtractLatLon(gps):'''FunctiontoExtractLattitudeandLongitudeValues'''
#toperformthecalcuationweneedatleast#lat,lon,latRefandlonReftry:latitude=gps["GPSLatitude"]latitudeRef=gps["GPSLatitudeRef"]longitude=gps["GPSLongitude"]longitudeRef=gps["GPSLongitudeRef"]
lat,lon=ConvertToDegreesV1(latitude,latitudeRef,longitude,longitudeRef)
gpsCoor={"Lat":lat,"LatRef":latitudeRef,"Lon":lon,"LonRef":longitudeRef}
returngpsCoor
exceptExceptionaserr:returnNone
#EndExtractLatLon==============================================
defConvertToDegreesV1(lat,latRef,lon,lonRef):degrees=lat[0]minutes=lat[1]seconds=lat[2]try:seconds=float(seconds)except:seconds=0.0
latDecimal=float((degrees+(minutes/60)+(seconds)/(60*60)))iflatRef=='S':latDecimal=latDecimal*-1.0degrees=lon[0]minutes=lon[1]seconds=lon[2]try:seconds=float(seconds)except:seconds=0.0lonDecimal=float((degrees+(minutes/60)+(seconds)/(60*60)))iflonRef=='W':lonDecimal=lonDecimal*-1.0return(latDecimal,lonDecimal)
'''MAINPROGRAMENTRYSECTION'''
if__name__=="__main__":'''pyExifMainEntryPoint'''print("\nExtractEXIFDatafromJPEGFiles")
print("ScriptStarted",str(datetime.now()))print()
'''PROCESSEACHJPEGFILESECTION'''
latLonList=[]targetFile="barn.jpg"#filemustbelocatedinthesamefolder
ifos.path.isfile(targetFile):gpsDictionary,exifList=ExtractGPSDictionary(targetFile)ifexifList:TS=exifList[0]MAKE=exifList[1]MODEL=exifList[2]else:TS='NA'MAKE='NA'MODEL='NA'
print("PhotoDetails")print("-------------")print("TimeStamp:",TS)print("CameraMake:",MAKE)print("CameraModel:",MODEL)if(gpsDictionary!=None):
#ObtaintheLatLonvaluesfromthegpsDictionary#Convertedtodegrees#Thereturnvalueisadictionarykeyvaluepairs
dCoor=ExtractLatLon(gpsDictionary)
print("\nGeo-LocationData")print("-----------------")
ifdCoor:lat=dCoor.get("Lat")latRef=dCoor.get("LatRef")lon=dCoor.get("Lon")lonRef=dCoor.get("LonRef")if(latandlonandlatRefandlonRef):print("Lattitude:",'{:4.4f}'.format(lat))print("Longitude:",'{:4.4f}'.format(lon))else:print("WARNINGNoGPSEXIFData")else:print("WARNINGNoGPSEXIFData")else:print("WARNING","notavalidfile",targetFile)
#CreateResultTableDisplayusingPrettyTable'''GENERATERESULTSTABLESECTION'''
'''ResultTableHeading'''resultTable=PrettyTable(['File-Name','Lat','Lon','TimeStamp','Make','Model'])'''Yourworkstartshere'''print()
Feb 13, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here