Beispiel #1
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterBand(self.BANDS,
                                                     self.tr('Selected band(s)'),
                                                     None,
                                                     self.INPUT,
                                                     allowMultiple=True))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Converted')))
Beispiel #2
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterCrs(self.TARGET_CRS,
                                                    self.tr('Override the projection for the output file'),
                                                    defaultValue=None,
                                                    optional=True))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Assign a specified nodata value to output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=None,
                                                       optional=True))
        self.addParameter(QgsProcessingParameterBoolean(self.COPY_SUBDATASETS,
                                                        self.tr('Copy all subdatasets of this file to individual output files'),
                                                        defaultValue=False))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Converted')))
Beispiel #3
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Point layer'),
                                                              [QgsProcessing.TypeVectorPoint]))

        z_field_param = QgsProcessingParameterField(self.Z_FIELD,
                                                    self.tr('Z value from field'),
                                                    None,
                                                    self.INPUT,
                                                    QgsProcessingParameterField.Numeric,
                                                    optional=True)
        z_field_param.setFlags(z_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(z_field_param)

        self.addParameter(QgsProcessingParameterNumber(self.RADIUS_1,
                                                       self.tr('The first radius of search ellipse'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.RADIUS_2,
                                                       self.tr('The second radius of search ellipse'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.ANGLE,
                                                       self.tr('Angle of search ellipse rotation in degrees (counter clockwise)'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       maxValue=360.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.MIN_POINTS,
                                                       self.tr('Minimum number of data points to use'),
                                                       type=QgsProcessingParameterNumber.Integer,
                                                       minValue=0,
                                                       defaultValue=0))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('NODATA marker to fill empty points'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation parameters'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Interpolated (moving average)')))
Beispiel #4
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
                                                            self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
                                                       self.tr('Clipping extent')))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Assign a specified nodata value to output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=None,
                                                       optional=True))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Clipped (extent)')))
