예제 #1
0
def getRasterFiles(path, recursive=False):
    rasters = []
    if not QFileInfo(path).exists():
        return rasters

    # TODO remove *.aux.xml
    _filter = getRasterExtensions()
    workDir = QDir(path)
    workDir.setFilter(QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot)
    workDir.setNameFilters(_filter)
    files = workDir.entryList()
    for f in files:
        rasters.append(path + "/" + f)

    if recursive:
        for myRoot, myDirs, myFiles in os.walk(unicode(path)):
            for dir in myDirs:
                workDir = QDir(myRoot + "/" + dir)
                workDir.setFilter(QDir.Files | QDir.NoSymLinks
                                  | QDir.NoDotAndDotDot)
                workDir.setNameFilters(_filter)
                workFiles = workDir.entryList()
                for f in workFiles:
                    rasters.append(myRoot + "/" + dir + "/" + f)

    return rasters
예제 #2
0
def getRasterFiles(path, recursive=False):
    rasters = []
    if not QFileInfo(path).exists():
        return rasters

    # TODO remove *.aux.xml
    _filter = getRasterExtensions()
    workDir = QDir(path)
    workDir.setFilter(QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot)
    workDir.setNameFilters(_filter)
    files = workDir.entryList()
    for f in files:
        rasters.append(path + "/" + f)

    if recursive:
        for myRoot, myDirs, myFiles in os.walk(unicode(path)):
            for dir in myDirs:
                workDir = QDir(myRoot + "/" + dir)
                workDir.setFilter(QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot)
                workDir.setNameFilters(_filter)
                workFiles = workDir.entryList()
                for f in workFiles:
                    rasters.append(myRoot + "/" + dir + "/" + f)

    return rasters
예제 #3
0
파일: doWarp.py 프로젝트: Antoviscomi/QGIS
    def fillInputDir(self):
        inputDir = Utils.FileDialog.getExistingDirectory(self, self.tr("Select the input directory with files to Warp"))
        if not inputDir:
            return

        self.inSelector.setFilename(inputDir)

        filter = Utils.getRasterExtensions()
        workDir = QDir(inputDir)
        workDir.setFilter(QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot)
        workDir.setNameFilters(filter)
        if len(workDir.entryList()) > 0:
            fl = inputDir + "/" + workDir.entryList()[0]
            self.sourceSRSEdit.setText(Utils.getRasterSRS(self, fl))
예제 #4
0
    def fillInputDir(self):
        inputDir = Utils.FileDialog.getExistingDirectory(
            self, self.tr("Select the input directory with files to Warp"))
        if not inputDir:
            return

        self.inSelector.setFilename(inputDir)

        filter = Utils.getRasterExtensions()
        workDir = QDir(inputDir)
        workDir.setFilter(QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot)
        workDir.setNameFilters(filter)
        if len(workDir.entryList()) > 0:
            fl = inputDir + "/" + workDir.entryList()[0]
            self.sourceSRSEdit.setText(Utils.getRasterSRS(self, fl))
예제 #5
0
    def batchRun(self):
        exts = re.sub('\).*$', '', re.sub('^.*\(', '', self.formatCombo.currentText())).split(" ")
        if len(exts) > 0 and exts[0] != "*" and exts[0] != "*.*":
            outExt = exts[0].replace("*", "")
        else:
            outExt = ".tif"

        self.base.enableRun(False)
        self.base.setCursor(Qt.WaitCursor)

        inDir = self.getInputFileName()
        outDir = self.getOutputFileName()

        extensions = Utils.getRasterExtensions()
        workDir = QDir(inDir)
        workDir.setFilter(QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot)
        workDir.setNameFilters(extensions)
        files = workDir.entryList()

        self.inFiles = []
        self.outFiles = []

        for f in files:
            self.inFiles.append(inDir + "/" + f)
            if outDir is not None:
                outFile = re.sub("\.[a-zA-Z0-9]{2,4}", outExt, f)
                self.outFiles.append(outDir + "/" + outFile)

        self.errors = []
        self.batchIndex = 0
        self.batchTotal = len(self.inFiles)
        self.setProgressRange(self.batchTotal)

        self.runItem(self.batchIndex, self.batchTotal)
예제 #6
0
    def fillInputDir(self):
        inputDir = Utils.FileDialog.getExistingDirectory(self, self.tr("Select the input directory with files to Translate"))
        if not inputDir:
            return
        self.inSelector.setFilename(inputDir)

        filter = Utils.getRasterExtensions()
        workDir = QDir(inputDir)
        workDir.setFilter(QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot)
        workDir.setNameFilters(filter)

        # search for a valid SRS, then use it as default target SRS
        srs = ''
        for fname in workDir.entryList():
            fl = inputDir + "/" + fname
            srs = Utils.getRasterSRS(self, fl)
            if srs:
                break
        self.targetSRSEdit.setText(srs)
