def loadTags(self, dirName):
        if dirName == "":
            return

        self.lstTags.clear()

        etPath = utils.getExifToolPath()
        if not etPath == "":
            etPath = os.path.join(os.path.normpath(unicode(etPath)),
                                  "exiftool")
        else:
            etPath = "exiftool"

        # config file
        cfgFile = self.leConfigFile.text()
        if cfgFile == "":
            cfgFile = utils.getConfigPath()

        if cfgFile != "":
            etPath += " -config " + unicode(cfgFile)

        et = exiftool.ExifTool(etPath)

        md = None
        found = False

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        # fetch metadata from first photo
        with et:
            for root, dirs, files in os.walk(unicode(dirName)):
                if len(files) == 0:
                    continue

                for f in files:
                    if f.lower().endswith(".jpg") or f.lower().endswith(
                            ".jpeg"):
                        md = et.get_metadata(os.path.join(root, f))
                        if len(md) > 0:
                            found = True
                            break

                if found:
                    break

        # process metadata and populate tag list
        for k, v in md.iteritems():
            if not k.startswith("EXIF:"):
                continue
            ti = QTreeWidgetItem(self.lstTags)
            ti.setText(0, k)
            ti.setCheckState(0, Qt.Unchecked)
        self.lstTags.sortItems(0, Qt.AscendingOrder)

        QApplication.restoreOverrideCursor()
    def loadTags(self, dirName):
        if dirName == "":
            return

        self.lstTags.clear()

        etPath = utils.getExifToolPath()
        if not etPath == "":
            etPath = os.path.join(os.path.normpath(unicode(etPath)), "exiftool")
        else:
            etPath = "exiftool"

        # config file
        cfgFile = self.leConfigFile.text()
        if cfgFile == "":
            cfgFile = utils.getConfigPath()

        if cfgFile != "":
            etPath += " -config " + unicode(cfgFile)

        et = exiftool.ExifTool(etPath)

        md = None
        found = False

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        # fetch metadata from first photo
        with et:
            for root, dirs, files in os.walk(unicode(dirName)):
                if len(files) == 0:
                    continue

                for f in files:
                    if f.lower().endswith(".jpg") or f.lower().endswith(".jpeg"):
                        md = et.get_metadata(os.path.join(root, f))
                        if len(md) > 0:
                            found = True
                            break

                if found:
                    break

        # process metadata and populate tag list
        for k, v in md.iteritems():
            if not k.startswith("EXIF:"):
                continue
            ti = QTreeWidgetItem(self.lstTags)
            ti.setText(0, k)
            ti.setCheckState(0, Qt.Unchecked)
        self.lstTags.sortItems(0, Qt.AscendingOrder)

        QApplication.restoreOverrideCursor()
    def run(self):
        if self.appendFile:
            layer = self.openExistingLayer()
            print "LAYER OPENED"
        else:
            layer = self.createNewLayer()

        provider = layer.dataProvider()
        fields = provider.fields()

        if not set(self.tagsList).issuperset(self.geotags):
            self.tagsList.extend(self.geotags)

        etPath = utils.getExifToolPath()
        if etPath != "":
            etPath = os.path.join(os.path.normpath(unicode(etPath)), "exiftool")
        else:
            etPath = "exiftool"

        # config file
        if self.config != "":
            etPath += " -config " + unicode(self.config)

        et = exiftool.ExifTool(etPath)

        filters = QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot
        nameFilter = ["*.jpg", "*.jpeg", "*.JPG", "*.JPEG"]

        count = 0

        with et:
            for root, dirs, files in os.walk(unicode(self.photosDir)):
                fileCount = len(QDir(root).entryList(nameFilter, filters))
                if fileCount > 0:
                    self.rangeChanged.emit([self.tr("Import: %p%"), fileCount])
                    for f in files:
                        if os.path.splitext(f)[1] not in self.wildcards:
                            continue
                        fName = os.path.normpath(os.path.join(root, f))
                        md = et.get_tags(self.tagsList, unicode(fName))

                        # create new feature
                        ft = QgsFeature()
                        ft.setFields(fields)
                        print "FEATURE INITIALIZED"

                        for k, v in md.iteritems():
                            tagName = k.replace("EXIF:", "")
                            if tagName in self.tagFieldMap.keys():
                                ft[self.tagFieldMap[tagName]] = unicode(v)

                        # hardcoded fields
                        if "filepath" in self.fieldNames:
                            ft["filepath"] = os.path.join(root, f)
                        if "filename" in self.fieldNames:
                            ft["filename"] = f

                        # get geometry
                        if not set(md.keys()).issuperset(self.geotags):
                            pass
                        else:
                            lat = float(md["EXIF:GPSLatitude"])
                            lon = float(md["EXIF:GPSLongitude"])
                            if md["EXIF:GPSLongitudeRef"] == "W":
                                lon = 0 - lon
                            if md["EXIF:GPSLatitudeRef"] == "S":
                                lat = 0 - lat

                            ft.setGeometry(QgsGeometry.fromPoint(QgsPoint(lon, lat)))
                            count += 1

                        if ft.geometry() is not None:
                            provider.addFeatures([ft])

                        self.updateProgress.emit()

                        self.mutex.lock()
                        s = self.stopMe
                        self.mutex.unlock()
                        if s == 1:
                            self.interrupted = True
                            break

                if not self.recurseDir:
                    break

        haveShape = True
        if count == 0:
            if not self.appendFile:
                QgsVectorFileWriter.deleteShapeFile(self.outFileName)
            haveShape = False

        if not self.interrupted:
            self.processFinished.emit(haveShape)
        else:
            self.processInterrupted.emit()
