コード例 #1
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        fileName = inLayer.source()

        crs = self.parameterAsCrs(parameters, self.CRS, context)

        arguments = []
        arguments.append('-a_srs')
        arguments.append(GdalUtils.gdal_crs_string(crs))

        arguments.append(fileName)

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

        self.setOutputValue(self.OUTPUT, fileName)
        return commands
コード例 #2
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        arguments = []
        arguments.append('-band')
        arguments.append(
            str(self.parameterAsInt(parameters, self.BAND, context)))

        if self.parameterAsBool(parameters, self.CSV, context):
            arguments.append('-csv')

        arguments.append(
            self.parameterAsRasterLayer(parameters, self.INPUT,
                                        context).source())
        arguments.append(
            self.parameterAsFileOutput(parameters, self.OUTPUT, context))

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

        return commands
コード例 #3
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        arguments = []
        arguments.append('-n')
        arguments.append(
            str(self.parameterAsInt(parameters, self.NCOLORS, context)))

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

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

        return commands
コード例 #4
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        arguments = []
        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)))

        if self.parameterAsBool(parameters, self.RGBA, context):
            arguments.append('-rgba')

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

        return commands
コード例 #5
0
    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
コード例 #6
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        arguments = []
        arguments.append('-md')
        arguments.append(
            str(self.parameterAsInt(parameters, self.DISTANCE, context)))

        nIterations = self.parameterAsInt(parameters, self.ITERATIONS, context)
        if nIterations:
            arguments.append('-si')
            arguments.append(str(nIterations))

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

        if self.parameterAsBool(parameters, self.NO_MASK, context):
            arguments.append('-nomask')

        mask = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        if mask:
            arguments.append('-mask {}'.format(mask.source()))

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

        arguments.append(
            self.parameterAsRasterLayer(parameters, self.INPUT,
                                        context).source())
        arguments.append(out)

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

        return commands
コード例 #7
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        arguments = ['roughness']
        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)))

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

        options = self.parameterAsString(parameters, self.OPTIONS, context)
        if options:
            arguments.append('-co')
            arguments.append(options)

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
コード例 #8
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        arguments = []
        arguments.append('-resolution')
        arguments.append(self.RESOLUTION_OPTIONS[self.parameterAsEnum(
            parameters, self.RESOLUTION, context)])
        if self.parameterAsBool(parameters, buildvrt.SEPARATE, context):
            arguments.append('-separate')
        if self.parameterAsBool(parameters, buildvrt.PROJ_DIFFERENCE, context):
            arguments.append('-allow_projection_difference')
        # 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='buildvrtInputFiles.txt',
            alg=self,
            parameters=parameters,
            parameter_name=self.INPUT,
            context=context,
            executing=executing,
            quote=False)
        arguments.append('-input_file_list')
        arguments.append(list_file)

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

        return ['gdalbuildvrt', GdalUtils.escapeAndJoin(arguments)]
コード例 #9
0
    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)]
コード例 #10
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        fields = self.parameterAsSource(parameters, self.INPUT,
                                        context).fields()
        ogrLayer, layerName = self.getOgrCompatibleSource(
            self.INPUT, parameters, context, feedback, executing)
        geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
        distance = self.parameterAsDouble(parameters, self.DISTANCE, context)
        side = self.parameterAsEnum(parameters, self.BUFFER_SIDE, context)
        fieldName = self.parameterAsString(parameters, self.FIELD, context)
        dissolve = self.parameterAsBool(parameters, self.DISSOLVE, context)
        options = self.parameterAsString(parameters, self.OPTIONS, context)
        outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(
            outFile, context)

        other_fields = []
        for f in fields:
            if f.name() == geometry:
                continue
            other_fields.append(f.name())

        if other_fields:
            other_fields = ', {}'.format(','.join(other_fields))
        else:
            other_fields = ''

        arguments = []
        arguments.append(output)
        arguments.append(ogrLayer)
        arguments.append('-dialect')
        arguments.append('sqlite')
        arguments.append('-sql')

        if dissolve or fieldName:
            sql = "SELECT ST_Union(ST_SingleSidedBuffer({}, {}, {})) AS {}{} FROM '{}'".format(
                geometry, distance, side, geometry, other_fields, layerName)
        else:
            sql = "SELECT ST_SingleSidedBuffer({}, {}, {}) AS {}{} FROM '{}'".format(
                geometry, distance, side, geometry, other_fields, layerName)

        if fieldName:
            sql = '"{} GROUP BY {}"'.format(sql, fieldName)

        arguments.append(sql)

        if self.parameterAsBool(parameters, self.EXPLODE_COLLECTIONS, context):
            arguments.append('-explodecollections')

        if options:
            arguments.append(options)

        if outputFormat:
            arguments.append('-f {}'.format(outputFormat))

        return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
