def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)

        arguments = []
        arguments.append(inLayer.source())

        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        arguments.append('-of')
        arguments.append(
            QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
        arguments.append('-o')
        arguments.append(out)

        arguments.append('-near')
        arguments.append(
            str(self.parameterAsInt(parameters, self.NEAR, context)))

        if self.parameterAsBool(parameters, self.WHITE, context):
            arguments.append('-white')

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
    def getConsoleCommands(self, parameters, context, feedback, executing=True):
        arguments = []

        arguments.append('-ps')
        arguments.append(str(self.parameterAsInt(parameters, self.TILE_SIZE_X, context)))
        arguments.append(str(self.parameterAsInt(parameters, self.TILE_SIZE_Y, context)))

        arguments.append('-overlap')
        arguments.append(str(self.parameterAsInt(parameters, self.OVERLAP, context)))

        arguments.append('-levels')
        arguments.append(str(self.parameterAsInt(parameters, self.LEVELS, context)))

        crs = self.parameterAsCrs(parameters, self.SOURCE_CRS, context)
        if crs.isValid():
            arguments.append('-s_srs')
            arguments.append(GdalUtils.gdal_crs_string(crs))

        arguments.append('-r')
        arguments.append(self.methods[self.parameterAsEnum(parameters, self.RESAMPLING, context)][1])

        arguments.append('-ot')
        arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        if self.parameterAsBool(parameters, self.DIR_FOR_ROW, context):
            arguments.append('-pyramidOnly')

        if self.parameterAsBool(parameters, self.ONLY_PYRAMIDS, context):
            arguments.append('-useDirForEachRow')

        csvFile = self.parameterAsFileOutput(parameters, self.OUTPUT_CSV, context)
        if csvFile:
            arguments.append('-csv')
            arguments.append(csvFile)
            delimiter = self.parameterAsString(parameters, self.DELIMITER, context)
            if delimiter:
                arguments.append('-csvDelim')
                arguments.append('"{}"'.format(delimiter))

        arguments.append('-targetDir')
        arguments.append(self.parameterAsString(parameters, self.OUTPUT, context))

        layers = [l.source() for l in self.parameterAsLayerList(parameters, self.INPUT, context)]
        arguments.extend(layers)

        commands = []
        if isWindows():
            commands = ['cmd.exe', '/C ', 'gdal_retile.bat',
                        GdalUtils.escapeAndJoin(arguments)]
        else:
            commands = ['gdal_retile.py',
                        GdalUtils.escapeAndJoin(arguments)]

        return commands
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        ogrLayer, layerName = self.getOgrCompatibleSource(
            self.INPUT, parameters, context, feedback, executing)

        arguments = ['-l']
        arguments.append(layerName)

        fieldName = self.parameterAsString(parameters, self.Z_FIELD, context)
        if fieldName:
            arguments.append('-zfield')
            arguments.append(fieldName)

        params = 'invdist'
        params += ':power={}'.format(
            self.parameterAsDouble(parameters, self.POWER, context))
        params += ':smothing={}'.format(
            self.parameterAsDouble(parameters, self.SMOOTHING, context))
        params += ':radius1={}'.format(
            self.parameterAsDouble(parameters, self.RADIUS_1, context))
        params += ':radius2={}'.format(
            self.parameterAsDouble(parameters, self.RADIUS_2, context))
        params += ':angle={}'.format(
            self.parameterAsDouble(parameters, self.ANGLE, context))
        params += ':max_points={}'.format(
            self.parameterAsInt(parameters, self.MAX_POINTS, context))
        params += ':min_points={}'.format(
            self.parameterAsInt(parameters, self.MIN_POINTS, context))
        params += ':nodata={}'.format(
            self.parameterAsDouble(parameters, self.NODATA, context))

        arguments.append('-a')
        arguments.append(params)
        arguments.append('-ot')
        arguments.append(self.TYPES[self.parameterAsEnum(
            parameters, self.DATA_TYPE, context)])

        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        arguments.append('-of')
        arguments.append(
            QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        arguments.append(ogrLayer)
        arguments.append(out)

        return ['gdal_grid', GdalUtils.escapeAndJoin(arguments)]
Exemplo n.º 4
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)

        maskLayer, maskLayerName = self.getOgrCompatibleSource(
            self.MASK, parameters, context, feedback, executing)

        if self.NODATA in parameters and parameters[self.NODATA] is not None:
            nodata = self.parameterAsDouble(parameters, self.NODATA, context)
        else:
            nodata = None
        options = self.parameterAsString(parameters, self.OPTIONS, context)
        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        arguments = []
        arguments.append('-ot')
        arguments.append(self.TYPES[self.parameterAsEnum(
            parameters, self.DATA_TYPE, context)])

        arguments.append('-of')
        arguments.append(
            QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

        if self.parameterAsBool(parameters, self.KEEP_RESOLUTION, context):
            arguments.append('-tr')
            arguments.append(str(inLayer.rasterUnitsPerPixelX()))
            arguments.append(str(-inLayer.rasterUnitsPerPixelY()))
            arguments.append('-tap')

        arguments.append('-cutline')
        arguments.append(maskLayer)

        if self.parameterAsBool(parameters, self.CROP_TO_CUTLINE, context):
            arguments.append('-crop_to_cutline')

        if self.parameterAsBool(parameters, self.ALPHA_BAND, context):
            arguments.append('-dstalpha')

        if nodata is not None:
            arguments.append('-dstnodata {}'.format(nodata))

        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        arguments.append(inLayer.source())
        arguments.append(out)

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
Exemplo n.º 5
0
    def getConsoleCommands(self, parameters, context, feedback, executing=True):
        arguments = ['TPI']
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        arguments.append(inLayer.source())
        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        arguments.append(out)

        arguments.append('-b')
        arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))

        if self.parameterAsBool(parameters, self.COMPUTE_EDGES, context):
            arguments.append('-compute_edges')

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
Exemplo n.º 6
0
    def getConsoleCommands(self, parameters, context, feedback, executing=True):
        arguments = ['hillshade']
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        arguments.append(inLayer.source())

        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        arguments.append(out)

        arguments.append('-of')
        arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

        arguments.append('-b')
        arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))
        arguments.append('-z')
        arguments.append(str(self.parameterAsDouble(parameters, self.Z_FACTOR, context)))
        arguments.append('-s')
        arguments.append(str(self.parameterAsDouble(parameters, self.SCALE, context)))
        arguments.append('-az')
        arguments.append(str(self.parameterAsDouble(parameters, self.AZIMUTH, context)))
        arguments.append('-alt')
        arguments.append(str(self.parameterAsDouble(parameters, self.ALTITUDE, context)))

        if self.parameterAsBool(parameters, self.COMPUTE_EDGES, context):
            arguments.append('-compute_edges')

        if self.parameterAsBool(parameters, self.ZEVENBERGEN, context):
            arguments.append('-alg')
            arguments.append('ZevenbergenThorne')

        if self.parameterAsBool(parameters, self.COMBINED, context):
            arguments.append('-combined')

        if self.parameterAsBool(parameters, self.MULTIDIRECTIONAL, context):
            arguments.append('-multidirectional')

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
Exemplo n.º 7
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        bbox = self.parameterAsExtent(parameters, self.EXTENT, context,
                                      inLayer.crs())
        if self.NODATA in parameters and parameters[self.NODATA] is not None:
            nodata = self.parameterAsDouble(parameters, self.NODATA, context)
        else:
            nodata = None
        options = self.parameterAsString(parameters, self.OPTIONS, context)
        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        arguments = []
        arguments.append('-projwin')
        arguments.append(str(bbox.xMinimum()))
        arguments.append(str(bbox.yMaximum()))
        arguments.append(str(bbox.xMaximum()))
        arguments.append(str(bbox.yMinimum()))

        if nodata is not None:
            arguments.append('-a_nodata {}'.format(nodata))

        arguments.append('-ot')
        arguments.append(self.TYPES[self.parameterAsEnum(
            parameters, self.DATA_TYPE, context)])

        arguments.append('-of')
        arguments.append(
            QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        arguments.append(inLayer.source())
        arguments.append(out)

        return ['gdal_translate', GdalUtils.escapeAndJoin(arguments)]
Exemplo n.º 8
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        arguments = ['slope']
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        arguments.append(inLayer.source())

        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        arguments.append(out)

        arguments.append('-of')
        arguments.append(
            QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

        arguments.append('-b')
        arguments.append(
            str(self.parameterAsInt(parameters, self.BAND, context)))

        arguments.append('-s')
        arguments.append(
            str(self.parameterAsDouble(parameters, self.SCALE, context)))

        if self.parameterAsBool(parameters, self.AS_PERCENT, context):
            arguments.append('-p')

        if self.parameterAsBool(parameters, self.COMPUTE_EDGES, context):
            arguments.append('-compute_edges')

        if self.parameterAsBool(parameters, self.ZEVENBERGEN, context):
            arguments.append('-alg')
            arguments.append('ZevenbergenThorne')

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
Exemplo n.º 9
0
    def getConsoleCommands(self, parameters, context, feedback, executing=True):
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        if self.NODATA in parameters and parameters[self.NODATA] is not None:
            nodata = self.parameterAsDouble(parameters, self.NODATA, context)
        else:
            nodata = None

        arguments = []

        crs = self.parameterAsCrs(parameters, self.TARGET_CRS, context)
        if crs.isValid():
            arguments.append('-a_srs')
            arguments.append(GdalUtils.gdal_crs_string(crs))

        if nodata is not None:
            arguments.append('-a_nodata')
            arguments.append(nodata)

        if self.parameterAsBool(parameters, self.COPY_SUBDATASETS, context):
            arguments.append('-sds')

        arguments.append('-ot')
        arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

        arguments.append('-of')
        arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        arguments.append(inLayer.source())
        arguments.append(out)

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        distance = self.parameterAsDouble(parameters, self.MAX_DISTANCE,
                                          context)
        replaceValue = self.parameterAsDouble(parameters, self.REPLACE,
                                              context)
        if self.NODATA in parameters and parameters[self.NODATA] is not None:
            nodata = self.parameterAsDouble(parameters, self.NODATA, context)
        else:
            nodata = None
        options = self.parameterAsString(parameters, self.OPTIONS, context)
        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        arguments = []
        arguments.append('-srcband')
        arguments.append(
            str(self.parameterAsInt(parameters, self.BAND, context)))

        arguments.append('-distunits')
        arguments.append(self.distanceUnits[self.parameterAsEnum(
            parameters, self.UNITS, context)][1])

        values = self.parameterAsString(parameters, self.VALUES, context)
        if values:
            arguments.append('-values')
            arguments.append(values)

        if distance:
            arguments.append('-maxdist')
            arguments.append(str(distance))

        if nodata is not None:
            arguments.append('-nodata')
            arguments.append(str(nodata))

        if replaceValue:
            arguments.append('-fixed-buf-val')
            arguments.append(str(replaceValue))

        arguments.append('-ot')
        arguments.append(self.TYPES[self.parameterAsEnum(
            parameters, self.DATA_TYPE, context)])

        arguments.append('-of')
        arguments.append(
            QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        arguments.append(inLayer.source())
        arguments.append(out)

        commands = []
        if isWindows():
            commands = [
                'cmd.exe', '/C ', 'gdal_proximity.bat',
                GdalUtils.escapeAndJoin(arguments)
            ]
        else:
            commands = [
                'gdal_proximity.py',
                GdalUtils.escapeAndJoin(arguments)
            ]

        return commands
Exemplo n.º 11
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        ogrLayer, layerName = self.getOgrCompatibleSource(
            self.INPUT, parameters, context, feedback, executing)

        arguments = ['-l']
        arguments.append(layerName)

        fieldName = self.parameterAsString(parameters, self.FIELD, context)
        if fieldName:
            arguments.append('-a')
            arguments.append(fieldName)
        else:
            arguments.append('-burn')
            arguments.append(
                self.parameterAsDouble(parameters, self.BURN, context))

        units = self.parameterAsEnum(parameters, self.UNITS, context)
        if units == 0:
            arguments.append('-ts')
        else:
            arguments.append('-tr')
        arguments.append(
            self.parameterAsDouble(parameters, self.WIDTH, context))
        arguments.append(
            self.parameterAsDouble(parameters, self.HEIGHT, context))

        initValue = self.parameterAsDouble(parameters, self.INIT, context)
        if initValue:
            arguments.append('-init')
            arguments.append(initValue)

        if self.parameterAsBool(parameters, self.INVERT, context):
            arguments.append('-i')

        if self.parameterAsBool(parameters, self.ALL_TOUCH, context):
            arguments.append('-at')

        if self.NODATA in parameters and parameters[self.NODATA] is not None:
            nodata = self.parameterAsDouble(parameters, self.NODATA, context)
            arguments.append('-a_nodata')
            arguments.append(nodata)

        extent = self.parameterAsExtent(parameters, self.EXTENT, context)
        if not extent.isNull():
            arguments.append('-te')
            arguments.append(extent.xMinimum())
            arguments.append(extent.yMinimum())
            arguments.append(extent.xMaximum())
            arguments.append(extent.yMaximum())

        arguments.append('-ot')
        arguments.append(self.TYPES[self.parameterAsEnum(
            parameters, self.DATA_TYPE, context)])

        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        arguments.append('-of')
        arguments.append(
            QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
        options = self.parameterAsString(parameters, self.OPTIONS, context)

        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        arguments.append(ogrLayer)
        arguments.append(out)

        return ['gdal_rasterize', GdalUtils.escapeAndJoin(arguments)]
Exemplo n.º 12
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        arguments = []
        if self.parameterAsBool(parameters, self.PCT, context):
            arguments.append('-pct')

        if self.parameterAsBool(parameters, self.SEPARATE, context):
            arguments.append('-separate')

        if self.NODATA_INPUT in parameters and parameters[
                self.NODATA_INPUT] is not None:
            nodata_input = self.parameterAsInt(parameters, self.NODATA_INPUT,
                                               context)
            arguments.append('-n')
            arguments.append(str(nodata_input))

        if self.NODATA_OUTPUT in parameters and parameters[
                self.NODATA_OUTPUT] is not None:
            nodata_output = self.parameterAsInt(parameters, self.NODATA_OUTPUT,
                                                context)
            arguments.append('-a_nodata')
            arguments.append(str(nodata_output))

        arguments.append('-ot')
        arguments.append(self.TYPES[self.parameterAsEnum(
            parameters, self.DATA_TYPE, context)])

        arguments.append('-of')
        arguments.append(
            QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        arguments.append('-o')
        arguments.append(out)

        # Always write input files to a text file in case there are many of them and the
        # length of the command will be longer then allowed in command prompt
        list_file = GdalUtils.writeLayerParameterToTextFile(
            filename='mergeInputFiles.txt',
            alg=self,
            parameters=parameters,
            parameter_name=self.INPUT,
            context=context,
            quote=True,
            executing=executing)
        arguments.append('--optfile')
        arguments.append(list_file)

        commands = []
        if isWindows():
            commands = [
                'cmd.exe', '/C ', 'gdal_merge.bat',
                GdalUtils.escapeAndJoin(arguments)
            ]
        else:
            commands = ['gdal_merge.py', GdalUtils.escapeAndJoin(arguments)]

        return commands
Exemplo n.º 13
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        sourceCrs = self.parameterAsCrs(parameters, self.SOURCE_CRS, context)
        targetCrs = self.parameterAsCrs(parameters, self.TARGET_CRS, context)
        if self.NODATA in parameters and parameters[self.NODATA] is not None:
            nodata = self.parameterAsDouble(parameters, self.NODATA, context)
        else:
            nodata = None
        resolution = self.parameterAsDouble(parameters, self.TARGET_RESOLUTION,
                                            context)

        arguments = []
        if sourceCrs.isValid():
            arguments.append('-s_srs')
            arguments.append(GdalUtils.gdal_crs_string(sourceCrs))

        if targetCrs.isValid():
            arguments.append('-t_srs')
            arguments.append(GdalUtils.gdal_crs_string(targetCrs))

        if nodata is not None:
            arguments.append('-dstnodata')
            arguments.append(str(nodata))

        if resolution:
            arguments.append('-tr')
            arguments.append(str(resolution))
            arguments.append(str(resolution))

        arguments.append('-r')
        arguments.append(self.methods[self.parameterAsEnum(
            parameters, self.RESAMPLING, context)][1])

        extent = self.parameterAsExtent(parameters, self.TARGET_EXTENT,
                                        context)
        if not extent.isNull():
            arguments.append('-te')
            arguments.append(extent.xMinimum())
            arguments.append(extent.yMinimum())
            arguments.append(extent.xMaximum())
            arguments.append(extent.yMaximum())

            extentCrs = self.parameterAsCrs(parameters, self.TARGET_EXTENT_CRS,
                                            context)
            if extentCrs:
                arguments.append('-te_srs')
                arguments.append(extentCrs.authid())

        if self.parameterAsBool(parameters, self.MULTITHREADING, context):
            arguments.append('-multi')

        arguments.append('-ot')
        arguments.append(self.TYPES[self.parameterAsEnum(
            parameters, self.DATA_TYPE, context)])

        out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        arguments.append('-of')
        arguments.append(
            QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.extend(GdalUtils.parseCreationOptions(options))

        arguments.append(inLayer.source())
        arguments.append(out)

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]