#########################################################################
#
# Copyright (C) 2016 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
import os
import logging
from slugify import slugify
from datetime import datetime
[docs]
logger = logging.getLogger(__name__)
[docs]
ABSTRACT_TEMPLATE_MODEL_DATE_LATLON = "Image shot by {model} on {date} at {lat}, {lon} (latitude, longitude)"
[docs]
ABSTRACT_TEMPLATE_MODEL_DATE = "Image shot by {model} on {date}"
[docs]
ABSTRACT_TEMPLATE_MODEL = "Image shot by {model}"
[docs]
ABSTRACT_TEMPLATE_DATE = "Image shot on {date}"
[docs]
def convertExifDateToDjangoDate(date):
a = list(date.replace(" ", "T"))
a[4] = "-"
a[7] = "-"
a[10] = "T"
return datetime(
int("".join(a[0:4])),
int("".join(a[5:7])),
int("".join(a[8:10])),
int("".join(a[11:13])),
int("".join(a[14:16])),
)
[docs]
def convertExifLocationToDecimalDegrees(location, direction):
if location:
dd = 0.0
d, m, s = location
dd += float(d)
dd += float(m) / 60.0
dd += float(s) / 3600.0
if direction:
if direction.lower() == "s" or direction.lower() == "w":
dd = dd * -1.0
return dd
else:
return None
[docs]
def exif_build_abstract(model=None, date=None, lat=None, lon=None):
if model and date and lat and lon:
return ABSTRACT_TEMPLATE_MODEL_DATE_LATLON.format(model=model, date=date, lat=lat, lon=lon)
elif model and date:
return ABSTRACT_TEMPLATE_MODEL_DATE.format(model=model, date=date)
elif model:
return ABSTRACT_TEMPLATE_MODEL.format(model=model)
elif date:
return ABSTRACT_TEMPLATE_DATE.format(date=date)
else:
return None