Ejemplo n.º 1
0
 def write(self):
     """Save exif data to photo file on disk."""
     if self.altitude is not None:
         self.exif[GPS + 'Altitude'] = float_to_rational(self.altitude)
         self.exif[GPS + 'AltitudeRef'] = '0' if self.altitude >= 0 else '1'
     self.exif[GPS + 'Latitude'] = decimal_to_dms(self.latitude)
     self.exif[GPS + 'LatitudeRef'] = 'N' if self.latitude >= 0 else 'S'
     self.exif[GPS + 'Longitude'] = decimal_to_dms(self.longitude)
     self.exif[GPS + 'LongitudeRef'] = 'E' if self.longitude >= 0 else 'W'
     self.exif[GPS + 'MapDatum'] = 'WGS-84'
     self.exif.write()
Ejemplo n.º 2
0
 def write(self):
     """Save exif data to photo file on disk."""
     if self.altitude is not None:
         self.exif[GPS + 'Altitude']    = float_to_rational(self.altitude)
         self.exif[GPS + 'AltitudeRef'] = '0' if self.altitude >= 0 else '1'
     self.exif[GPS + 'Latitude']     = decimal_to_dms(self.latitude)
     self.exif[GPS + 'LatitudeRef']  = 'N' if self.latitude >= 0 else 'S'
     self.exif[GPS + 'Longitude']    = decimal_to_dms(self.longitude)
     self.exif[GPS + 'LongitudeRef'] = 'E' if self.longitude >= 0 else 'W'
     self.exif[GPS + 'MapDatum']     = 'WGS-84'
     self.exif.write()
Ejemplo n.º 3
0
 def write(self):
     """Save exif data to photo file on disk."""
     if self.altitude is not None:
         self.exif[GPS + 'Altitude']    = float_to_rational(self.altitude)
         self.exif[GPS + 'AltitudeRef'] = '0' if self.altitude >= 0 else '1'
     self.exif[GPS + 'Latitude']     = decimal_to_dms(self.latitude)
     self.exif[GPS + 'LatitudeRef']  = 'N' if self.latitude >= 0 else 'S'
     self.exif[GPS + 'Longitude']    = decimal_to_dms(self.longitude)
     self.exif[GPS + 'LongitudeRef'] = 'E' if self.longitude >= 0 else 'W'
     self.exif[GPS + 'MapDatum']     = 'WGS-84'
     self.exif.write()
     modified.discard(self)
     self.liststore.set_value(self.iter, 1, self.long_summary())
Ejemplo n.º 4
0
 def write(self):
     """Save exif data to photo file on disk."""
     self.exif[GPS + 'AltitudeRef']  = '0' if self.altitude >= 0 else '1'
     self.exif[GPS + 'Altitude']     = Fraction(self.altitude)
     self.exif[GPS + 'Latitude']     = decimal_to_dms(self.latitude)
     self.exif[GPS + 'LatitudeRef']  = 'N' if self.latitude >= 0 else 'S'
     self.exif[GPS + 'Longitude']    = decimal_to_dms(self.longitude)
     self.exif[GPS + 'LongitudeRef'] = 'E' if self.longitude >= 0 else 'W'
     self.exif[GPS + 'MapDatum']     = 'WGS-84'
     self.exif[IPTC + 'City']          = [self.names[0] or '']
     self.exif[IPTC + 'ProvinceState'] = [self.names[1] or '']
     self.exif[IPTC + 'CountryName']   = [self.names[2] or '']
     self.exif.write()
     modified.discard(self)
     Widgets.loaded_photos.set_value(self.iter, 1, str(self))