コード例 #11
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        ogrLayer, layerName = self.getOgrCompatibleSource(
            self.INPUT, parameters, context, feedback, executing)
        source = self.parameterAsSource(parameters, self.INPUT, context)
        extent = self.parameterAsExtent(parameters, self.EXTENT, context,
                                        source.sourceCrs())
        options = self.parameterAsString(parameters, self.OPTIONS, context)
        outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(
            outFile, context)

        arguments = []
        arguments.append('-spat')
        arguments.append(str(extent.xMinimum()))
        arguments.append(str(extent.yMaximum()))
        arguments.append(str(extent.xMaximum()))
        arguments.append(str(extent.yMinimum()))
        arguments.append('-clipsrc spat_extent')

        arguments.append(output)
        arguments.append(ogrLayer)
        arguments.append(layerName)

        if options:
            arguments.append(options)

        if outputFormat:
            arguments.append('-f {}'.format(outputFormat))

        return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
コード例 #12
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        inLayer, inLayerName = self.getOgrCompatibleSource(
            self.INPUT, parameters, context, feedback, executing)
        maskLayer, maskLayerName = self.getOgrCompatibleSource(
            self.MASK, parameters, context, feedback, executing)
        options = self.parameterAsString(parameters, self.OPTIONS, context)
        outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(
            outFile, context)

        arguments = []
        arguments.append('-clipsrc')
        arguments.append(maskLayer)
        arguments.append('-clipsrclayer')
        arguments.append(maskLayerName)

        arguments.append(output)
        arguments.append(inLayer)
        arguments.append(inLayerName)

        if options:
            arguments.append(options)

        if outputFormat:
            arguments.append('-f {}'.format(outputFormat))

        return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
コード例 #13
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        ogrLayer, layerName = self.getOgrCompatibleSource(
            self.INPUT, parameters, context, feedback, executing)
        options = self.parameterAsString(parameters, self.OPTIONS, context)
        outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(
            outFile, context)

        if outputFormat == 'SQLite' and os.path.isfile(output):
            raise QgsProcessinException(
                self.tr('Output file "{}" already exists.'.format(output)))

        arguments = []
        if outputFormat:
            arguments.append('-f {}'.format(outputFormat))

        if options:
            arguments.append(options)

        arguments.append(output)
        arguments.append(ogrLayer)
        arguments.append(layerName)

        return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
コード例 #14
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        arguments = ['color-relief']
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        arguments.append(inLayer.source())
        arguments.append(
            self.parameterAsFile(parameters, self.COLOR_TABLE, context))

        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)))

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

        arguments.append(self.modes[self.parameterAsEnum(
            parameters, self.MATCH_MODE, context)][1])

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
コード例 #15
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        fileName = inLayer.source()

        arguments = []
        arguments.append(fileName)

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

        ovrFormat = self.parameterAsEnum(parameters, self.FORMAT, context)
        if ovrFormat == 1:
            arguments.append('-ro')
        elif ovrFormat == 2:
            arguments.extend('--config USE_RRD YES'.split(' '))

        if self.parameterAsBool(parameters, self.CLEAN, context):
            arguments.append('-clean')

        arguments.extend(
            self.parameterAsString(parameters, self.LEVELS,
                                   context).split(' '))

        self.setOutputValue(self.OUTPUT, fileName)

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
コード例 #16
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        context = dataobjects.createContext()
        inLayer = QgsProcessingUtils.mapLayerFromString(
            self.getParameterValue(self.INPUT), context)
        inRasterLayer = QgsProcessingUtils.mapLayerFromString(
            self.getParameterValue(self.INPUT_RASTER), context)

        ogrLayer = GdalUtils.ogrConnectionString(inLayer, context)[1:-1]
        ogrRasterLayer = GdalUtils.ogrConnectionString(inRasterLayer,
                                                       context)[1:-1]

        arguments = []
        arguments.append('-a')
        arguments.append(str(self.getParameterValue(self.FIELD)))

        arguments.append('-l')
        arguments.append(GdalUtils.ogrLayerName(inLayer))
        arguments.append(ogrLayer)
        arguments.append(ogrRasterLayer)

        return ['gdal_rasterize', GdalUtils.escapeAndJoin(arguments)]