예제 #7
0
    def testStatistics(self):
        """Test zonal stats"""
        TEST_DATA_DIR = unitTestDataPath() + "/zonalstatistics/"
        myTempPath = QDir.tempPath() + "/"
        testDir = QDir(TEST_DATA_DIR)
        for f in testDir.entryList(QDir.Files):
            QFile.remove(myTempPath + f)
            QFile.copy(TEST_DATA_DIR + f, myTempPath + f)

        myVector = QgsVectorLayer(myTempPath + "polys.shp", "poly", "ogr")
        myRasterPath = myTempPath + "edge_problem.asc"
        zs = QgsZonalStatistics(myVector, myRasterPath, "", 1)
        zs.calculateStatistics(None)

        feat = QgsFeature()
        # validate statistics for each feature
        request = QgsFeatureRequest().setFilterFid(0)
        feat = next(myVector.getFeatures(request))
        myMessage = ('Expected: %f\nGot: %f\n' % (12.0, feat[1]))
        assert feat[1] == 12.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (8.0, feat[2]))
        assert feat[2] == 8.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (0.666666666666667, feat[3]))
        assert abs(feat[3] - 0.666666666666667) < 0.00001, myMessage

        request.setFilterFid(1)
        feat = next(myVector.getFeatures(request))
        myMessage = ('Expected: %f\nGot: %f\n' % (9.0, feat[1]))
        assert feat[1] == 9.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (5.0, feat[2]))
        assert feat[2] == 5.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (0.555555555555556, feat[3]))
        assert abs(feat[3] - 0.555555555555556) < 0.00001, myMessage

        request.setFilterFid(2)
        feat = next(myVector.getFeatures(request))
        myMessage = ('Expected: %f\nGot: %f\n' % (6.0, feat[1]))
        assert feat[1] == 6.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (5.0, feat[2]))
        assert feat[2] == 5.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (0.833333333333333, feat[3]))
        assert abs(feat[3] - 0.833333333333333) < 0.00001, myMessage
예제 #8
0
    def testStatistics(self):
        """Test zonal stats"""
        TEST_DATA_DIR = unitTestDataPath() + "/zonalstatistics/"
        myTempPath = QDir.tempPath() + "/"
        testDir = QDir(TEST_DATA_DIR)
        for f in testDir.entryList(QDir.Files):
            QFile.remove(myTempPath + f)
            QFile.copy(TEST_DATA_DIR + f, myTempPath + f)

        myVector = QgsVectorLayer(myTempPath + "polys.shp", "poly", "ogr")
        myRasterPath = myTempPath + "edge_problem.asc"
        zs = QgsZonalStatistics(myVector, myRasterPath, "", 1)
        zs.calculateStatistics(None)

        feat = QgsFeature()
        # validate statistics for each feature
        request = QgsFeatureRequest().setFilterFid(0)
        feat = next(myVector.getFeatures(request))
        myMessage = ('Expected: %f\nGot: %f\n' % (12.0, feat[1]))
        assert feat[1] == 12.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (8.0, feat[2]))
        assert feat[2] == 8.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (0.666666666666667, feat[3]))
        assert abs(feat[3] - 0.666666666666667) < 0.00001, myMessage

        request.setFilterFid(1)
        feat = next(myVector.getFeatures(request))
        myMessage = ('Expected: %f\nGot: %f\n' % (9.0, feat[1]))
        assert feat[1] == 9.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (5.0, feat[2]))
        assert feat[2] == 5.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (0.555555555555556, feat[3]))
        assert abs(feat[3] - 0.555555555555556) < 0.00001, myMessage

        request.setFilterFid(2)
        feat = next(myVector.getFeatures(request))
        myMessage = ('Expected: %f\nGot: %f\n' % (6.0, feat[1]))
        assert feat[1] == 6.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (5.0, feat[2]))
        assert feat[2] == 5.0, myMessage
        myMessage = ('Expected: %f\nGot: %f\n' % (0.833333333333333, feat[3]))
        assert abs(feat[3] - 0.833333333333333) < 0.00001, myMessage
