Mam problem z kodem: "Ifdracyjny" obiekt nie jest subskryptowany

Oto ślad:

lat = get_decimal_from_dms(geotags['GPSLatitude'], geotags['GPSLatitudeRef'])
degrees = dms[0][0] / dms[0][1] 

Problemem jest: Wartość zmienna DMS (45,0, 46,0, 34.29) Ref 'n'

{'GPSAltitude': 22.90324416619237,
 'GPSAltitudeRef': b'\x00',
 'GPSDateStamp': '2020:10:17',
 'GPSDestBearing': 18.1919587128,
 'GPSDestBearingRef': 'M',
 'GPSHPositioningError': 65.0,
 'GPSImgDirection': 108.199192887128,
 'GPSImgDirectionRef': 'M',
 'GPSLatitude': (12.0, 26.0, 14.09),
 'GPSLatitudeRef': 'N',
 'GPSLongitude': (1.0, 47.0, 39.38),
 'GPSLongitudeRef': 'E',
 'GPSSpeed': 0.0,
 'GPSSpeedRef': 'K',
 'GPSTimeStamp': (12.0, 58.0, 42.0)}

Na przykład na przykład z obrazu. Myślę, że kod asymiluje Gplatituderef do stopni = DMS [0] [0] / DMS [0] [1]. Rzecz jest gpslatituderef jest literą nie ma numeru.

def get_geotagging(exifgps):
    
        geotagging = {}
        for (idx, tag) in TAGS.items():
            if tag == 'GPSInfo':
                if idx not in exifgps:
                    raise ValueError("No EXIF geotagging found")
    
                for (key, val) in GPSTAGS.items():
                    if key in exifgps[idx]:
                        geotagging[val] = exifgps[idx][key]
    
        return geotagging
        
    def get_decimal_from_dms(dms, ref):

        degrees = dms[0][0] / dms[0][1]
        minutes = dms[1][0] / dms[1][1] / 60.0
        seconds = dms[2][0] / dms[2][1] / 3600.0
    
        if ref in ['S', 'W']:
            degrees = -degrees
            minutes = -minutes
            seconds = -seconds
    
        return round(degrees + minutes + seconds, 5)
        
    def get_lat_coordinates(geotags):
            lat = get_decimal_from_dms(geotags['GPSLatitude'], geotags['GPSLatitudeRef'])
            return lat
            
    def get_lon_coordinates(geotags):
            lon = get_decimal_from_dms(geotags['GPSLongitude'], geotags['GPSLongitudeRef'])
            return lon

try:
            exifgps = img.getexif()
            geotags = get_geotagging(exifgps)
            self.gpsinfo = geotags
        except Exception as e:
                pass
        
        #try:
        exifgps = img.getexif()
        geotags = get_geotagging(exifgps)
        self.latitude = get_lat_coordinates(geotags)
        #except Exception as e:
                #pass
        
        #try:
        exifgps = img.getexif()
        geotags = get_geotagging(exifgps)
        self.longitude = get_lon_coordinates(geotags)
        #except Exception as e:
                #pass
1
Beginner 17 październik 2020, 20:27

1 odpowiedź

Najlepsza odpowiedź

Nie mogę zrozumieć, dlaczego degrees = dms[0][0] / dms[0][1] jest konieczne, gdy można po prostu wyodrębnić stopnie z krotki za pomocą degrees = dms[0]

Wymień

def get_decimal_from_dms(dms, ref):

    degrees = dms[0][0] / dms[0][1]
    minutes = dms[1][0] / dms[1][1] / 60.0
    seconds = dms[2][0] / dms[2][1] / 3600.0

Z

def get_decimal_from_dms(dms, ref):

    degrees = dms[0]
    minutes = dms[1] / 60.0
    seconds = dms[2] / 3600.0
2
Luke 10 marzec 2021, 06:09