示例#4
0
    def run(self):
        if self.appendFile:
            layer = self.openExistingLayer()
            print "LAYER OPENED"
        else:
            layer = self.createNewLayer()

        provider = layer.dataProvider()
        fields = provider.fields()

        if not set(self.tagsList).issuperset(self.geotags):
            self.tagsList.extend(self.geotags)

        etPath = utils.getExifToolPath()
        if etPath != "":
            etPath = os.path.join(os.path.normpath(unicode(etPath)),
                                  "exiftool")
        else:
            etPath = "exiftool"

        # config file
        if self.config != "":
            etPath += " -config " + unicode(self.config)

        et = exiftool.ExifTool(etPath)

        filters = QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot
        nameFilter = ["*.jpg", "*.jpeg", "*.JPG", "*.JPEG"]

        count = 0

        with et:
            for root, dirs, files in os.walk(unicode(self.photosDir)):
                fileCount = len(QDir(root).entryList(nameFilter, filters))
                if fileCount > 0:
                    self.rangeChanged.emit([self.tr("Import: %p%"), fileCount])
                    for f in files:
                        if os.path.splitext(f)[1] not in self.wildcards:
                            continue
                        fName = os.path.normpath(os.path.join(root, f))
                        md = et.get_tags(self.tagsList, unicode(fName))

                        # create new feature
                        ft = QgsFeature()
                        ft.setFields(fields)
                        print "FEATURE INITIALIZED"

                        for k, v in md.iteritems():
                            tagName = k.replace("EXIF:", "")
                            if tagName in self.tagFieldMap.keys():
                                ft[self.tagFieldMap[tagName]] = unicode(v)

                        # hardcoded fields
                        if "filepath" in self.fieldNames:
                            ft["filepath"] = os.path.join(root, f)
                        if "filename" in self.fieldNames:
                            ft["filename"] = f

                        # get geometry
                        if not set(md.keys()).issuperset(self.geotags):
                            pass
                        else:
                            lat = float(md["EXIF:GPSLatitude"])
                            lon = float(md["EXIF:GPSLongitude"])
                            if md["EXIF:GPSLongitudeRef"] == "W":
                                lon = 0 - lon
                            if md["EXIF:GPSLatitudeRef"] == "S":
                                lat = 0 - lat

                            ft.setGeometry(
                                QgsGeometry.fromPoint(QgsPoint(lon, lat)))
                            count += 1

                        if ft.geometry() is not None:
                            provider.addFeatures([ft])

                        self.updateProgress.emit()

                        self.mutex.lock()
                        s = self.stopMe
                        self.mutex.unlock()
                        if s == 1:
                            self.interrupted = True
                            break

                if not self.recurseDir:
                    break

        haveShape = True
        if count == 0:
            if not self.appendFile:
                QgsVectorFileWriter.deleteShapeFile(self.outFileName)
            haveShape = False

        if not self.interrupted:
            self.processFinished.emit(haveShape)
        else:
            self.processInterrupted.emit()
 def manageGui(self):
     self.leExifToolPath.setText(utils.getExifToolPath())
     self.leConfigPath.setText(utils.getConfigPath())
