当前位置: 首页>>代码示例>>Python>>正文


Python ExifTags.GPSTAGS类代码示例

本文整理汇总了Python中PIL.ExifTags.GPSTAGS的典型用法代码示例。如果您正苦于以下问题:Python GPSTAGS类的具体用法?Python GPSTAGS怎么用?Python GPSTAGS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GPSTAGS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ExtractLatLon

def ExtractLatLon(gps):
    # to perform the calculation we need at least
    # lat, lon, latRef and lonRef
    if (
        GPSTAGS.has_key("GPSLatitude")
        and GPSTAGS.has_key("GPSLongitude")
        and GPSTAGS.has_key("GPSLatitudeRef")
        and GPSTAGS.has_key("GPSLatitudeRef")
    ):
        latitude = gps["GPSLatitude"]
        latitudeRef = gps["GPSLatitudeRef"]
        longitude = gps["GPSLongitude"]
        longitudeRef = gps["GPSLongitudeRef"]
        lat = ConvertToDegrees(latitude)
        lon = ConvertToDegrees(longitude)
        # Check Latitude Reference
        # If South of the Equator then lat value is negative
        if latitudeRef == "S":
            lat = 0 - lat
        # Check Longitude Reference
        # If West of the Prime Meridian in
        # Greenwich then the Longitude value is negative
        if longitudeRef == "W":
            lon = 0 - lon
        gpsCoor = {"Lat": lat, "LatRef": latitudeRef, "Lon": lon, "LonRef": longitudeRef}
        return gpsCoor
    else:
        return None
开发者ID:Draft2007,项目名称:Scripts,代码行数:28,代码来源:_modEXIF.py

示例2: extractCoordinates

def extractCoordinates(exifValue):
    latRef = None
    longitRef = None
    lat = None
    longit = None

    #geocoding
    gpsData = {}
    for gpsTag in exifValue:
        tagElem = GPSTAGS.get(gpsTag, gpsTag)
        gpsData[tagElem] = exifValue[gpsTag]

    if "GPSLatitude" in gpsData:
        lat =  gpsData["GPSLatitude"]
        lat = decimalCoordinatesToDegress(lat)
    if "GPSLongitude" in gpsData:
        longit =  gpsData["GPSLongitude"]
        longit = decimalCoordinatesToDegress(longit)
    if "GPSLatitudeRef" in gpsData:
        latRef =  gpsData["GPSLatitudeRef"]
    if "GPSLongitudeRef" in gpsData:
        longitRef =  gpsData["GPSLongitudeRef"]

    if latRef is not None and latRef != "N":
        lat = 0 - lat
    if longitRef is not None and longitRef != "E":
        longit = 0 - longit

    return lat,longit
开发者ID:hifly81,项目名称:photox,代码行数:29,代码来源:geoUtil.py

示例3: getGPSTags

def getGPSTags(imagePath):
    image = Image.open(imagePath)
    #Get the EXIF data from the image.
    rawEXIF = image._getexif()

    #Somewhere to store the rest of the EXIF data, I might use it one day.
    tags = {}

    #Aaand a place to store the GPS data.
    gpsTags = {}

    #pulling out the EXIF tags.
    for tag, value in rawEXIF.items():
        decoded = TAGS.get(tag,tag)
        tags[decoded] = value

    rawGPS = tags['GPSInfo']

    #Pulling out the GPS specific tags.
    for gpstag , value in rawGPS.items():
        decoded = GPSTAGS.get(gpstag,gpstag)
        gpsTags[decoded] = value

    #Pull together our return variable that includes both tagsets.
    return {'tags' : tags, 'gps' : gpsTags}
开发者ID:rollinginsanity,项目名称:NameTheLocation,代码行数:25,代码来源:GPSFuncs.py

示例4: get_exif_data

