# !/usr/bin/python3
# coding: utf-8
import json
import os
import traceback
import exifread
import requests
def parse_gps_express(gps_express):
'''
GPS坐标表达式转数值
:param gps_express: GPS坐标表达式 [1,2,3/4]
:return: GPS坐标数值 1.033542
'''
try:
express = str(gps_express).replace(" ", "").replace("[", "").replace("]", "")
parts = express.split(",")
subpart = parts[2].split("/")
degrees = float(parts[0])
minutes = float(parts[1])
seconds = float(subpart[0]) / float(subpart[1])
return degrees + minutes / 60 + seconds / 3600
except:
raise Exception("Error information for the picture")
def photo_gps(photo_path):
'''
照片拍摄地GPS坐标
:param photo_path: 照片的磁盘路径
:return: 照片的 (GPS经度,GPS纬度)
'''
if not os.path.isfile(photo_path):
raise Exception("File is not exist")
with open(photo_path, 'rb') as f:
exif_dict = exifread.process_file(f)
longitude_ref = str(exif_dict["GPS GPSLongitudeRef"]).strip()
longitude = parse_gps_express(str(exif_dict["GPS GPSLongitude"]))
latitude_ref = str(exif_dict["GPS GPSLatitudeRef"]).strip()
latitude = parse_gps_express(str(exif_dict["
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交