コード例 #17
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        arguments = []
        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        arguments.append(inLayer.source())

        outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        output, outFormat = GdalUtils.ogrConnectionStringAndFormat(
            outFile, context)
        arguments.append(output)

        if self.parameterAsBool(parameters, self.EIGHT_CONNECTEDNESS, context):
            arguments.append('-8')

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

        if outFormat:
            arguments.append('-f {}'.format(outFormat))

        arguments.append(GdalUtils.ogrLayerName(output))
        arguments.append(
            self.parameterAsString(parameters, self.FIELD, context))

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

        return commands
コード例 #18
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.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)]
コード例 #19
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        input_layers = self.parameterAsLayerList(parameters, self.LAYERS,
                                                 context)
        crs_field = self.parameterAsString(parameters, self.CRS_FIELD_NAME,
                                           context)
        crs_format = self.parameterAsEnum(parameters, self.CRS_FORMAT, context)
        target_crs = self.parameterAsCrs(parameters, self.TARGET_CRS, context)

        outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
        output, outFormat = GdalUtils.ogrConnectionStringAndFormat(
            outFile, context)

        layers = []
        for layer in input_layers:
            if layer.type() != QgsMapLayer.RasterLayer:
                raise QgsProcessingException(
                    self.tr('All layers must be raster layers!'))
            layers.append(layer.source())

        arguments = []
        arguments.append('-tileindex')
        arguments.append(
            self.parameterAsString(parameters, self.PATH_FIELD_NAME, context))

        if self.parameterAsBool(parameters, self.ABSOLUTE_PATH, context):
            arguments.append('-write_absolute_path')

        if self.parameterAsBool(parameters, self.PROJ_DIFFERENCE, context):
            arguments.append('-skip_different_projection')

        if crs_field:
            arguments.append('-src_srs_name {}'.format(crs_field))

        if crs_format:
            arguments.append('-src_srs_format {}'.format(
                self.modes[crs_format][1]))

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

        if outFormat:
            arguments.append('-f {}'.format(outFormat))

        arguments.append(output)
        arguments.append(' '.join(layers))

        return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
コード例 #20
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)]
コード例 #21
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        fields = self.parameterAsSource(parameters, self.INPUT,
                                        context).fields()
        ogrLayer, layerName = self.getOgrCompatibleSource(
            self.INPUT, parameters, context, feedback, executing)
        geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
        distance = self.parameterAsDouble(parameters, self.DISTANCE, context)
        options = self.parameterAsString(parameters, self.OPTIONS, context)
        outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(
            outFile, context)

        other_fields = []
        for f in fields:
            if f.name() == geometry:
                continue
            other_fields.append(f.name())

        if other_fields:
            other_fields = ', {}'.format(','.join(other_fields))
        else:
            other_fields = ''

        arguments = []
        arguments.append(output)
        arguments.append(ogrLayer)
        arguments.append('-dialect')
        arguments.append('sqlite')
        arguments.append('-sql')

        sql = "SELECT ST_OffsetCurve({}, {}) AS {}{} FROM '{}'".format(
            geometry, distance, geometry, other_fields, layerName)
        arguments.append(sql)

        if options:
            arguments.append(options)

        if outputFormat:
            arguments.append('-f {}'.format(outputFormat))

        return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