Ejemplo n.º 5
0
    def test_gps_math(self):
        """Test coordinate conversion functions."""
        rats_to_fracs = lambda rats: [Fraction(rat.to_float()) for rat in rats]

        # Really important that this method is bulletproof
        self.assertFalse(valid_coords(None, None))
        self.assertFalse(valid_coords('', ''))
        self.assertFalse(valid_coords(True, True))
        self.assertFalse(valid_coords(False, False))
        self.assertFalse(valid_coords(45, 270))
        self.assertFalse(valid_coords(100, 50))
        self.assertFalse(valid_coords([], 50))
        self.assertFalse(valid_coords(45, {'grunt':42}))
        self.assertFalse(valid_coords(self, 50))
        self.assertFalse(valid_coords(45, valid_coords))
        self.assertFalse(valid_coords("ya", "dun goofed"))

        # St. John's broke the math. I'm not sure why.
        # Seriously. Revert commit 362dd6eb and watch this explode.
        stjohns = Coordinates()
        stjohns.latitude = 47.56494
        stjohns.longitude = -52.70931
        stjohns.lookup_geoname()
        self.assertEqual(stjohns.city, "St. John's")

        # Pick 100 random coordinates on the globe, convert them from decimal
        # to sexagesimal and then back, and ensure that they are always equal.
        for _ in range(100):
            # Oh, and test altitudes too
            altitude = round(random_coord(1000), 6)
            fraction = float_to_rational(altitude)
            self.assertAlmostEqual(
                abs(altitude),
                fraction.numerator / fraction.denominator,
                3
            )

            decimal_lat = round(random_coord(80),  6)
            decimal_lon = round(random_coord(180), 6)

            self.assertTrue(valid_coords(decimal_lat, decimal_lon))

            dms_lat = decimal_to_dms(decimal_lat)
            dms_lon = decimal_to_dms(decimal_lon)

            self.assertEqual(len(dms_lat), 3)
            self.assertEqual(
                dms_lat[0].numerator,
                floor(abs(decimal_lat))
            )

            self.assertEqual(len(dms_lon), 3)
            self.assertEqual(
                dms_lon[0].numerator,
                floor(abs(decimal_lon))
            )

            self.assertAlmostEqual(
                decimal_lat,
                dms_to_decimal(*rats_to_fracs(dms_lat) + ['N' if decimal_lat >= 0 else 'S']),
                10 # equal to 10 places
            )
            self.assertAlmostEqual(
                decimal_lon,
                dms_to_decimal(*rats_to_fracs(dms_lon) + ['E' if decimal_lon >= 0 else 'W']),
                10 # equal to 10 places
            )
Ejemplo n.º 6
0
 def test_gps_math(self):
     """Test coordinate conversion functions."""
     rats_to_fracs = lambda rats: [Fraction(rat.to_float()) for rat in rats]
     
     # Really important that this method is bulletproof
     self.assertFalse(valid_coords(None, None))
     self.assertFalse(valid_coords('', ''))
     self.assertFalse(valid_coords(True, True))
     self.assertFalse(valid_coords(False, False))
     self.assertFalse(valid_coords(45, 270))
     self.assertFalse(valid_coords(100, 50))
     self.assertFalse(valid_coords([], 50))
     self.assertFalse(valid_coords(45, {'grunt':42}))
     self.assertFalse(valid_coords(self, 50))
     self.assertFalse(valid_coords(45, valid_coords))
     self.assertFalse(valid_coords("ya", "dun goofed"))
     
     # St. John's broke the math. I'm not sure why.
     # Seriously. Revert commit 362dd6eb and watch this explode.
     stjohns = Coordinates()
     stjohns.latitude = 47.56494
     stjohns.longitude = -52.70931
     stjohns.lookup_geoname()
     self.assertEqual(stjohns.city, "St. John's")
     
     # Pick 100 random coordinates on the globe, convert them from decimal
     # to sexagesimal and then back, and ensure that they are always equal.
     for i in range(100):
         # Oh, and test altitudes too
         altitude = round(random_coord(1000), 6)
         fraction = float_to_rational(altitude)
         self.assertAlmostEqual(
             abs(altitude),
             fraction.numerator / fraction.denominator,
             3
         )
         
         decimal_lat = round(random_coord(80),  6)
         decimal_lon = round(random_coord(180), 6)
         
         self.assertTrue(valid_coords(decimal_lat, decimal_lon))
         
         dms_lat = decimal_to_dms(decimal_lat)
         dms_lon = decimal_to_dms(decimal_lon)
         
         self.assertEqual(len(dms_lat), 3)
         self.assertEqual(
             dms_lat[0].numerator,
             floor(abs(decimal_lat))
         )
         
         self.assertEqual(len(dms_lon), 3)
         self.assertEqual(
             dms_lon[0].numerator,
             floor(abs(decimal_lon))
         )
         
         self.assertAlmostEqual(
             decimal_lat,
             dms_to_decimal(*rats_to_fracs(dms_lat) + ['N' if decimal_lat >= 0 else 'S']),
             10 # equal to 10 places
         )
         self.assertAlmostEqual(
             decimal_lon,
             dms_to_decimal(*rats_to_fracs(dms_lon) + ['E' if decimal_lon >= 0 else 'W']),
             10 # equal to 10 places
         )