示例#6
0
 def manageGui(self):
     self.leExifToolPath.setText(utils.getExifToolPath())
     self.leConfigPath.setText(utils.getConfigPath())
    def runRename(self):
        etPath = utils.getExifToolPath()
        if etPath != "":
            etPath = os.path.join(os.path.normpath(unicode(etPath)), "exiftool")
        else:
            etPath = "exiftool"

        et = exiftool.ExifTool(etPath)

        filters = QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot
        nameFilter = ["*.jpg", "*.jpeg", "*.JPG", "*.JPEG"]

        rows = self.model.rowCount()

        with et:
            for r in xrange(rows):
                if self.interrupted:
                    break

                item = self.model.item(r, 3)
                if item is None:
                    continue
                if item and item.text() == "":
                    continue

                dirName = unicode(self.model.item(r, 3).text())
                areaName = os.path.basename(dirName)

                for root, dirs, files in os.walk(unicode(dirName)):
                    fileCount = len(QDir(root).entryList(nameFilter, filters))
                    if fileCount > 0:
                        trapName = os.path.split(root)[1]

                        if trapName == areaName:
                            areaName = ""

                        self.rangeChanged.emit([self.tr("Renaming: %p%"), fileCount])

                        dt = ""
                        num = 0
                        zcount = len(str(fileCount))

                        for f in files:
                            fullPath = os.path.join(root, f)
                            if os.path.isfile(fullPath) and (os.path.splitext(fullPath)[1] in self.wildcards):
                                dt = et.get_tag("EXIF:DateTimeOriginal", unicode(fullPath))

                                if areaName == "":
                                    newName ="%s_%s_%s.jpg" % (trapName, dt.replace(":", "-").replace(" ", "_"), str(num).zfill(zcount))
                                else:
                                    newName = "%s_%s_%s_%s.jpg" % (areaName, trapName, dt.replace(":", "-").replace(" ", "_"), str(num).zfill(zcount))
                                num += 1

                                try:
                                    os.rename(fullPath, os.path.join(root, unicode(newName)))
                                except OSError, e:
                                    print e

                                self.updateProgress.emit()

                                self.mutex.lock()
                                s = self.stopMe
                                self.mutex.unlock()
                                if s == 1:
                                    self.interrupted = True
                                    break
    def runRename(self):
        etPath = utils.getExifToolPath()
        if etPath != "":
            etPath = os.path.join(os.path.normpath(unicode(etPath)),
                                  "exiftool")
        else:
            etPath = "exiftool"

        et = exiftool.ExifTool(etPath)

        filters = QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot
        nameFilter = ["*.jpg", "*.jpeg", "*.JPG", "*.JPEG"]

        rows = self.model.rowCount()

        with et:
            for r in xrange(rows):
                if self.interrupted:
                    break

                item = self.model.item(r, 3)
                if item is None:
                    continue
                if item and item.text() == "":
                    continue

                dirName = unicode(self.model.item(r, 3).text())
                areaName = os.path.basename(dirName)

                for root, dirs, files in os.walk(unicode(dirName)):
                    fileCount = len(QDir(root).entryList(nameFilter, filters))
                    if fileCount > 0:
                        trapName = os.path.split(root)[1]

                        if trapName == areaName:
                            areaName = ""

                        self.rangeChanged.emit(
                            [self.tr("Renaming: %p%"), fileCount])

                        dt = ""
                        num = 0
                        zcount = len(str(fileCount))

                        for f in files:
                            fullPath = os.path.join(root, f)
                            if os.path.isfile(fullPath) and (
                                    os.path.splitext(fullPath)[1]
                                    in self.wildcards):
                                dt = et.get_tag("EXIF:DateTimeOriginal",
                                                unicode(fullPath))

                                if areaName == "":
                                    newName = "%s_%s_%s.jpg" % (
                                        trapName, dt.replace(":", "-").replace(
                                            " ", "_"), str(num).zfill(zcount))
                                else:
                                    newName = "%s_%s_%s_%s.jpg" % (
                                        areaName, trapName, dt.replace(
                                            ":", "-").replace(" ", "_"),
                                        str(num).zfill(zcount))
                                num += 1

                                try:
                                    os.rename(
                                        fullPath,
                                        os.path.join(root, unicode(newName)))
                                except OSError, e:
                                    QgsMessageLog.logMessage(
                                        e,
                                        tag='Geotag and import photos',
                                        level=QgsMessageLog.CRITICAL)

                                self.updateProgress.emit()

                                self.mutex.lock()
                                s = self.stopMe
                                self.mutex.unlock()
                                if s == 1:
                                    self.interrupted = True
                                    break