コード例 #22
0
 def getConsoleCommands(self,
                        parameters,
                        context,
                        feedback,
                        executing=True):
     arguments = []
     if self.parameterAsBool(parameters, self.MIN_MAX, context):
         arguments.append('-mm')
     if self.parameterAsBool(parameters, self.STATS, context):
         arguments.append('-stats')
     if self.parameterAsBool(parameters, self.NO_GCP, context):
         arguments.append('-nogcp')
     if self.parameterAsBool(parameters, self.NO_METADATA, context):
         arguments.append('-nomd')
     arguments.append(
         self.parameterAsRasterLayer(parameters, self.INPUT,
                                     context).source())
     return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]
コード例 #23
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)]
コード例 #24
0
 def getConnectionString(self, parameters, context):
     host = self.parameterAsString(parameters, self.HOST, context)
     port = self.parameterAsString(parameters, self.PORT, context)
     user = self.parameterAsString(parameters, self.USER, context)
     dbname = self.parameterAsString(parameters, self.DBNAME, context)
     password = self.parameterAsString(parameters, self.PASSWORD, context)
     schema = self.parameterAsString(parameters, self.SCHEMA, context)
     arguments = []
     if host:
         arguments.append('host=' + host)
     if port:
         arguments.append('port=' + str(port))
     if dbname:
         arguments.append('dbname=' + dbname)
     if password:
         arguments.append('password='******'active_schema=' + schema)
     if user:
         arguments.append('user=' + user)
     return GdalUtils.escapeAndJoin(arguments)
コード例 #25
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)]
コード例 #26
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)]
コード例 #27
0
    def getConsoleCommands(self,
                           parameters,
                           context,
                           feedback,
                           executing=True):
        ogrLayer, layerName = self.getOgrCompatibleSource(
            self.INPUT, parameters, context, feedback, executing)
        sql = self.parameterAsString(parameters, self.SQL, context)
        options = self.parameterAsString(parameters, self.OPTIONS, context)
        outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

        output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(
            outFile, context)

        if not sql:
            raise QgsProcessingException(
                self.
                tr('Empty SQL. Please enter valid SQL expression and try again.'
                   ))

        arguments = []
        arguments.append(output)
        arguments.append(ogrLayer)
        arguments.append('-sql')
        arguments.append(sql)

        dialect = self.dialects[self.parameterAsEnum(parameters, self.DIALECT,
                                                     context)][1]
        if dialect:
            arguments.append('-dialect')
            arguments.append(dialect)

        if options:
            arguments.append(options)

        if outputFormat:
            arguments.append('-f {}'.format(outputFormat))

        return ['ogr2ogr', GdalUtils.escapeAndJoin(arguments)]
コード例 #28
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)]
コード例 #29
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)]
コード例 #30
0
    def getConsoleCommands(self, parameters, context, feedback, executing=True):
        arguments = []

        arguments.append('-p')
        arguments.append(self.profiles[self.parameterAsEnum(parameters, self.PROFILE, context)][1])

        zoom = self.parameterAsString(parameters, self.ZOOM, context)
        if zoom:
            arguments.append('-z')
            arguments.append(str(zoom))

        arguments.append('-w')
        arguments.append(self.viewers[self.parameterAsEnum(parameters, self.VIEWER, context)][1])

        title = self.parameterAsString(parameters, self.TITLE, context)
        if title:
            arguments.append('-t')
            arguments.append(title)

        copying = self.parameterAsString(parameters, self.COPYRIGHT, context)
        if copying:
            arguments.append('-c')
            arguments.append(copying)

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

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

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

        url = self.parameterAsString(parameters, self.URL, context)
        if url:
            arguments.append('-u')
            arguments.append(url)

        key = self.parameterAsString(parameters, self.GOOGLE_KEY, context)
        if key:
            arguments.append('-g')
            arguments.append(key)

        key = self.parameterAsString(parameters, self.BING_KEY, context)
        if key:
            arguments.append('-b')
            arguments.append(key)

        if self.parameterAsBool(parameters, self.RESUME, context):
            arguments.append('-e')

        if self.parameterAsBool(parameters, self.KML, context):
            arguments.append('-k')

        if self.parameterAsBool(parameters, self.NO_KML, context):
            arguments.append('-n')

        inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        arguments.append(inLayer.source())
        arguments.append(self.parameterAsString(parameters, self.OUTPUT, context))

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

        return commands