Esempio n. 1
0
    def set_location(self, latitude, longitude):
        """Set latitude and longitude for a photo.

        :param float latitude: Latitude of the file
        :param float longitude: Longitude of the file
        :returns: bool
        """
        if (latitude is None or longitude is None):
            return False

        source = self.source
        exif_metadata = pyexiv2.ImageMetadata(source)
        exif_metadata.read()

        exif_metadata['Exif.GPSInfo.GPSLatitude'] = geolocation.decimal_to_dms(
            latitude, False)  # noqa
        exif_metadata['Exif.GPSInfo.GPSLatitudeRef'] = pyexiv2.ExifTag(
            'Exif.GPSInfo.GPSLatitudeRef',
            'N' if latitude >= 0 else 'S')  # noqa
        exif_metadata[
            'Exif.GPSInfo.GPSLongitude'] = geolocation.decimal_to_dms(
                longitude, False)  # noqa
        exif_metadata['Exif.GPSInfo.GPSLongitudeRef'] = pyexiv2.ExifTag(
            'Exif.GPSInfo.GPSLongitudeRef',
            'E' if longitude >= 0 else 'W')  # noqa

        exif_metadata.write()
        self.reset_cache()
        return True
Esempio n. 2
0
    def set_location(self, latitude, longitude):
        """Set latitude and longitude for a photo.

        :param float latitude: Latitude of the file
        :param float longitude: Longitude of the file
        :returns: bool
        """
        if latitude is None or longitude is None:
            return False

        source = self.source
        exif_metadata = pyexiv2.ImageMetadata(source)
        exif_metadata.read()

        exif_metadata["Exif.GPSInfo.GPSLatitude"] = geolocation.decimal_to_dms(latitude, False)  # noqa
        exif_metadata["Exif.GPSInfo.GPSLatitudeRef"] = pyexiv2.ExifTag(
            "Exif.GPSInfo.GPSLatitudeRef", "N" if latitude >= 0 else "S"
        )  # noqa
        exif_metadata["Exif.GPSInfo.GPSLongitude"] = geolocation.decimal_to_dms(longitude, False)  # noqa
        exif_metadata["Exif.GPSInfo.GPSLongitudeRef"] = pyexiv2.ExifTag(
            "Exif.GPSInfo.GPSLongitudeRef", "E" if longitude >= 0 else "W"
        )  # noqa

        exif_metadata.write()
        return True
