|
|
|
@ -18,6 +18,21 @@ def get_exif_data(image_path): |
|
|
|
print(f"Error reading EXIF data: {e}") |
|
|
|
print(f"Error reading EXIF data: {e}") |
|
|
|
return None |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_camera_info(exif): |
|
|
|
|
|
|
|
if not exif: |
|
|
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera_info = { |
|
|
|
|
|
|
|
'Make': exif.get('Make', 'Unknown'), |
|
|
|
|
|
|
|
'Model': exif.get('Model', 'Unknown') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Some cameras store model in 'Camera Model Name' instead |
|
|
|
|
|
|
|
if camera_info['Model'] == 'Unknown': |
|
|
|
|
|
|
|
camera_info['Model'] = exif.get('Camera Model Name', 'Unknown') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return camera_info |
|
|
|
|
|
|
|
|
|
|
|
def get_gps_info(exif_data): |
|
|
|
def get_gps_info(exif_data): |
|
|
|
"""Extract GPS information from EXIF data""" |
|
|
|
"""Extract GPS information from EXIF data""" |
|
|
|
if not exif_data or 'GPSInfo' not in exif_data: |
|
|
|
if not exif_data or 'GPSInfo' not in exif_data: |
|
|
|
@ -60,6 +75,37 @@ def get_lat_lon(gps_info): |
|
|
|
print(f"Error converting coordinates: {e}") |
|
|
|
print(f"Error converting coordinates: {e}") |
|
|
|
|
|
|
|
|
|
|
|
return None, None |
|
|
|
return None, None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import math |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def haversine(lat1, lon1, lat2, lon2): |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
Calculate the great circle distance between two points |
|
|
|
|
|
|
|
on the earth (specified in decimal degrees) |
|
|
|
|
|
|
|
Returns distance in miles |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
# Convert decimal degrees to radians |
|
|
|
|
|
|
|
lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Haversine formula |
|
|
|
|
|
|
|
dlon = lon2 - lon1 |
|
|
|
|
|
|
|
dlat = lat2 - lat1 |
|
|
|
|
|
|
|
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2 |
|
|
|
|
|
|
|
c = 2 * math.asin(math.sqrt(a)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Radius of earth in miles (3956 for miles, 6371 for kilometers) |
|
|
|
|
|
|
|
r = 3956 |
|
|
|
|
|
|
|
return c * r |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def are_within_one_mile(lat1, lon1, lat2, lon2): |
|
|
|
|
|
|
|
distance = haversine(lat1, lon1, lat2, lon2) |
|
|
|
|
|
|
|
return distance <= 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
Example points: |
|
|
|
|
|
|
|
point1 = (40.7128, -74.0060) # New York City |
|
|
|
|
|
|
|
point2 = (40.7200, -74.0100) # About 0.5 miles from NYC |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
def get_coordinates_from_image(image_path): |
|
|
|
def get_coordinates_from_image(image_path): |
|
|
|
"""Main function to get coordinates from image file""" |
|
|
|
"""Main function to get coordinates from image file""" |
|
|
|
@ -73,9 +119,11 @@ def get_coordinates_from_image(image_path): |
|
|
|
print("No GPS information found in EXIF data.") |
|
|
|
print("No GPS information found in EXIF data.") |
|
|
|
return None |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera_info = get_camera_info(exif_data) |
|
|
|
|
|
|
|
|
|
|
|
latitude, longitude = get_lat_lon(gps_info) |
|
|
|
latitude, longitude = get_lat_lon(gps_info) |
|
|
|
if latitude is not None and longitude is not None: |
|
|
|
if latitude is not None and longitude is not None: |
|
|
|
return (latitude, longitude) |
|
|
|
return (camera_info, latitude, longitude) |
|
|
|
else: |
|
|
|
else: |
|
|
|
print("Could not extract valid coordinates.") |
|
|
|
print("Could not extract valid coordinates.") |
|
|
|
return None |
|
|
|
return None |
|
|
|
|