def get_exif_data(image):
    """Returns a dictionary from the exif data of an PIL Image item. Also converts the GPS Tags"""

    try:
        info = image._getexif()
    except AttributeError:
        return {}
    if not info:
        return {}
    exif_data = {TAGS.get(tag, tag): value for tag, value in info.items()}

    def is_fraction(val):
        return isinstance(val, tuple) and len(val) == 2 and isinstance(val[0], int) and isinstance(val[1], int)

    def frac_to_dec(frac):
        return float(frac[0]) / float(frac[1])

    if "GPSInfo" in exif_data:
        gpsinfo = {GPSTAGS.get(t, t): v for t, v in exif_data["GPSInfo"].items()}
        for tag, value in gpsinfo.items():
            if is_fraction(value):
                gpsinfo[tag] = frac_to_dec(value)
            elif all(is_fraction(x) for x in value):
                gpsinfo[tag] = tuple(map(frac_to_dec, value))
        exif_data["GPSInfo"] = gpsinfo
    return exif_data
开发者ID:realyasswl,项目名称:vc,代码行数:26,代码来源:info.py

示例5: get_exif_data

def get_exif_data(image):
    """Return a dict from the exif data of a PIL Image and convert the GPS
    tags.
    """

    exif_data = {}
    info = image._getexif()

    if info:
        for tag, value in info.items():
            decoded = TAGS.get(tag, tag)

            if decoded == "GPSInfo":
                gps_data = {}

                for gps_tag in value:
                    sub_decoded = GPSTAGS.get(gps_tag, gps_tag)
                    gps_data[sub_decoded] = value[gps_tag]

                exif_data[decoded] = gps_data

            else:
                exif_data[decoded] = value

    return exif_data
开发者ID:tylertreat,项目名称:Kanna,代码行数:25,代码来源:exif.py

示例6: get_exif_header

def get_exif_header(image):
   """Returns a dictionary from the exif header of an PIL Image. Also converts the GPS Tags.

   Args:
      image: 
   """
   try:
      info = image._getexif()
   except:
      raise gserror.EmptyExifHeaderError('could not found the exif header')
   
   if not info:
      raise gserror.EmptyExifHeaderError('empty exif header')
   
   exif_header = {}   
   for tag, value in info.items():
      tag_id = TAGS.get(tag, tag)
      if tag_id == __EXIF_GPS_INFO:
         gps_info = {}
         for t in value:
            gps_tag_id = GPSTAGS.get(t, t)
            gps_info[gps_tag_id] = value[t]
         exif_header[tag_id] = gps_info
      else:
         exif_header[tag_id] = value
   return exif_header
开发者ID:pavelsimo,项目名称:GeoSearchEngine,代码行数:26,代码来源:gsutils.py

示例7: _get_exif_data

    def _get_exif_data(self, image):
        """Returns a dictionary from the exif data of an PIL Image item.
        Also converts the GPS Tags"""

        exif_data = {}
        try:
            info = image._getexif()
        except AttributeError:
            return exif_data
        except IndexError:
            return exif_data
        if info:
            for tag, value in info.items():
                decoded = TAGS.get(tag, tag)
                if decoded == "GPSInfo":
                    gps_data = {}
                    for t in value:
                        sub_decoded = GPSTAGS.get(t, t)
                        gps_data[sub_decoded] = value[t]

                    exif_data[decoded] = gps_data
                else:
                    exif_data[decoded] = value

        return exif_data
开发者ID:BastiTee,项目名称:pyntrest,代码行数:25,代码来源:pyntrest_pil.py

示例8: readExif

def readExif(exif):

    
    data = {}
    exif_data = {}
    gps_data = {}
 
    if exif is None:
        return data
    
    for k,v in exif.items():
       if k in tag_name_to_id:
           data[tag_name_to_id[k]] = v
       decoded = TAGS.get(k, k)
       if decoded == "GPSInfo":
           for t in v:
               sub_decoded = GPSTAGS.get(t, t)
               gps_data[sub_decoded] = v[t]

           exif_data[decoded] = gps_data
       else:
           exif_data[decoded] = v
       
       #else:
       #   data[k] = v
 
    data['GPSInfo'] = gps_data
 
    # These fields are in UCS2/UTF-16, convert to something usable within python
    for k in ['XPTitle', 'XPComment', 'XPAuthor', 'XPKeywords', 'XPSubject']:
        if k in data:
            data[k] = data[k].decode('utf-16').rstrip('\x00')

    print data
    return data
开发者ID:mov-q,项目名称:gimsey,代码行数:35,代码来源:imgfuncs.py

示例9: _extract_gpsinfo