Esempio n. 3
0
    def set_location(self, latitude, longitude):
        if(latitude is None or longitude is None):
            return False

        source = self.source
        exif_metadata = pyexiv2.ImageMetadata(source)
        exif_metadata.read()

        exif_metadata['Exif.GPSInfo.GPSLatitude'] = geolocation.decimal_to_dms(latitude)
        exif_metadata['Exif.GPSInfo.GPSLatitudeRef'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSLatitudeRef', 'N' if latitude >= 0 else 'S')
        exif_metadata['Exif.GPSInfo.GPSLongitude'] = geolocation.decimal_to_dms(longitude)
        exif_metadata['Exif.GPSInfo.GPSLongitudeRef'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSLongitudeRef', 'E' if longitude >= 0 else 'W')

        exif_metadata.write()
        return True
Esempio n. 4
0
    def set_location(self, latitude, longitude):
        """Set latitude and longitude for a photo.

        :param float latitude: Latitude of the file
        :param float longitude: Longitude of the file
        :returns: bool
        """
        if(latitude is None or longitude is None):
            return False

        source = self.source
        exif_metadata = pyexiv2.ImageMetadata(source)
        exif_metadata.read()

        exif_metadata['Exif.GPSInfo.GPSLatitude'] = geolocation.decimal_to_dms(latitude, False)  # noqa
        exif_metadata['Exif.GPSInfo.GPSLatitudeRef'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSLatitudeRef', 'N' if latitude >= 0 else 'S')  # noqa
        exif_metadata['Exif.GPSInfo.GPSLongitude'] = geolocation.decimal_to_dms(longitude, False)  # noqa
        exif_metadata['Exif.GPSInfo.GPSLongitudeRef'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSLongitudeRef', 'E' if longitude >= 0 else 'W')  # noqa

        exif_metadata.write()
        self.reset_cache()
        return True
Esempio n. 5
0
def test_dms_string_longitude():

    for x in range(0, 5):
        target_decimal_value = random.uniform(0.0, 180.0)
        if(x % 2 == 1):
            target_decimal_value = target_decimal_value * -1

        dms = geolocation.decimal_to_dms(target_decimal_value)
        dms_string = geolocation.dms_string(target_decimal_value, 'longitude')

        check_value = 'E' if target_decimal_value >= 0 else 'W'

        assert check_value in dms_string, '%s not in %s' % (check_value, dms_string)
        assert str(dms[0]) in dms_string, '%s not in %s' % (dms[0], dms_string)
Esempio n. 6
0
def test_decimal_to_dms_unsigned():

    for x in range(0, 1000):
        target_decimal_value = random.uniform(0.0, 180.0) * -1
    
        dms = geolocation.decimal_to_dms(target_decimal_value, False)
        check_value = dms[0].to_float() + dms[1].to_float() / 60 + dms[2].to_float() / 3600

        target_decimal_value = round(target_decimal_value, 8)
        check_value = round(check_value, 8)

        new_target_decimal_value = abs(target_decimal_value)

        assert new_target_decimal_value == check_value, '%s does not match %s' % (check_value, new_target_decimal_value)
Esempio n. 7
0
def test_decimal_to_dms():

    for x in range(0, 1000):
        target_decimal_value = random.uniform(0.0, 180.0)
        if(x % 2 == 1):
            target_decimal_value = target_decimal_value * -1
    
        dms = geolocation.decimal_to_dms(target_decimal_value)
        check_value = dms[0].to_float() + dms[1].to_float() / 60 + dms[2].to_float() / 3600

        target_decimal_value = round(target_decimal_value, 8)
        check_value = round(check_value, 8)

        assert target_decimal_value == check_value, '%s does not match %s' % (check_value, target_decimal_value)
Esempio n. 8
0
def test_dms_string_longitude():

    for x in range(0, 5):
        target_decimal_value = random.uniform(0.0, 180.0)
        if (x % 2 == 1):
            target_decimal_value = target_decimal_value * -1

        dms = geolocation.decimal_to_dms(target_decimal_value)
        dms_string = geolocation.dms_string(target_decimal_value, 'longitude')

        check_value = 'E' if target_decimal_value >= 0 else 'W'

        assert check_value in dms_string, '%s not in %s' % (check_value,
                                                            dms_string)
        assert str(dms[0]) in dms_string, '%s not in %s' % (dms[0], dms_string)
Esempio n. 9
0
def test_decimal_to_dms():

    for x in range(0, 1000):
        target_decimal_value = random.uniform(0.0, 180.0)
        if (x % 2 == 1):
            target_decimal_value = target_decimal_value * -1

        dms = geolocation.decimal_to_dms(target_decimal_value)

        check_value = (dms[0] + dms[1] / 60 + dms[2] / 3600) * dms[3]

        target_decimal_value = round(target_decimal_value, 8)
        check_value = round(check_value, 8)

        assert target_decimal_value == check_value, '%s does not match %s' % (
            check_value, target_decimal_value)
Esempio n. 10
0
def test_decimal_to_dms_unsigned():

    for x in range(0, 1000):
        target_decimal_value = random.uniform(0.0, 180.0) * -1

        dms = geolocation.decimal_to_dms(target_decimal_value, False)
        check_value = dms[0].to_float(
        ) + dms[1].to_float() / 60 + dms[2].to_float() / 3600

        target_decimal_value = round(target_decimal_value, 8)
        check_value = round(check_value, 8)

        new_target_decimal_value = abs(target_decimal_value)

        assert new_target_decimal_value == check_value, '%s does not match %s' % (
            check_value, new_target_decimal_value)