예제 #9
0
    def getAllInstalled(self, testLoad=True):
        """ Build the localCache """
        self.localCache = {}

        # reversed list of the plugin paths: first system plugins -> then user plugins -> finally custom path(s)
        pluginPaths = list(plugin_paths)
        pluginPaths.reverse()

        for pluginsPath in pluginPaths:
            isTheSystemDir = (pluginPaths.index(pluginsPath) == 0
                              )  # The curent dir is the system plugins dir
            if isTheSystemDir:
                # temporarily add the system path as the first element to force loading the readonly plugins, even if masked by user ones.
                sys.path = [pluginsPath] + sys.path
            try:
                pluginDir = QDir(pluginsPath)
                pluginDir.setFilter(QDir.AllDirs)
                for key in pluginDir.entryList():
                    if key not in [".", ".."]:
                        path = QDir.convertSeparators(pluginsPath + "/" + key)
                        # readOnly = not QFileInfo(pluginsPath).isWritable() # On windows testing the writable status isn't reliable.
                        readOnly = isTheSystemDir  # Assume only the system plugins are not writable.
                        # only test those not yet loaded. Loaded plugins already proved they're o.k.
                        # failedToLoad = settings.value("/PythonPlugins/watchDog/" + key) is not None
                        testLoadThis = testLoad and key not in qgis.utils.plugins
                        plugin = self.getInstalledPlugin(key,
                                                         path=path,
                                                         readOnly=readOnly,
                                                         testLoad=testLoadThis)
                        self.localCache[key] = plugin
                        if key in self.localCache.keys() and compareVersions(
                                self.localCache[key]["version_installed"],
                                plugin["version_installed"]) == 1:
                            # An obsolete plugin in the "user" location is masking a newer one in the "system" location!
                            self.obsoletePlugins += [key]
            except:
                # it's not necessary to stop if one of the dirs is inaccessible
                pass

            if isTheSystemDir:
                # remove the temporarily added path
                sys.path.remove(pluginsPath)
예제 #10
0
    def batchRun(self):
        exts = re.sub('\).*$', '',
                      re.sub('^.*\(', '',
                             self.formatCombo.currentText())).split(" ")
        if len(exts) > 0 and exts[0] != "*" and exts[0] != "*.*":
            outExt = exts[0].replace("*", "")
        else:
            outExt = ".tif"

        self.base.enableRun(False)
        self.base.setCursor(Qt.WaitCursor)

        inDir = self.getInputFileName()
        outDir = self.getOutputFileName()

        extensions = Utils.getRasterExtensions()
        workDir = QDir(inDir)
        workDir.setFilter(QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot)
        workDir.setNameFilters(extensions)
        files = workDir.entryList()

        self.inFiles = []
        self.outFiles = []

        for f in files:
            self.inFiles.append(inDir + "/" + f)
            if outDir is not None:
                outFile = re.sub("\.[a-zA-Z0-9]{2,4}", outExt, f)
                self.outFiles.append(outDir + "/" + outFile)

        self.errors = []
        self.batchIndex = 0
        self.batchTotal = len(self.inFiles)
        self.setProgressRange(self.batchTotal)

        self.runItem(self.batchIndex, self.batchTotal)
예제 #11
0
    def getAllInstalled(self, testLoad=True):
        """ Build the localCache """
        self.localCache = {}

        # reversed list of the plugin paths: first system plugins -> then user plugins -> finally custom path(s)
        pluginPaths = list(plugin_paths)
        pluginPaths.reverse()

        for pluginsPath in pluginPaths:
            isTheSystemDir = (pluginPaths.index(pluginsPath) == 0)  # The curent dir is the system plugins dir
            if isTheSystemDir:
                # temporarily add the system path as the first element to force loading the readonly plugins, even if masked by user ones.
                sys.path = [pluginsPath] + sys.path
            try:
                pluginDir = QDir(pluginsPath)
                pluginDir.setFilter(QDir.AllDirs)
                for key in pluginDir.entryList():
                    if key not in [".", ".."]:
                        path = QDir.convertSeparators(pluginsPath + "/" + key)
                        # readOnly = not QFileInfo(pluginsPath).isWritable() # On windows testing the writable status isn't reliable.
                        readOnly = isTheSystemDir                            # Assume only the system plugins are not writable.
                        # only test those not yet loaded. Loaded plugins already proved they're o.k.
                        # failedToLoad = settings.value("/PythonPlugins/watchDog/" + key) is not None
                        testLoadThis = testLoad and key not in qgis.utils.plugins
                        plugin = self.getInstalledPlugin(key, path=path, readOnly=readOnly, testLoad=testLoadThis)
                        self.localCache[key] = plugin
                        if key in self.localCache.keys() and compareVersions(self.localCache[key]["version_installed"], plugin["version_installed"]) == 1:
                            # An obsolete plugin in the "user" location is masking a newer one in the "system" location!
                            self.obsoletePlugins += [key]
            except:
                # it's not necessary to stop if one of the dirs is inaccessible
                pass

            if isTheSystemDir:
                # remove the temporarily added path
                sys.path.remove(pluginsPath)