def _extract_gpsinfo(values):
    lat = None
    lon = None
    altitude = None
    gps_data = {}
    for t in values:
        sub_decoded = GPSTAGS.get(t, t)
        gps_data[sub_decoded] = values[t]

    gps_lat = _get_if_exist(gps_data, "GPSLatitude")
    gps_lat_ref = _get_if_exist(gps_data, 'GPSLatitudeRef')
    gps_lon = _get_if_exist(gps_data, 'GPSLongitude')
    gps_lon_ref = _get_if_exist(gps_data, 'GPSLongitudeRef')

    if gps_lat and gps_lat_ref and gps_lon and gps_lon_ref:
        lat = _convert_to_degress(gps_lat)
        if gps_lat_ref != "N":
            lat = 0 - lat

        lon = _convert_to_degress(gps_lon)
        if gps_lon_ref != "E":
            lon = 0 - lon

    altitude = _get_if_exist(gps_data, 'GPSAltitude')
    if altitude:
        altitude = _frac_to_float(altitude)
    return (lat, lon, altitude, gps_data)
开发者ID:gregpac,项目名称:cartoterra,代码行数:27,代码来源:forms.py

示例10: extract

    def extract(self, filepath):
        fd = Image.open(filepath)
        exif = fd._getexif() # raw exif
        gps = {} # raw undecoded gps
        results = {} 

        if exif:
            for (k, v) in exif.items():
                results[TAGS.get(k, k)] = v

        if exif and ExifExtract.GPSINFO in exif:
            for t in exif[ExifExtract.GPSINFO]:
                sub_decoded = GPSTAGS.get(t, t)
                gps[sub_decoded] = exif[ExifExtract.GPSINFO][t]

        if 'GPSLatitude' in gps and 'GPSLatitudeRef' in gps and 'GPSLongitude' in gps and 'GPSLongitudeRef' in gps:
            lat_deg = self._to_degrees(gps['GPSLatitude'])
            if 'N' is not gps['GPSLatitudeRef']:
                lat_deg *= -1

            lng_deg = self._to_degrees(gps['GPSLongitude'])
            if 'E' is not gps['GPSLongitudeRef']:
                lng_deg *= -1

            results['GPS'] = {
                'longitude': lng_deg,
                'latitude': lat_deg
            }

        return results
开发者ID:jacobgreenleaf,项目名称:thorn-metadata,代码行数:30,代码来源:extract.py

示例11: get_exif_data

def get_exif_data(filename):
    """Return a dict with the raw EXIF data."""

    logger = logging.getLogger(__name__)

    if PIL.PILLOW_VERSION == '3.0.0':
        warnings.warn('Pillow 3.0.0 is broken with EXIF data, consider using '
                      'another version if you want to use EXIF data.')

    img = PILImage.open(filename)
    try:
        exif = img._getexif() or {}
    except ZeroDivisionError:
        logger.warning('Failed to read EXIF data.')
        return None

    data = {TAGS.get(tag, tag): value for tag, value in exif.items()}

    if 'GPSInfo' in data:
        try:
            data['GPSInfo'] = {GPSTAGS.get(tag, tag): value
                               for tag, value in data['GPSInfo'].items()}
        except AttributeError:
            logger = logging.getLogger(__name__)
            logger.info('Failed to get GPS Info')
            del data['GPSInfo']
    return data
开发者ID:Ev4ngelos,项目名称:sigal,代码行数:27,代码来源:image.py

示例12: show_geodata_for_image

def show_geodata_for_image(imageSrc, imageFilePath):
	"""
	Searches for GPS data in the image and shows it if found and valid.
	"""
	exitData = {}
	try:
		imageFile = Image.open(imageFilePath)
		info = imageFile._getexif()
	except:
		return

	if info:
		for (tag, value) in info.items():
			decoded = TAGS.get(tag, tag)
			if decoded == 'GPSInfo':
				gpsData = {}
				for t in value:
					decodedGps = GPSTAGS.get(t, t)
					gpsData[decodedGps] = value[t]

				if 'GPSLatitude' in gpsData and 'GPSLatitudeRef' in gpsData and 'GPSLongitude' in gpsData and 'GPSLongitudeRef' in gpsData:
					latitude = convert_to_degrees(gpsData['GPSLatitude'])
					if gpsData['GPSLatitudeRef'] != 'N':
						latitude = 0 - latitude
					longitude = convert_to_degrees(gpsData['GPSLongitude'])
					if gpsData['GPSLongitude'] != 'E':
						longitude = 0 - longitude
					if latitude !=0 and longitude != 0:
						print 'GPS data for %s: latitude=%f%s, longitude=%f%s' % (imageSrc, latitude, gpsData['GPSLatitudeRef'], longitude, gpsData['GPSLongitudeRef'])

				break
