Support for geo search

This commit is contained in:
2023-01-02 15:08:46 +01:00
parent 075f08a8c1
commit ea1b92015d
3 changed files with 32 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
from modules.utils import configGet
from pymongo import MongoClient
from pymongo import MongoClient, GEOSPHERE
db_config = configGet("database")
@@ -32,4 +32,6 @@ col_users = db.get_collection("users")
col_albums = db.get_collection("albums")
col_photos = db.get_collection("photos")
col_videos = db.get_collection("videos")
col_tokens = db.get_collection("tokens")
col_tokens = db.get_collection("tokens")
col_photos.create_index([("location", GEOSPHERE)])

View File

@@ -13,7 +13,7 @@ def decimal_coords(coords: float, ref: str) -> float:
decimal_degrees = coords[0] + coords[1] / 60 + coords[2] / 3600
if ref == "S" or ref == "W":
decimal_degrees = -decimal_degrees
return decimal_degrees
return round(decimal_degrees, 5)
def extract_location(filepath: str) -> dict:
"""Get location data from image
@@ -22,13 +22,13 @@ def extract_location(filepath: str) -> dict:
* filepath (`str`): Path to file location
### Returns:
* dict: `{ "latitude": float, "longitude": float, "altitude": float }`
* dict: `{ "lng": float, "lat": float, "alt": float }`
"""
output = {
"latitude": 0.0,
"longitude": 0.0,
"altitude": 0.0
"lng": 0.0,
"lat": 0.0,
"alt": 0.0
}
with open(filepath, 'rb') as src:
@@ -38,9 +38,9 @@ def extract_location(filepath: str) -> dict:
return output
try:
output["latitude"] = decimal_coords(img.gps_latitude, img.gps_latitude_ref)
output["longitude"] = decimal_coords(img.gps_longitude, img.gps_longitude_ref)
output["altitude"] = img.gps_altitude
output["lng"] = decimal_coords(img.gps_longitude, img.gps_longitude_ref)
output["lat"] = decimal_coords(img.gps_latitude, img.gps_latitude_ref)
output["alt"] = img.gps_altitude
except AttributeError:
pass