Beispiel #1
0
def set_gps_location(file_name, lat, lng, alt, t):
    """
    see: http://stackoverflow.com/questions/453395/what-is-the-best-way-to-geotag-jpeg-images-with-python
    
    Adds GPS position as EXIF metadata

    Keyword arguments:
    file_name -- image file 
    lat -- latitude (as float)
    lng -- longitude (as float)

    """

    m = pyexiv2.ImageMetadata(file_name)
    m.read()

    m["Exif.GPSInfo.GPSLatitude"] = mav_position.decimal_to_dms(lat)
    m["Exif.GPSInfo.GPSLatitudeRef"] = 'N' if lat >= 0 else 'S'
    m["Exif.GPSInfo.GPSLongitude"] = mav_position.decimal_to_dms(lng)
    m["Exif.GPSInfo.GPSLongitudeRef"] = 'E' if lng >= 0 else 'W'
    m["Exif.Image.GPSTag"] = 654
    m["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
    m["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
    m["Exif.Image.DateTime"] = datetime.datetime.fromtimestamp(t)

    try:
        m["Exif.GPSInfo.GPSAltitude"] = mav_position.Fraction(alt)
    except Exception:
        pass

    m.write()
Beispiel #2
0
def set_gps_location(file_name, lat, lng, alt, t):
    """
    see: http://stackoverflow.com/questions/453395/what-is-the-best-way-to-geotag-jpeg-images-with-python
    
    Adds GPS position as EXIF metadata

    Keyword arguments:
    file_name -- image file 
    lat -- latitude (as float)
    lng -- longitude (as float)

    """

    lat_deg = to_deg(lat, ["S", "N"])
    lng_deg = to_deg(lng, ["W", "E"])

    # convert decimal coordinates into degrees, munutes and seconds
    exiv_lat = (pyexiv2.Rational(lat_deg[0] * 60 + lat_deg[1],
                                 60), pyexiv2.Rational(lat_deg[2] * 100, 6000),
                pyexiv2.Rational(0, 1))
    exiv_lng = (pyexiv2.Rational(lng_deg[0] * 60 + lng_deg[1],
                                 60), pyexiv2.Rational(lng_deg[2] * 100, 6000),
                pyexiv2.Rational(0, 1))

    m = pyexiv2.ImageMetadata(file_name)
    m.read()

    m["Exif.GPSInfo.GPSLatitude"] = exiv_lat
    m["Exif.GPSInfo.GPSLatitudeRef"] = lat_deg[3]
    m["Exif.GPSInfo.GPSLongitude"] = exiv_lng
    m["Exif.GPSInfo.GPSLongitudeRef"] = lng_deg[3]
    m["Exif.Image.GPSTag"] = 654
    m["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"
    m["Exif.GPSInfo.GPSVersionID"] = '2 0 0 0'
    m["Exif.Image.DateTime"] = datetime.datetime.fromtimestamp(t)

    try:
        m["Exif.GPSInfo.GPSAltitude"] = mav_position.Fraction(alt)
    except Exception:
        pass

    m.write()
Beispiel #3
0
def test_Fraction():
    fr = mav_position.Fraction(0.3)
    assert fr == fractions.Fraction(3, 10)