I'm working on a Python script that strips the GPS info from images and uses that info to create a shapefile from that info. Right now I have all the file names as keys to tuples of decimal degrees coordinates. This dictionary prints out like this:
{'IMG_2840.jpg': (39.08861111111111, 114.80472222222222), 'IMG_2823.jpg': (38.61611111111111, 119.88777777777777), 'IMG_2912.jpg': (41.97861111111111, 106.25500000000001), 'IMG_2859.jpg': (39.742777777777775, 112.19694444444444), 'IMG_2813.jpg': (39.200833333333335, 119.79416666666665), 'IMG_2790.jpg': (41.82111111111111, 121.72472222222221), 'IMG_2753.jpg': (41.72027777777778, 124.32249999999999), 'IMG_2916.jpg': (41.01388888888889, 105.97611111111111), 'IMG_2750.jpg': (42.50833333333333, 125.72888888888889)}
How would I take this dictionary and turn it into a shapefile so that the names of the files are the names of the points?
I would prefer an open source way such as shapely or ogr/gdal.
Here's the code that generated this list. It does not really deal with spatial data at all.
filelist = os.listdir(Path)
for f in filelist:
if f.endswith(".jpg"):
with open(Path + "/" + f, 'r') as I:
print(I)
img = Image.open(Path + "/" + f)
exif = {ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS}
print(exif)
meta = exif['GPSInfo'][2]
meta = [x[0] for x in meta]
d = meta[0]
m = meta[1]
s = meta[2]
NCDict[os.path.basename(I.name)] = dms_to_dd(d=d,m=m,s=s)
# Ncoords = {I:dms_to_dd(d=d, m=m, s=s)}
# print(Ncoords)
meta2 = exif['GPSInfo'][4]
meta2 = [b[0] for b in meta2]
d = meta2[0]
m = meta2[1]
s = meta2[2]
WCDict[os.path.basename(I.name)] = dms_to_dd(d=d,m=m,s=s)
print NCDict
print WCDict
# writing xy coords to new file
corddict=[NCDict,WCDict]
finalCoord = {}
for k in NCDict.iterkeys():
finalCoord[k] = tuple(finalCoord[k] for finalCoord in corddict)
print(finalCoord)