I am trying to recreate/customize a tool (found here) which reads metadata from a JPG and creates a KML from it. The KML points to the relative path of the JPG and the image is displayed in the KML's pop-up window.
I cannot get the image to show up and was hoping someone had an idea. The image below shows what the KML looks like in Google Earth.
Here is the code that produces the KML.
for directory, sub, files in os.walk(imageDir):
for f in files:
fullpath = os.path.join(directory, f)
relpath = os.path.relpath(fullpath) #I've tried passing both fullpath and relpath to Text below
data = get_exif_data(fullpath)
c = get_lat_lon(data)
coordinates = (c[1],c[0])
pnt = kml.newpoint(name=f, coords = [coordinates])
imgHeight = data['ImageLength']/4
imgWidth = data['ImageWidth']/4
project = 'Test'
date = data['DateTime']
device = 'Apple iPhone'
Text = '<img src="'+relpath+'" alt="path failed" width="{0}" height="{1}"'+\
'align="left"/>'.format(imgWidth, imgHeight)+\
'<br>Project Name: {0}'+\
'<br>Capture Date & Time: {1}<br>Device: {2}'.format(project, date, device)
pnt.style.iconstyle.icon.href ="http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png"
kml.save(outKML)
Any ideas as to why this is happening. I'm 99% sure the path to the image is incorrect, but I'm out of ideas.
Solved! Go to Solution.
I always include the script name in any script, then you can play with relative paths etc.
The easiest is store everything in one folder ie script and image
import sys
script = sys.argv[0]
pth = "/".join(script.split('/')[:-1]) + "/test.png"
pth
'C:/GIS/Tools_scripts/Table_tools/Scripts/test.png'
I always include the script name in any script, then you can play with relative paths etc.
The easiest is store everything in one folder ie script and image
import sys
script = sys.argv[0]
pth = "/".join(script.split('/')[:-1]) + "/test.png"
pth
'C:/GIS/Tools_scripts/Table_tools/Scripts/test.png'
As an alternative there are some tools available to do this in ArcGIS:GeoTagged Photos To Points—Data Management toolbox | ArcGIS Desktop and http://www.arcgis.com/home/item.html?id=1cfeb0e0b8b946239ad10552eec5a21e
Holy cow! Dan, that worked! Thanks so much! All I did was move the script to the folder where the images are housed. You're the man.