Beispiel #5
0
    def initAlgorithm(self, config=None):
        self.methods = ((self.tr('Nearest Neighbour'), 'nearest'),
                        (self.tr('Bilinear'), 'bilinear'),
                        (self.tr('Cubic'), 'cubic'),
                        (self.tr('Cubic Spline'), 'cubicspline'),
                        (self.tr('Lanczos Windowed Sinc'), 'lanczos'),
                        (self.tr('Average'), 'average'))

        self.addParameter(QgsProcessingParameterRasterLayer(self.SPECTRAL,
                                                            self.tr('Spectral dataset')))
        self.addParameter(QgsProcessingParameterRasterLayer(self.PANCHROMATIC,
                                                            self.tr('Panchromatic dataset')))

        resampling_param = QgsProcessingParameterEnum(self.RESAMPLING,
                                                      self.tr('Resampling algorithm'),
                                                      options=[i[0] for i in self.methods],
                                                      defaultValue=2)
        resampling_param.setFlags(resampling_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(resampling_param)

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Output')))
Beispiel #6
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
                                                            self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterFeatureSource(self.MASK,
                                                              self.tr('Mask layer'),
                                                              [QgsProcessing.TypeVectorPolygon]))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Assign a specified nodata value to output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=None,
                                                       optional=True))
        self.addParameter(QgsProcessingParameterBoolean(self.ALPHA_BAND,
                                                        self.tr('Create an output alpha band'),
                                                        defaultValue=False))
        self.addParameter(QgsProcessingParameterBoolean(self.CROP_TO_CUTLINE,
                                                        self.tr('Match the extent of the clipped raster to the extent of the mask layer'),
                                                        defaultValue=True))
        self.addParameter(QgsProcessingParameterBoolean(self.KEEP_RESOLUTION,
                                                        self.tr('Keep resolution of output raster'),
                                                        defaultValue=False))

        target_extent_param = QgsProcessingParameterExtent(self.TARGET_EXTENT,
                                                           self.tr('Georeferenced extents of output file to be created'),
                                                           optional=True)
        target_extent_param.setFlags(target_extent_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(target_extent_param)

        target_extent_crs_param = QgsProcessingParameterCrs(self.TARGET_EXTENT_CRS,
                                                            self.tr('CRS of the target raster extent'),
                                                            optional=True)
        target_extent_crs_param.setFlags(target_extent_crs_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(target_extent_crs_param)

        multithreading_param = QgsProcessingParameterBoolean(self.MULTITHREADING,
                                                             self.tr('Use multithreaded warping implementation'),
                                                             defaultValue=False)
        multithreading_param.setFlags(multithreading_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(multithreading_param)

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Clipped (mask)')))
Beispiel #7
0
    def initAlgorithm(self, config=None):

        class ParameterVrtDestination(QgsProcessingParameterRasterDestination):

            def __init__(self, name, description):
                super().__init__(name, description)

            def clone(self):
                copy = ParameterVrtDestination(self.name(), self.description())
                return copy

            def type(self):
                return 'vrt_destination'

            def defaultFileExtension(self):
                return 'vrt'

        self.addParameter(QgsProcessingParameterMultipleLayers(self.INPUT,
                                                               self.tr('Input layers'),
                                                               QgsProcessing.TypeRaster))
        self.addParameter(QgsProcessingParameterEnum(self.RESOLUTION,
                                                     self.tr('Resolution'),
                                                     options=self.RESOLUTION_OPTIONS,
                                                     defaultValue=0))
        self.addParameter(QgsProcessingParameterBoolean(self.SEPARATE,
                                                        self.tr('Place each input file into a separate band'),
                                                        defaultValue=True))
        self.addParameter(QgsProcessingParameterBoolean(self.PROJ_DIFFERENCE,
                                                        self.tr('Allow projection difference'),
                                                        defaultValue=False))

        add_alpha_param = QgsProcessingParameterBoolean(self.ADD_ALPHA,
                                                        self.tr('Add alpha mask band to VRT when source raster has none'),
                                                        defaultValue=False)
        add_alpha_param.setFlags(add_alpha_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(add_alpha_param)

        assign_crs = QgsProcessingParameterCrs(self.ASSIGN_CRS,
                                               self.tr('Override projection for the output file'),
                                               defaultValue=None, optional=True)
        assign_crs.setFlags(assign_crs.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(assign_crs)

        resampling = QgsProcessingParameterEnum(self.RESAMPLING,
                                                self.tr('Resampling algorithm'),
                                                options=self.RESAMPLING_OPTIONS,
                                                defaultValue=0)
        resampling.setFlags(resampling.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(resampling)

        src_nodata_param = QgsProcessingParameterString(self.SRC_NODATA,
                                                        self.tr('Nodata value(s) for input bands (space separated)'),
                                                        defaultValue=None,
                                                        optional=True)
        src_nodata_param.setFlags(src_nodata_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(src_nodata_param)

        self.addParameter(ParameterVrtDestination(self.OUTPUT, QCoreApplication.translate("ParameterVrtDestination", 'Virtual')))
Beispiel #8
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Point layer'),
                                                              [QgsProcessing.TypeVectorPoint]))

        z_field_param = QgsProcessingParameterField(self.Z_FIELD,
                                                    self.tr('Z value from field'),
                                                    None,
                                                    self.INPUT,
                                                    QgsProcessingParameterField.Numeric,
                                                    optional=True)
        z_field_param.setFlags(z_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(z_field_param)

        self.addParameter(QgsProcessingParameterNumber(self.RADIUS,
                                                       self.tr('Search distance '),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=-1.0,
                                                       defaultValue=-1.0))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('NODATA marker to fill empty points'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Interpolated (Linear)')))
Beispiel #9
0
    def initAlgorithm(self, config=None):
        self.formats = ((self.tr('Auto'), 'AUTO'),
                        (self.tr('Well-known text (WKT)'), 'WKT'),
                        (self.tr('EPSG'), 'EPSG'),
                        (self.tr('Proj.4'), 'PROJ'))

        self.addParameter(QgsProcessingParameterMultipleLayers(self.LAYERS,
                                                               self.tr('Input files'),
                                                               QgsProcessing.TypeRaster))
        self.addParameter(QgsProcessingParameterString(self.PATH_FIELD_NAME,
                                                       self.tr('Field name to hold the file path to the indexed rasters'),
                                                       defaultValue='location'))
        self.addParameter(QgsProcessingParameterBoolean(self.ABSOLUTE_PATH,
                                                        self.tr('Store absolute path to the indexed rasters'),
                                                        defaultValue=False))
        self.addParameter(QgsProcessingParameterBoolean(self.PROJ_DIFFERENCE,
                                                        self.tr('Skip files with different projection reference'),
                                                        defaultValue=False))

        target_crs_param = QgsProcessingParameterCrs(self.TARGET_CRS,
                                                     self.tr('Transform geometries to the given CRS'),
                                                     optional=True)
        target_crs_param.setFlags(target_crs_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(target_crs_param)

        crs_field_param = QgsProcessingParameterString(self.CRS_FIELD_NAME,
                                                       self.tr('The name of the field to store the SRS of each tile'),
                                                       optional=True)
        crs_field_param.setFlags(crs_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(crs_field_param)

        crs_format_param = QgsProcessingParameterEnum(self.CRS_FORMAT,
                                                      self.tr('The format in which the CRS of each tile must be written'),
                                                      options=[i[0] for i in self.formats],
                                                      allowMultiple=False,
                                                      defaultValue=0)
        crs_format_param.setFlags(crs_format_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(crs_format_param)

        self.addParameter(QgsProcessingParameterVectorDestination(self.OUTPUT,
                                                                  self.tr('Tile index'),
                                                                  QgsProcessing.TypeVectorPolygon))
Beispiel #10
0
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
                                                            self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterFeatureSource(self.MASK,
                                                              self.tr('Mask layer'),
                                                              [QgsProcessing.TypeVectorPolygon]))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Assign a specified nodata value to output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0,
                                                       optional=True))
        self.addParameter(QgsProcessingParameterBoolean(self.ALPHA_BAND,
                                                        self.tr('Create an output alpha band'),
                                                        defaultValue=False))
        self.addParameter(QgsProcessingParameterBoolean(self.CROP_TO_CUTLINE,
                                                        self.tr('Crop the extent of the target dataset to the extent of the cutline'),
                                                        defaultValue=True))
        self.addParameter(QgsProcessingParameterBoolean(self.KEEP_RESOLUTION,
                                                        self.tr('Keep resolution of output raster'),
                                                        defaultValue=False))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation parameters'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Clipped (mask)')))
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Point layer'),
                                                              [QgsProcessing.TypeVectorPoint]))

        z_field_param = QgsProcessingParameterField(self.Z_FIELD,
                                                    self.tr('Z value from field'),
                                                    None,
                                                    self.INPUT,
                                                    QgsProcessingParameterField.Numeric,
                                                    optional=True)
        z_field_param.setFlags(z_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(z_field_param)

        self.addParameter(QgsProcessingParameterNumber(self.POWER,
                                                       self.tr('Weighting power'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       maxValue=100.0,
                                                       defaultValue=2.0))
        self.addParameter(QgsProcessingParameterNumber(self.SMOOTHING,
                                                       self.tr('Smoothing'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.RADIUS,
                                                       self.tr('The radius of the search circle'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=1.0))
        self.addParameter(QgsProcessingParameterNumber(self.MAX_POINTS,
                                                       self.tr('Maximum number of data points to use'),
                                                       type=QgsProcessingParameterNumber.Integer,
                                                       minValue=0,
                                                       defaultValue=12))
        self.addParameter(QgsProcessingParameterNumber(self.MIN_POINTS,
                                                       self.tr('Minimum number of data points to use'),
                                                       type=QgsProcessingParameterNumber.Integer,
                                                       minValue=0,
                                                       defaultValue=0))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('NODATA marker to fill empty points'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Interpolated (IDW with NN search)')))
Beispiel #12
0
    def initAlgorithm(self, config=None):
        self.methods = ((self.tr('Nearest neighbour'), 'near'),
                        (self.tr('Bilinear'), 'bilinear'),
                        (self.tr('Cubic'), 'cubic'),
                        (self.tr('Cubic spline'), 'cubicspline'),
                        (self.tr('Lanczos windowed sinc'), 'lanczos'),
                        (self.tr('Average'), 'average'),
                        (self.tr('Mode'), 'mode'),
                        (self.tr('Maximum'), 'max'),
                        (self.tr('Minimum'), 'min'),
                        (self.tr('Median'), 'med'),
                        (self.tr('First quartile'), 'q1'),
                        (self.tr('Third quartile'), 'q3'))

        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterCrs(self.SOURCE_CRS,
                                                    self.tr('Source CRS'),
                                                    optional=True))
        self.addParameter(QgsProcessingParameterCrs(self.TARGET_CRS,
                                                    self.tr('Target CRS'),
                                                    'EPSG:4326'))
        self.addParameter(QgsProcessingParameterEnum(self.RESAMPLING,
                                                     self.tr('Resampling method to use'),
                                                     options=[i[0] for i in self.methods],
                                                     defaultValue=0))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Nodata value for output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=None,
                                                       optional=True))
        self.addParameter(QgsProcessingParameterNumber(self.TARGET_RESOLUTION,
                                                       self.tr('Output file resolution in target georeferenced units'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=None,
                                                       optional=True))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation options'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        target_extent_param = QgsProcessingParameterExtent(self.TARGET_EXTENT,
                                                           self.tr('Georeferenced extents of output file to be created'),
                                                           optional=True)
        target_extent_param.setFlags(target_extent_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(target_extent_param)

        target_extent_crs_param = QgsProcessingParameterCrs(self.TARGET_EXTENT_CRS,
                                                            self.tr('CRS of the target raster extent'),
                                                            optional=True)
        target_extent_crs_param.setFlags(target_extent_crs_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(target_extent_crs_param)

        multithreading_param = QgsProcessingParameterBoolean(self.MULTITHREADING,
                                                             self.tr('Use multithreaded warping implementation'),
                                                             defaultValue=False)
        multithreading_param.setFlags(multithreading_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(multithreading_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Reprojected')))
    def initAlgorithm(self, config=None):

        self.TYPES = [
            self.tr('Use Input Layer Data Type'), 'Byte', 'Int16', 'UInt16',
            'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32',
            'CFloat32', 'CFloat64'
        ]

        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterCrs(
                self.TARGET_CRS,
                self.tr('Override the projection for the output file'),
                defaultValue=None,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('Assign a specified nodata value to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.COPY_SUBDATASETS,
                self.
                tr('Copy all subdatasets of this file to individual output files'
                   ),
                defaultValue=False))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        extra_param = QgsProcessingParameterString(
            self.EXTRA,
            self.tr('Additional command-line parameters'),
            defaultValue=None,
            optional=True)
        extra_param.setFlags(extra_param.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(extra_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=0)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Converted')))
Beispiel #14
0
    def initAlgorithm(self, config=None):
        self.KERNELS = OrderedDict([
            (self.tr('Quartic'), QgsKernelDensityEstimation.KernelQuartic),
            (self.tr('Triangular'),
             QgsKernelDensityEstimation.KernelTriangular),
            (self.tr('Uniform'), QgsKernelDensityEstimation.KernelUniform),
            (self.tr('Triweight'), QgsKernelDensityEstimation.KernelTriweight),
            (self.tr('Epanechnikov'),
             QgsKernelDensityEstimation.KernelEpanechnikov)
        ])

        self.OUTPUT_VALUES = OrderedDict([
            (self.tr('Raw'), QgsKernelDensityEstimation.OutputRaw),
            (self.tr('Scaled'), QgsKernelDensityEstimation.OutputScaled)
        ])

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Point layer'),
                [QgsProcessing.TypeVectorPoint]))

        self.addParameter(
            QgsProcessingParameterNumber(self.RADIUS,
                                         self.tr('Radius (layer units)'),
                                         QgsProcessingParameterNumber.Double,
                                         100.0, False, 0.0, 9999999999.99))

        radius_field_param = QgsProcessingParameterField(
            self.RADIUS_FIELD,
            self.tr('Radius from field'),
            None,
            self.INPUT,
            QgsProcessingParameterField.Numeric,
            optional=True)
        radius_field_param.setFlags(
            radius_field_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(radius_field_param)

        class ParameterHeatmapPixelSize(QgsProcessingParameterNumber):
            def __init__(self,
                         name='',
                         description='',
                         parent_layer=None,
                         radius_param=None,
                         radius_field_param=None,
                         minValue=None,
                         maxValue=None,
                         default=None,
                         optional=False):
                QgsProcessingParameterNumber.__init__(
                    self, name, description,
                    QgsProcessingParameterNumber.Double, default, optional,
                    minValue, maxValue)
                self.parent_layer = parent_layer
                self.radius_param = radius_param
                self.radius_field_param = radius_field_param

        pixel_size_param = ParameterHeatmapPixelSize(
            self.PIXEL_SIZE,
            self.tr('Output raster size'),
            parent_layer=self.INPUT,
            radius_param=self.RADIUS,
            radius_field_param=self.RADIUS_FIELD,
            minValue=0.0,
            maxValue=9999999999,
            default=0.1)
        pixel_size_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.qgis.ui.HeatmapWidgets.HeatmapPixelSizeWidgetWrapper'
            }
        })
        self.addParameter(pixel_size_param)

        weight_field_param = QgsProcessingParameterField(
            self.WEIGHT_FIELD,
            self.tr('Weight from field'),
            None,
            self.INPUT,
            QgsProcessingParameterField.Numeric,
            optional=True)
        weight_field_param.setFlags(
            weight_field_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(weight_field_param)

        keys = list(self.KERNELS.keys())
        kernel_shape_param = QgsProcessingParameterEnum(
            self.KERNEL,
            self.tr('Kernel shape'),
            keys,
            allowMultiple=False,
            defaultValue=0)
        kernel_shape_param.setFlags(
            kernel_shape_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(kernel_shape_param)

        decay_ratio = QgsProcessingParameterNumber(
            self.DECAY, self.tr('Decay ratio (Triangular kernels only)'),
            QgsProcessingParameterNumber.Double, 0.0, True, -100.0, 100.0)
        decay_ratio.setFlags(decay_ratio.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(decay_ratio)

        keys = list(self.OUTPUT_VALUES.keys())
        output_scaling = QgsProcessingParameterEnum(
            self.OUTPUT_VALUE,
            self.tr('Output value scaling'),
            keys,
            allowMultiple=False,
            defaultValue=0)
        output_scaling.setFlags(
            output_scaling.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(output_scaling)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Heatmap')))
Beispiel #15
0
    def initAlgorithm(self, config=None):
        self.KERNELS = OrderedDict([(self.tr('Quartic'), QgsKernelDensityEstimation.KernelQuartic),
                                    (self.tr('Triangular'), QgsKernelDensityEstimation.KernelTriangular),
                                    (self.tr('Uniform'), QgsKernelDensityEstimation.KernelUniform),
                                    (self.tr('Triweight'), QgsKernelDensityEstimation.KernelTriweight),
                                    (self.tr('Epanechnikov'), QgsKernelDensityEstimation.KernelEpanechnikov)])

        self.OUTPUT_VALUES = OrderedDict([(self.tr('Raw'), QgsKernelDensityEstimation.OutputRaw),
                                          (self.tr('Scaled'), QgsKernelDensityEstimation.OutputScaled)])

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Point layer'),
                                                              [QgsProcessing.TypeVectorPoint]))

        self.addParameter(QgsProcessingParameterDistance(self.RADIUS,
                                                         self.tr('Radius'),
                                                         100.0, self.INPUT, False, 0.0))

        radius_field_param = QgsProcessingParameterField(self.RADIUS_FIELD,
                                                         self.tr('Radius from field'),
                                                         None,
                                                         self.INPUT,
                                                         QgsProcessingParameterField.Numeric,
                                                         optional=True
                                                         )
        radius_field_param.setFlags(radius_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(radius_field_param)

        class ParameterHeatmapPixelSize(QgsProcessingParameterNumber):

            def __init__(self, name='', description='', parent_layer=None, radius_param=None, radius_field_param=None, minValue=None,
                         default=None, optional=False):
                QgsProcessingParameterNumber.__init__(self, name, description, QgsProcessingParameterNumber.Double, default, optional, minValue)
                self.parent_layer = parent_layer
                self.radius_param = radius_param
                self.radius_field_param = radius_field_param

            def clone(self):
                copy = ParameterHeatmapPixelSize(self.name(), self.description(), self.parent_layer, self.radius_param, self.radius_field_param, self.minimum(), self.maximum(), self.defaultValue((), self.flags() & QgsProcessingParameterDefinition.FlagOptional))
                return copy

        pixel_size_param = ParameterHeatmapPixelSize(self.PIXEL_SIZE,
                                                     self.tr('Output raster size'),
                                                     parent_layer=self.INPUT,
                                                     radius_param=self.RADIUS,
                                                     radius_field_param=self.RADIUS_FIELD,
                                                     minValue=0.0,
                                                     default=0.1)
        pixel_size_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.qgis.ui.HeatmapWidgets.HeatmapPixelSizeWidgetWrapper'}})
        self.addParameter(pixel_size_param)

        weight_field_param = QgsProcessingParameterField(self.WEIGHT_FIELD,
                                                         self.tr('Weight from field'),
                                                         None,
                                                         self.INPUT,
                                                         QgsProcessingParameterField.Numeric,
                                                         optional=True
                                                         )
        weight_field_param.setFlags(weight_field_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(weight_field_param)

        keys = list(self.KERNELS.keys())
        kernel_shape_param = QgsProcessingParameterEnum(self.KERNEL,
                                                        self.tr('Kernel shape'),
                                                        keys,
                                                        allowMultiple=False,
                                                        defaultValue=0)
        kernel_shape_param.setFlags(kernel_shape_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(kernel_shape_param)

        decay_ratio = QgsProcessingParameterNumber(self.DECAY,
                                                   self.tr('Decay ratio (Triangular kernels only)'),
                                                   QgsProcessingParameterNumber.Double,
                                                   0.0, True, -100.0, 100.0)
        decay_ratio.setFlags(decay_ratio.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(decay_ratio)

        keys = list(self.OUTPUT_VALUES.keys())
        output_scaling = QgsProcessingParameterEnum(self.OUTPUT_VALUE,
                                                    self.tr('Output value scaling'),
                                                    keys,
                                                    allowMultiple=False,
                                                    defaultValue=0)
        output_scaling.setFlags(output_scaling.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(output_scaling)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Heatmap')))
Beispiel #16
0
    def initAlgorithm(self, config=None):
        class ParameterVrtDestination(QgsProcessingParameterRasterDestination):
            def __init__(self, name, description):
                super().__init__(name, description)

            def clone(self):
                copy = ParameterVrtDestination(self.name(), self.description())
                return copy

            def type(self):
                return 'vrt_destination'

            def defaultFileExtension(self):
                return 'vrt'

        self.addParameter(
            QgsProcessingParameterMultipleLayers(
                self.INPUT,
                QCoreApplication.translate("ParameterVrtDestination",
                                           'Input layers'),
                QgsProcessing.TypeRaster))
        self.addParameter(
            QgsProcessingParameterEnum(self.RESOLUTION,
                                       QCoreApplication.translate(
                                           "ParameterVrtDestination",
                                           'Resolution'),
                                       options=self.RESOLUTION_OPTIONS,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SEPARATE,
                QCoreApplication.translate(
                    "ParameterVrtDestination",
                    'Place each input file into a separate band'),
                defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(self.PROJ_DIFFERENCE,
                                          QCoreApplication.translate(
                                              "ParameterVrtDestination",
                                              'Allow projection difference'),
                                          defaultValue=False))

        add_alpha_param = QgsProcessingParameterBoolean(
            self.ADD_ALPHA,
            QCoreApplication.translate(
                "ParameterVrtDestination",
                'Add alpha mask band to VRT when source raster has none'),
            defaultValue=False)
        add_alpha_param.setFlags(
            add_alpha_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(add_alpha_param)

        assign_crs = QgsProcessingParameterCrs(
            self.ASSIGN_CRS,
            QCoreApplication.translate(
                "ParameterVrtDestination",
                'Override projection for the output file'),
            defaultValue=None,
            optional=True)
        assign_crs.setFlags(assign_crs.flags()
                            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(assign_crs)

        resampling = QgsProcessingParameterEnum(
            self.RESAMPLING,
            QCoreApplication.translate("ParameterVrtDestination",
                                       'Resampling algorithm'),
            options=self.RESAMPLING_OPTIONS,
            defaultValue=0)
        resampling.setFlags(resampling.flags()
                            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(resampling)

        self.addParameter(
            ParameterVrtDestination(
                self.OUTPUT,
                QCoreApplication.translate("ParameterVrtDestination",
                                           'Virtual')))
Beispiel #17
0
    def initAlgorithm(self, config=None):
        self.distanceUnits = ((self.tr('Georeferenced coordinates'), 'GEO'),
                              (self.tr('Pixel coordinates'), 'PIXEL'))

        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterBand(self.BAND,
                                       self.tr('Band number'),
                                       1,
                                       parentLayerParameterName=self.INPUT))
        self.addParameter(
            QgsProcessingParameterString(
                self.VALUES,
                self.
                tr('A list of pixel values in the source image to be considered target pixels'
                   ),
                optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(
                self.UNITS,
                self.tr('Distance units'),
                options=[i[0] for i in self.distanceUnits],
                allowMultiple=False,
                defaultValue=1))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.MAX_DISTANCE,
                self.tr('The maximum distance to be generated'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.REPLACE,
                self.
                tr('Value to be applied to all pixels that are within the -maxdist of target pixels'
                   ),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.
                tr('Nodata value to use for the destination proximity raster'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0,
                optional=True))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        extra_param = QgsProcessingParameterString(
            self.EXTRA,
            self.tr('Additional command-line parameters'),
            defaultValue=None,
            optional=True)
        extra_param.setFlags(extra_param.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(extra_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=5)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Proximity map')))
Beispiel #18
0
    def initAlgorithm(self, config=None):
        self.units = [self.tr("Pixels"),
                      self.tr("Georeferenced units")]

        self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
                                                              self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterField(self.FIELD,
                                                      self.tr('Field to use for a burn-in value'),
                                                      None,
                                                      self.INPUT,
                                                      QgsProcessingParameterField.Numeric,
                                                      optional=True))
        self.addParameter(QgsProcessingParameterNumber(self.BURN,
                                                       self.tr('A fixed value to burn'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0,
                                                       optional=True))
        self.addParameter(QgsProcessingParameterEnum(self.UNITS,
                                                     self.tr('Output raster size units'),
                                                     self.units))
        self.addParameter(QgsProcessingParameterNumber(self.WIDTH,
                                                       self.tr('Width/Horizontal resolution'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.HEIGHT,
                                                       self.tr('Height/Vertical resolution'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterExtent(self.EXTENT,
                                                       self.tr('Output extent')))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Assign a specified nodata value to output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0,
                                                       optional=True))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation parameters'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        init_param = QgsProcessingParameterNumber(self.INIT,
                                                  self.tr('Pre-initialize the output image with value'),
                                                  type=QgsProcessingParameterNumber.Double,
                                                  defaultValue=0.0,
                                                  optional=True)
        init_param.setFlags(init_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(init_param)

        invert_param = QgsProcessingParameterBoolean(self.INVERT,
                                                     self.tr('Invert rasterization'),
                                                     defaultValue=False)
        invert_param.setFlags(invert_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(invert_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Rasterized')))
Beispiel #19
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Point layer'),
                [QgsProcessing.TypeVectorPoint]))

        z_field_param = QgsProcessingParameterField(
            self.Z_FIELD,
            self.tr('Z value from field'),
            None,
            self.INPUT,
            QgsProcessingParameterField.Numeric,
            optional=True)
        z_field_param.setFlags(z_field_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(z_field_param)

        self.addParameter(
            QgsProcessingParameterNumber(
                self.RADIUS_1,
                self.tr('The first radius of search ellipse'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.RADIUS_2,
                self.tr('The second radius of search ellipse'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.ANGLE,
                self.
                tr('Angle of search ellipse rotation in degrees (counter clockwise)'
                   ),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                maxValue=360.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('NODATA marker to fill empty points'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation parameters'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=5)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(
                self.OUTPUT, self.tr('Interpolated (Nearest neighbor)')))
    def initAlgorithm(self, config=None):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """

        self.db_variables = QgsSettings()
        self.taxonomic_ranks_variables = [
            "Groupes taxonomiques", "Règnes", "Phylum", "Classes", "Ordres",
            "Familles",
            "Groupes 1 INPN (regroupement vernaculaire du référentiel national - niveau 1)",
            "Groupes 2 INPN (regroupement vernaculaire du référentiel national - niveau 2)"
        ]
        self.period_variables = [
            "Pas de filtre temporel", "5 dernières années",
            "10 dernières années",
            "Date de début - Date de fin (à définir ci-dessous)"
        ]
        histogram_variables = [
            "Pas d'histogramme", "Histogramme du nombre de données par taxon",
            "Histogramme du nombre d'espèces par taxon",
            "Histogramme du nombre d'observateurs par taxon",
            "Histogramme du nombre de dates par taxon",
            "Histogramme du nombre de données de mortalité par taxon"
        ]

        # Data base connection
        db_param = QgsProcessingParameterString(
            self.DATABASE,
            self.
            tr("""<b style="color:#0a84db">CONNEXION À LA BASE DE DONNÉES</b><br/>
                <b>*1/</b> Sélectionnez votre <u>connexion</u> à la base de données LPO AuRA (<i>gnlpoaura</i>)"""
               ),
            defaultValue='gnlpoaura')
        db_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
        self.addParameter(db_param)

        # Input vector layer = study area
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.STUDY_AREA,
                self.tr("""<b style="color:#0a84db">ZONE D'ÉTUDE</b><br/>
                    <b>*2/</b> Sélectionnez votre <u>zone d'étude</u>, à partir de laquelle seront extraits les résultats"""
                        ), [QgsProcessing.TypeVectorPolygon]))

        # Taxonomic rank
        taxonomic_rank = QgsProcessingParameterEnum(
            self.TAXONOMIC_RANK,
            self.tr("""<b style="color:#0a84db">RANG TAXONOMIQUE</b><br/>
                <b>*3/</b> Sélectionnez le <u>rang taxonomique</u> qui vous intéresse"""
                    ),
            self.taxonomic_ranks_variables,
            allowMultiple=False)
        taxonomic_rank.setMetadata({
            'widget_wrapper': {
                'useCheckBoxes': True,
                'columns': len(self.taxonomic_ranks_variables) / 2
            }
        })
        self.addParameter(taxonomic_rank)

        ### Taxons filters ###
        self.addParameter(
            QgsProcessingParameterEnum(
                self.GROUPE_TAXO,
                self.tr(
                    """<b style="color:#0a84db">FILTRES DE REQUÊTAGE</b><br/>
                    <b>4/</b> Si cela vous intéresse, vous pouvez sélectionner un/plusieurs <u>taxon(s)</u> dans la liste déroulante suivante (à choix multiples)<br/> pour filtrer vos données d'observations. <u>Sinon</u>, vous pouvez ignorer cette étape.<br/>
                    <i style="color:#952132"><b>N.B.</b> : D'autres filtres taxonomiques sont disponibles dans les paramètres avancés (plus bas, juste avant l'enregistrement des résultats).</i><br/>
                    - Groupes taxonomiques :"""),
                self.db_variables.value("groupe_taxo"),
                allowMultiple=True,
                optional=True))

        regne = QgsProcessingParameterEnum(self.REGNE,
                                           self.tr("- Règnes :"),
                                           self.db_variables.value("regne"),
                                           allowMultiple=True,
                                           optional=True)
        regne.setFlags(regne.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(regne)

        phylum = QgsProcessingParameterEnum(self.PHYLUM,
                                            self.tr("- Phylum :"),
                                            self.db_variables.value("phylum"),
                                            allowMultiple=True,
                                            optional=True)
        phylum.setFlags(phylum.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(phylum)

        classe = QgsProcessingParameterEnum(self.CLASSE,
                                            self.tr("- Classe :"),
                                            self.db_variables.value("classe"),
                                            allowMultiple=True,
                                            optional=True)
        classe.setFlags(classe.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(classe)

        ordre = QgsProcessingParameterEnum(self.ORDRE,
                                           self.tr("- Ordre :"),
                                           self.db_variables.value("ordre"),
                                           allowMultiple=True,
                                           optional=True)
        ordre.setFlags(ordre.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(ordre)

        famille = QgsProcessingParameterEnum(
            self.FAMILLE,
            self.tr("- Famille :"),
            self.db_variables.value("famille"),
            allowMultiple=True,
            optional=True)
        famille.setFlags(famille.flags()
                         | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(famille)

        group1_inpn = QgsProcessingParameterEnum(
            self.GROUP1_INPN,
            self.
            tr("- Groupe 1 INPN (regroupement vernaculaire du référentiel national - niveau 1) :"
               ),
            self.db_variables.value("group1_inpn"),
            allowMultiple=True,
            optional=True)
        group1_inpn.setFlags(group1_inpn.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(group1_inpn)

        group2_inpn = QgsProcessingParameterEnum(
            self.GROUP2_INPN,
            self.
            tr("- Groupe 2 INPN (regroupement vernaculaire du référentiel national - niveau 2) :"
               ),
            self.db_variables.value("group2_inpn"),
            allowMultiple=True,
            optional=True)
        group2_inpn.setFlags(group2_inpn.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(group2_inpn)

        ### Datetime filter ###
        period = QgsProcessingParameterEnum(
            self.PERIOD,
            self.
            tr("<b>*5/</b> Sélectionnez une <u>période</u> pour filtrer vos données d'observations"
               ),
            self.period_variables,
            allowMultiple=False,
            optional=False)
        period.setMetadata({
            'widget_wrapper': {
                'useCheckBoxes': True,
                'columns': len(self.period_variables) / 2
            }
        })
        self.addParameter(period)

        start_date = QgsProcessingParameterString(
            self.START_DATE,
            """- Date de début <i style="color:#952132">(nécessaire seulement si vous avez sélectionné l'option <b>Date de début - Date de fin</b>)</i> :""",
            defaultValue="",
            optional=True)
        start_date.setMetadata({'widget_wrapper': {'class': DateTimeWidget}})
        self.addParameter(start_date)

        end_date = QgsProcessingParameterString(
            self.END_DATE,
            """- Date de fin <i style="color:#952132">(nécessaire seulement si vous avez sélectionné l'option <b>Date de début - Date de fin</b>)</i> :""",
            optional=True)
        end_date.setMetadata({'widget_wrapper': {'class': DateTimeWidget}})
        self.addParameter(end_date)

        # Extra "where" conditions
        extra_where = QgsProcessingParameterString(
            self.EXTRA_WHERE,
            self.
            tr("""Vous pouvez ajouter des <u>conditions "where"</u> supplémentaires dans l'encadré suivant, en langage SQL <b style="color:#952132">(commencez par <i>and</i>)</b>"""
               ),
            multiLine=True,
            optional=True)
        extra_where.setFlags(extra_where.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(extra_where)

        # Output PostGIS layer = summary table
        self.addOutput(
            QgsProcessingOutputVectorLayer(
                self.OUTPUT, self.tr('Couche en sortie'),
                QgsProcessing.TypeVectorAnyGeometry))

        # Output PostGIS layer name
        self.addParameter(
            QgsProcessingParameterString(
                self.OUTPUT_NAME,
                self.
                tr("""<b style="color:#0a84db">PARAMÉTRAGE DES RESULTATS EN SORTIE</b><br/>
                    <b>*6/</b> Définissez un <u>nom</u> pour votre nouvelle couche PostGIS"""
                   ), self.tr("État des connaissances")))

        # Boolean : True = add the summary table in the DB ; False = don't
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_TABLE,
                self.
                tr("Enregistrer les résultats en sortie dans une nouvelle table PostgreSQL"
                   ),
                defaultValue=False))

        ### Histogram ###
        histogram_options = QgsProcessingParameterEnum(
            self.HISTOGRAM_OPTIONS,
            self.
            tr("<b>7/</b> Si cela vous intéresse, vous pouvez <u>exporter</u> les résultats sous forme d'<u>histogramme</u>. Dans ce cas, sélectionnez le type<br/> d'histogramme qui vous convient. <u>Sinon</u>, vous pouvez ignorer cette étape."
               ),
            histogram_variables,
            defaultValue="Pas d'histogramme")
        histogram_options.setMetadata({
            'widget_wrapper': {
                'useCheckBoxes': True,
                'columns': len(histogram_variables) / 3
            }
        })
        self.addParameter(histogram_options)

        self.addParameter(
            QgsProcessingParameterFileDestination(
                self.OUTPUT_HISTOGRAM,
                self.
                tr("""<b style="color:#0a84db">ENREGISTREMENT DES RESULTATS</b><br/>
                <b>8/</b> <u style="color:#952132">Si (et seulement si !)</u> vous avez sélectionné un type d'<u>histogramme</u>, veuillez renseigner un emplacement pour l'enregistrer<br/> sur votre ordinateur (au format image). <u>Dans le cas contraire</u>, vous pouvez ignorer cette étape.<br/>
                <font style='color:#06497a'><u>Aide</u> : Cliquez sur le bouton [...] puis sur 'Enregistrer vers un fichier...'</font>"""
                   ),
                self.tr('image PNG (*.png)'),
                optional=True,
                createByDefault=False))
Beispiel #21
0
    def initAlgorithm(self, config=None):
        self.metrics = ((self.tr('Minimum'), 'minimum'), (self.tr('Maximum'),
                                                          'maximum'),
                        (self.tr('Range'), 'range'), (self.tr('Count'),
                                                      'count'),
                        (self.tr('Average distance'), 'average_distance'),
                        (self.tr('Average distance between points'),
                         'average_distance_pts'))

        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Point layer'),
                [QgsProcessing.TypeVectorPoint]))

        z_field_param = QgsProcessingParameterField(
            self.Z_FIELD,
            self.tr('Z value from field'),
            None,
            self.INPUT,
            QgsProcessingParameterField.Numeric,
            optional=True)
        z_field_param.setFlags(z_field_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(z_field_param)

        self.addParameter(
            QgsProcessingParameterEnum(self.METRIC,
                                       self.tr('Data metric to use'),
                                       options=[i[0] for i in self.metrics],
                                       allowMultiple=False,
                                       defaultValue=0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.RADIUS_1,
                self.tr('The first radius of search ellipse'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.RADIUS_2,
                self.tr('The second radius of search ellipse'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.ANGLE,
                self.
                tr('Angle of search ellipse rotation in degrees (counter clockwise)'
                   ),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                maxValue=360.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.MIN_POINTS,
                self.tr('Minimum number of data points to use'),
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                defaultValue=0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('NODATA marker to fill empty points'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=5)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(
                self.OUTPUT, self.tr('Interpolated (data metrics)')))
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.MASK, self.tr('Mask layer'),
                [QgsProcessing.TypeVectorPolygon]))
        self.addParameter(
            QgsProcessingParameterCrs(self.SOURCE_CRS,
                                      self.tr('Source CRS'),
                                      optional=True))
        self.addParameter(
            QgsProcessingParameterCrs(self.TARGET_CRS,
                                      self.tr('Target CRS'),
                                      optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('Assign a specified nodata value to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ALPHA_BAND,
                self.tr('Create an output alpha band'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.CROP_TO_CUTLINE,
                self.
                tr('Match the extent of the clipped raster to the extent of the mask layer'
                   ),
                defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.KEEP_RESOLUTION,
                self.tr('Keep resolution of input raster'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SET_RESOLUTION,
                self.tr('Set output file resolution'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.X_RESOLUTION,
                self.tr('X Resolution to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.Y_RESOLUTION,
                self.tr('Y Resolution to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        multithreading_param = QgsProcessingParameterBoolean(
            self.MULTITHREADING,
            self.tr('Use multithreaded warping implementation'),
            defaultValue=False)
        multithreading_param.setFlags(
            multithreading_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(multithreading_param)
        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=0)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Clipped (mask)')))
Beispiel #23
0
    def initAlgorithm(self, config=None):
        self.units = [self.tr("Pixels"), self.tr("Georeferenced units")]

        self.addParameter(
            QgsProcessingParameterFeatureSource(self.INPUT,
                                                self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterField(
                self.FIELD,
                self.tr('Field to use for a burn-in value'),
                None,
                self.INPUT,
                QgsProcessingParameterField.Numeric,
                optional=True))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.BURN,
                self.tr('A fixed value to burn'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0,
                optional=True))
        self.addParameter(
            QgsProcessingParameterEnum(self.UNITS,
                                       self.tr('Output raster size units'),
                                       self.units))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.WIDTH,
                self.tr('Width/Horizontal resolution'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.HEIGHT,
                self.tr('Height/Vertical resolution'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterExtent(self.EXTENT,
                                         self.tr('Output extent')))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('Assign a specified nodata value to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0,
                optional=True))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=5)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        init_param = QgsProcessingParameterNumber(
            self.INIT,
            self.tr('Pre-initialize the output image with value'),
            type=QgsProcessingParameterNumber.Double,
            defaultValue=0.0,
            optional=True)
        init_param.setFlags(init_param.flags()
                            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(init_param)

        invert_param = QgsProcessingParameterBoolean(
            self.INVERT, self.tr('Invert rasterization'), defaultValue=False)
        invert_param.setFlags(invert_param.flags()
                              | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(invert_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Rasterized')))
Beispiel #24
0
    def initAlgorithm(self, config=None):
        self.methods = ((self.tr('Nearest neighbour'), 'near'),
                        (self.tr('Bilinear'), 'bilinear'),
                        (self.tr('Cubic'), 'cubic'),
                        (self.tr('Cubic spline'), 'cubicspline'),
                        (self.tr('Lanczos windowed sinc'), 'lanczos'),
                        (self.tr('Average'), 'average'),
                        (self.tr('Mode'), 'mode'),
                        (self.tr('Maximum'), 'max'),
                        (self.tr('Minimum'), 'min'),
                        (self.tr('Median'), 'med'),
                        (self.tr('First quartile'), 'q1'),
                        (self.tr('Third quartile'), 'q3'))

        self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
        self.addParameter(QgsProcessingParameterCrs(self.SOURCE_CRS,
                                                    self.tr('Source CRS'),
                                                    optional=True))
        self.addParameter(QgsProcessingParameterCrs(self.TARGET_CRS,
                                                    self.tr('Target CRS'),
                                                    'EPSG:4326'))
        self.addParameter(QgsProcessingParameterNumber(self.NODATA,
                                                       self.tr('Nodata value for output bands'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       defaultValue=0.0))
        self.addParameter(QgsProcessingParameterNumber(self.TARGET_RESOLUTION,
                                                       self.tr('Output file resolution in target georeferenced units'),
                                                       type=QgsProcessingParameterNumber.Double,
                                                       minValue=0.0,
                                                       defaultValue=None))

        options_param = QgsProcessingParameterString(self.OPTIONS,
                                                     self.tr('Additional creation parameters'),
                                                     defaultValue='',
                                                     optional=True)
        options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class': 'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'}})
        self.addParameter(options_param)

        self.addParameter(QgsProcessingParameterEnum(self.RESAMPLING,
                                                     self.tr('Resampling method to use'),
                                                     options=[i[0] for i in self.methods],
                                                     defaultValue=0))

        dataType_param = QgsProcessingParameterEnum(self.DATA_TYPE,
                                                    self.tr('Output data type'),
                                                    self.TYPES,
                                                    allowMultiple=False,
                                                    defaultValue=5)
        dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        target_extent_param = QgsProcessingParameterExtent(self.TARGET_EXTENT,
                                                           self.tr('Georeferenced extents of output file to be created'),
                                                           optional=True)
        target_extent_param.setFlags(target_extent_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(target_extent_param)

        target_extent_crs_param = QgsProcessingParameterCrs(self.TARGET_EXTENT_CRS,
                                                            self.tr('CRS of the target raster extent'),
                                                            optional=True)
        target_extent_crs_param.setFlags(target_extent_crs_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(target_extent_crs_param)

        multithreading_param = QgsProcessingParameterBoolean(self.MULTITHREADING,
                                                             self.tr('Use multithreaded warping implementation'),
                                                             defaultValue=False)
        multithreading_param.setFlags(multithreading_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(multithreading_param)

        self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                                  self.tr('Reprojected')))
Beispiel #25
0
    def initAlgorithm(self, config=None):
        class ParameterVrtDestination(QgsProcessingParameterRasterDestination):
            def __init__(self, name, description):
                super().__init__(name, description)

            def clone(self):
                copy = ParameterVrtDestination(self.name(), self.description())
                return copy

            def defaultFileExtension(self):
                return 'vrt'

            def createFileFilter(self):
                return '{} (*.vrt *.VRT)'.format(
                    QCoreApplication.translate("GdalAlgorithm", 'VRT files'))

            def supportedOutputRasterLayerExtensions(self):
                return ['vrt']

            def parameterAsOutputLayer(self, definition, value, context):
                return super(QgsProcessingParameterRasterDestination,
                             self).parameterAsOutputLayer(
                                 definition, value, context)

            def isSupportedOutputValue(self, value, context):
                output_path = QgsProcessingParameters.parameterAsOutputLayer(
                    self, value, context)
                if pathlib.Path(output_path).suffix.lower() != '.vrt':
                    return False, QCoreApplication.translate(
                        "GdalAlgorithm",
                        'Output filename must use a .vrt extension')
                return True, ''

        self.RESAMPLING_OPTIONS = ((self.tr('Nearest Neighbour'), 'nearest'),
                                   (self.tr('Bilinear'), 'bilinear'),
                                   (self.tr('Cubic Convolution'),
                                    'cubic'), (self.tr('B-Spline Convolution'),
                                               'cubicspline'),
                                   (self.tr('Lanczos Windowed Sinc'),
                                    'lanczos'), (self.tr('Average'),
                                                 'average'), (self.tr('Mode'),
                                                              'mode'))

        self.RESOLUTION_OPTIONS = ((self.tr('Average'), 'average'),
                                   (self.tr('Highest'),
                                    'highest'), (self.tr('Lowest'), 'lowest'))

        self.addParameter(
            QgsProcessingParameterMultipleLayers(self.INPUT,
                                                 self.tr('Input layers'),
                                                 QgsProcessing.TypeRaster))
        self.addParameter(
            QgsProcessingParameterEnum(
                self.RESOLUTION,
                self.tr('Resolution'),
                options=[i[0] for i in self.RESOLUTION_OPTIONS],
                defaultValue=0))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.SEPARATE,
                self.tr('Place each input file into a separate band'),
                defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.PROJ_DIFFERENCE,
                self.tr('Allow projection difference'),
                defaultValue=False))

        add_alpha_param = QgsProcessingParameterBoolean(
            self.ADD_ALPHA,
            self.tr('Add alpha mask band to VRT when source raster has none'),
            defaultValue=False)
        add_alpha_param.setFlags(
            add_alpha_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(add_alpha_param)

        assign_crs = QgsProcessingParameterCrs(
            self.ASSIGN_CRS,
            self.tr('Override projection for the output file'),
            defaultValue=None,
            optional=True)
        assign_crs.setFlags(assign_crs.flags()
                            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(assign_crs)

        resampling = QgsProcessingParameterEnum(
            self.RESAMPLING,
            self.tr('Resampling algorithm'),
            options=[i[0] for i in self.RESAMPLING_OPTIONS],
            defaultValue=0)
        resampling.setFlags(resampling.flags()
                            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(resampling)

        src_nodata_param = QgsProcessingParameterString(
            self.SRC_NODATA,
            self.tr('Nodata value(s) for input bands (space separated)'),
            defaultValue=None,
            optional=True)
        src_nodata_param.setFlags(
            src_nodata_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(src_nodata_param)

        extra_param = QgsProcessingParameterString(
            self.EXTRA,
            self.tr('Additional command-line parameters'),
            defaultValue=None,
            optional=True)
        extra_param.setFlags(extra_param.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(extra_param)

        self.addParameter(
            ParameterVrtDestination(
                self.OUTPUT,
                QCoreApplication.translate("ParameterVrtDestination",
                                           'Virtual')))
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.INPUT, self.tr('Point layer'),
                [QgsProcessing.TypeVectorPoint]))

        z_field_param = QgsProcessingParameterField(
            self.Z_FIELD,
            self.tr('Z value from field'),
            None,
            self.INPUT,
            QgsProcessingParameterField.Numeric,
            optional=True)
        z_field_param.setFlags(z_field_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(z_field_param)

        self.addParameter(
            QgsProcessingParameterNumber(
                self.POWER,
                self.tr('Weighting power'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                maxValue=100.0,
                defaultValue=2.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.SMOOTHING,
                self.tr('Smoothing'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=0.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.RADIUS,
                self.tr('The radius of the search circle'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0.0,
                defaultValue=1.0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.MAX_POINTS,
                self.tr('Maximum number of data points to use'),
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                defaultValue=12))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.MIN_POINTS,
                self.tr('Minimum number of data points to use'),
                type=QgsProcessingParameterNumber.Integer,
                minValue=0,
                defaultValue=0))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('NODATA marker to fill empty points'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=0.0))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=5)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(
                self.OUTPUT, self.tr('Interpolated (IDW with NN search)')))
    def initAlgorithm(self, config=None):
        """
        Here we define the inputs and output of the algorithm, along
        with some other properties.
        """

        self.ts = datetime.now()
        self.db_variables = QgsSettings()
        self.interval_variables = ["Par année", "Par mois"]
        self.months_names_variables = [
            "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet",
            "Août", "Septembre", "Octobre", "Novembre", "Décembre"
        ]
        self.taxonomic_ranks_variables = ["Espèces", "Groupes taxonomiques"]
        self.agg_variables = ["Nombre de données", "Nombre d'espèces"]

        # Data base connection
        db_param = QgsProcessingParameterString(
            self.DATABASE,
            self.
            tr("""<b style="color:#0a84db">CONNEXION À LA BASE DE DONNÉES</b><br/>
                <b>*1/</b> Sélectionnez votre <u>connexion</u> à la base de données LPO AuRA (<i>gnlpoaura</i>)"""
               ),
            defaultValue='gnlpoaura')
        db_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.gui.wrappers_postgis.ConnectionWidgetWrapper'
            }
        })
        self.addParameter(db_param)

        # Input vector layer = study area
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.STUDY_AREA,
                self.tr("""<b style="color:#0a84db">ZONE D'ÉTUDE</b><br/>
                    <b>*2/</b> Sélectionnez votre <u>zone d'étude</u>, à partir de laquelle seront extraits les résultats"""
                        ), [QgsProcessing.TypeVectorPolygon]))

        ### Time interval and period ###
        time_interval = QgsProcessingParameterEnum(
            self.TIME_INTERVAL,
            self.
            tr("""<b style="color:#0a84db">AGRÉGATION TEMPORELLE ET PÉRIODE</b><br/>
                <b>*3/</b> Sélectionnez l'<u>agrégation temporelle</u> qui vous intéresse"""
               ),
            self.interval_variables,
            allowMultiple=False)
        time_interval.setMetadata({
            'widget_wrapper': {
                'useCheckBoxes': True,
                'columns': len(self.interval_variables)
            }
        })
        self.addParameter(time_interval)

        add_five_years = QgsProcessingParameterEnum(
            self.ADD_FIVE_YEARS,
            self.
            tr("""<b>4/</b> <u style="color:#952132">Si (et seulement si !)</u> vous avez sélectionné l'<u>agrégation <b>Par année</b></u> :<br/> cochez la case ci-dessous si vous souhaitez ajouter des colonnes dîtes "bilan" par intervalle de 5 ans.<br/>
            <i style="color:#952132"><b>N.B.</b> : En cochant cette case, vous devez vous assurer de renseigner une période en années (cf. <b>*5/</b>) qui soit <b>divisible par 5</b>.<br/> Exemple : 2011 - 2020.</i>"""
               ),
            [
                'Oui, je souhaite ajouter des colonnes dîtes "bilan" par intervalle de 5 ans'
            ],
            allowMultiple=True,
            optional=True)
        add_five_years.setMetadata(
            {'widget_wrapper': {
                'useCheckBoxes': True,
                'columns': 1
            }})
        self.addParameter(add_five_years)

        self.addParameter(
            QgsProcessingParameterEnum(
                self.START_MONTH,
                self.
                tr("""<b>*5/</b> Sélectionnez la <u>période</u> qui vous intéresse<br/>
                    - Mois de début <i style="color:#952132">(nécessaire seulement si vous avez sélectionné l'agrégation <b>Par mois</b>)</i> :"""
                   ),
                self.months_names_variables,
                allowMultiple=False,
                optional=True))

        self.addParameter(
            QgsProcessingParameterNumber(self.START_YEAR,
                                         self.tr("- *Année de début :"),
                                         QgsProcessingParameterNumber.Integer,
                                         defaultValue=2010,
                                         minValue=1800,
                                         maxValue=int(self.ts.strftime('%Y'))))

        self.addParameter(
            QgsProcessingParameterEnum(
                self.END_MONTH,
                self.
                tr("""- Mois de fin <i style="color:#952132">(nécessaire seulement si vous avez sélectionné l'agrégation <b>Par mois</b>)</i> :"""
                   ),
                self.months_names_variables,
                allowMultiple=False,
                optional=True))

        self.addParameter(
            QgsProcessingParameterNumber(self.END_YEAR,
                                         self.tr("- *Année de fin :"),
                                         QgsProcessingParameterNumber.Integer,
                                         defaultValue=self.ts.strftime('%Y'),
                                         minValue=1800,
                                         maxValue=int(self.ts.strftime('%Y'))))

        # Taxonomic rank
        taxonomic_rank = QgsProcessingParameterEnum(
            self.TAXONOMIC_RANK,
            self.tr("""<b style="color:#0a84db">RANG TAXONOMIQUE</b><br/>
                <b>*6/</b> Sélectionnez le <u>rang taxonomique</u> qui vous intéresse"""
                    ),
            self.taxonomic_ranks_variables,
            allowMultiple=False)
        taxonomic_rank.setMetadata({
            'widget_wrapper': {
                'useCheckBoxes': True,
                'columns': len(self.taxonomic_ranks_variables)
            }
        })
        self.addParameter(taxonomic_rank)

        # Aggregation type
        aggregation_type = QgsProcessingParameterEnum(
            self.AGG,
            self.tr(
                """<b style="color:#0a84db">AGRÉGATION DES RÉSULTATS</b><br/>
                <b>*7/</b> Sélectionnez le <u>type d'agrégation</u> qui vous intéresse pour les résultats<br/>
                <i style="color:#952132"><b>N.B.</b> : Si vous avez choisi <b>Espèces</b> pour le rang taxonomique, <b>Nombre de données</b> sera utilisé <b>par défaut</b></i>"""
            ),
            self.agg_variables,
            allowMultiple=False,
            defaultValue="Nombre de données")
        aggregation_type.setMetadata({
            'widget_wrapper': {
                'useCheckBoxes': True,
                'columns': len(self.agg_variables)
            }
        })
        self.addParameter(aggregation_type)

        ### Taxons filters ###
        self.addParameter(
            QgsProcessingParameterEnum(
                self.GROUPE_TAXO,
                self.tr(
                    """<b style="color:#0a84db">FILTRES DE REQUÊTAGE</b><br/>
                    <b>8/</b> Si cela vous intéresse, vous pouvez sélectionner un/plusieurs <u>taxon(s)</u> dans la liste déroulante suivante (à choix multiples)<br/> pour filtrer vos données d'observations. <u>Sinon</u>, vous pouvez ignorer cette étape.<br/>
                    <i style="color:#952132"><b>N.B.</b> : D'autres filtres taxonomiques sont disponibles dans les paramètres avancés (plus bas, juste avant l'enregistrement des résultats).</i><br/>
                    - Groupes taxonomiques :"""),
                self.db_variables.value("groupe_taxo"),
                allowMultiple=True,
                optional=True))

        regne = QgsProcessingParameterEnum(self.REGNE,
                                           self.tr("- Règnes :"),
                                           self.db_variables.value("regne"),
                                           allowMultiple=True,
                                           optional=True)
        regne.setFlags(regne.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(regne)

        phylum = QgsProcessingParameterEnum(self.PHYLUM,
                                            self.tr("- Phylum :"),
                                            self.db_variables.value("phylum"),
                                            allowMultiple=True,
                                            optional=True)
        phylum.setFlags(phylum.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(phylum)

        classe = QgsProcessingParameterEnum(self.CLASSE,
                                            self.tr("- Classe :"),
                                            self.db_variables.value("classe"),
                                            allowMultiple=True,
                                            optional=True)
        classe.setFlags(classe.flags()
                        | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(classe)

        ordre = QgsProcessingParameterEnum(self.ORDRE,
                                           self.tr("- Ordre :"),
                                           self.db_variables.value("ordre"),
                                           allowMultiple=True,
                                           optional=True)
        ordre.setFlags(ordre.flags()
                       | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(ordre)

        famille = QgsProcessingParameterEnum(
            self.FAMILLE,
            self.tr("- Famille :"),
            self.db_variables.value("famille"),
            allowMultiple=True,
            optional=True)
        famille.setFlags(famille.flags()
                         | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(famille)

        group1_inpn = QgsProcessingParameterEnum(
            self.GROUP1_INPN,
            self.
            tr("- Groupe 1 INPN (regroupement vernaculaire du référentiel national - niveau 1) :"
               ),
            self.db_variables.value("group1_inpn"),
            allowMultiple=True,
            optional=True)
        group1_inpn.setFlags(group1_inpn.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(group1_inpn)

        group2_inpn = QgsProcessingParameterEnum(
            self.GROUP2_INPN,
            self.
            tr("- Groupe 2 INPN (regroupement vernaculaire du référentiel national - niveau 2) :"
               ),
            self.db_variables.value("group2_inpn"),
            allowMultiple=True,
            optional=True)
        group2_inpn.setFlags(group2_inpn.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(group2_inpn)

        # Extra "where" conditions
        extra_where = QgsProcessingParameterString(
            self.EXTRA_WHERE,
            self.
            tr("""Vous pouvez ajouter des <u>conditions "where"</u> supplémentaires dans l'encadré suivant, en langage SQL <b style="color:#952132">(commencez par <i>and</i>)</b>"""
               ),
            multiLine=True,
            optional=True)
        extra_where.setFlags(extra_where.flags()
                             | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(extra_where)

        # Output PostGIS layer = summary table
        self.addOutput(
            QgsProcessingOutputVectorLayer(
                self.OUTPUT, self.tr('Couche en sortie'),
                QgsProcessing.TypeVectorAnyGeometry))

        # Output PostGIS layer name
        self.addParameter(
            QgsProcessingParameterString(
                self.OUTPUT_NAME,
                self.
                tr("""<b style="color:#0a84db">PARAMÉTRAGE DES RESULTATS EN SORTIE</b><br/>
                    <b>*9/</b> Définissez un <u>nom</u> pour votre couche PostGIS"""
                   ), self.tr("Tableau synthèse temps")))

        # Boolean : True = add the summary table in the DB ; False = don't
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ADD_TABLE,
                self.
                tr("Enregistrer les résultats en sortie dans une nouvelle table PostgreSQL"
                   ), False))

        ### Histogram ###
        add_histogram = QgsProcessingParameterEnum(
            self.ADD_HISTOGRAM,
            self.
            tr("""<b>10/</b> Cochez la case ci-dessous si vous souhaitez <u>exporter</u> les résultats sous la forme d'un <u>histogramme</u> du total par<br/> pas de temps choisi."""
               ),
            [
                "Oui, je souhaite exporter les résultats sous la forme d'un histogramme du total par pas de temps choisi"
            ],
            allowMultiple=True,
            optional=True)
        add_histogram.setMetadata(
            {'widget_wrapper': {
                'useCheckBoxes': True,
                'columns': 1
            }})
        self.addParameter(add_histogram)

        self.addParameter(
            QgsProcessingParameterFileDestination(
                self.OUTPUT_HISTOGRAM,
                self.
                tr("""<b style="color:#0a84db">ENREGISTREMENT DES RESULTATS</b><br/>
                <b>11/</b> <u style="color:#952132">Si (et seulement si !)</u> vous avez sélectionné l'export sous forme d'<u>histogramme</u>, veuillez renseigner un emplacement<br/> pour l'enregistrer sur votre ordinateur (au format image). <u>Dans le cas contraire</u>, vous pouvez ignorer cette étape.<br/>
                <font style='color:#06497a'><u>Aide</u> : Cliquez sur le bouton [...] puis sur 'Enregistrer vers un fichier...'</font>"""
                   ),
                self.tr('image PNG (*.png)'),
                optional=True,
                createByDefault=False))
Beispiel #28
0
    def initAlgorithm(self, config=None):
        self.addParameter(
            QgsProcessingParameterRasterLayer(self.INPUT,
                                              self.tr('Input layer')))
        self.addParameter(
            QgsProcessingParameterFeatureSource(
                self.MASK, self.tr('Mask layer'),
                [QgsProcessing.TypeVectorPolygon]))
        self.addParameter(
            QgsProcessingParameterNumber(
                self.NODATA,
                self.tr('Assign a specified nodata value to output bands'),
                type=QgsProcessingParameterNumber.Double,
                defaultValue=None,
                optional=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.ALPHA_BAND,
                self.tr('Create an output alpha band'),
                defaultValue=False))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.CROP_TO_CUTLINE,
                self.
                tr('Crop the extent of the target dataset to the extent of the cutline'
                   ),
                defaultValue=True))
        self.addParameter(
            QgsProcessingParameterBoolean(
                self.KEEP_RESOLUTION,
                self.tr('Keep resolution of output raster'),
                defaultValue=False))

        options_param = QgsProcessingParameterString(
            self.OPTIONS,
            self.tr('Additional creation options'),
            defaultValue='',
            optional=True)
        options_param.setFlags(options_param.flags()
                               | QgsProcessingParameterDefinition.FlagAdvanced)
        options_param.setMetadata({
            'widget_wrapper': {
                'class':
                'processing.algs.gdal.ui.RasterOptionsWidget.RasterOptionsWidgetWrapper'
            }
        })
        self.addParameter(options_param)

        dataType_param = QgsProcessingParameterEnum(
            self.DATA_TYPE,
            self.tr('Output data type'),
            self.TYPES,
            allowMultiple=False,
            defaultValue=0)
        dataType_param.setFlags(
            dataType_param.flags()
            | QgsProcessingParameterDefinition.FlagAdvanced)
        self.addParameter(dataType_param)

        self.addParameter(
            QgsProcessingParameterRasterDestination(self.OUTPUT,
                                                    self.tr('Clipped (mask)')))