开发者ID:dmitryd,项目名称:violent-python-book,代码行数:31,代码来源:show_geo_from_web.py

示例13: get_exif_data

def get_exif_data(image):
    """Returns a dictionary from the exif data of a PIL Image item. Also converts the GPS Tags"""

    exif_data = {}
    print "BEFORE"
    info = image._getexif()
    # print image
    # info = image.tag.tags
    print "AFTER"
    if info:
        "IN INFO"
        for tag, value in info.items():
            decoded = TAGS.get(tag, tag)
            print tag
            if decoded == "GPSInfo":
                gps_data = {}

                for t in value:
                    sub_decoded = GPSTAGS.get(t, t)
                    gps_data[sub_decoded] = value[t]

                exif_data[decoded] = gps_data

            else:
                exif_data[decoded] = value

    return exif_data
开发者ID:HarryUp,项目名称:photoproject,代码行数:27,代码来源:allfunctions.py

示例14: get_exif_data

def get_exif_data(image):
    """
    Returns a dictionary from the exif data of an PIL Image item.
    Also converts the GPS Tags
    https://gist.github.com/valgur/2fbed04680864fab1bfc
    """

    info = image._getexif()
    if not info:
        return {}
    exif_data = {TAGS.get(tag, tag): value for tag, value in info.items()}

    def is_fraction(val):
        return isinstance(val, tuple) and len(val) == 2 and isinstance(
            val[0], int) and isinstance(val[1], int)

    def frac_to_dec(frac):
        return float(frac[0]) / float(frac[1])

    if 'GPSInfo' in exif_data:
        gpsinfo = {GPSTAGS.get(t, t): v
                   for t, v in exif_data['GPSInfo'].items()}
        for tag, value in gpsinfo.items():
            if is_fraction(value):
                gpsinfo[tag] = frac_to_dec(value)
            elif all(is_fraction(x) for x in value):
                gpsinfo[tag] = tuple(map(frac_to_dec, value))
        exif_data['GPSInfo'] = gpsinfo

    return exif_data
开发者ID:onewhaleid,项目名称:photo2kml,代码行数:30,代码来源:photo2kml.py

示例15: ExtractGPSDictionary

def ExtractGPSDictionary(fileName):
     
    try:
        pilImage = Image.open(fileName)
        exifData = pilImage._getexif()
    
    except Exception:
        # If exception occurs from PIL processing
        # Report the 
        return None, None
    
    # Interate through the exifData
    # Searching for GPS Tags
    
    imageTimeStamp = "NA"
    cameraModel = "NA"
    cameraMake = "NA"
    gpsData = False
    
    gpsDictionary = {}
    
    if exifData:
            
        for tag, theValue in exifData.items():
                
            # obtain the tag
            tagValue = TAGS.get(tag, tag)
                
            # Collect basic image data if available
            
            if tagValue == 'DateTimeOriginal':
                imageTimeStamp = exifData.get(tag)
                
            if tagValue == "Make":
                cameraMake = exifData.get(tag)
                
            if tagValue == 'Model':
                cameraModel = exifData.get(tag)
                
            # check the tag for GPS
            if tagValue == "GPSInfo":
                
                gpsData = True;
                
                # Found it !
                # Now create a Dictionary to hold the GPS Data
                
                # Loop through the GPS Information
                for curTag in theValue:
                    gpsTag = GPSTAGS.get(curTag, curTag)
                    gpsDictionary[gpsTag] = theValue[curTag]
                
                basicExifData = [imageTimeStamp, cameraMake, cameraModel]    
                
                return gpsDictionary, basicExifData
            
        if gpsData == False:
            return None, None
    else:
        return None, None
开发者ID:jmonmane,项目名称:scratch,代码行数:60,代码来源:_modEXIF.py


注:本文中的PIL.ExifTags.GPSTAGS类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。