def getOutputFromString(s): try: if "|" in s and s.startswith("Output"): tokens = s.split("|") params = [t if str(t) != "None" else None for t in tokens[1:]] clazz = getattr(sys.modules[__name__], tokens[0]) return clazz(*params) else: tokens = s.split("=") if not tokens[1].lower()[:len('output')] == 'output': return None name = tokens[0] description = tokens[0] token = tokens[1].strip()[len('output') + 1:] out = None if token.lower().strip().startswith('outputraster'): out = QgsProcessingOutputRasterLayer(name, description) elif token.lower().strip() == 'outputvector': out = QgsProcessingOutputVectorLayer(name, description) elif token.lower().strip() == 'outputlayer': out = QgsProcessingOutputMapLayer(name, description) elif token.lower().strip() == 'outputmultilayers': out = QgsProcessingOutputMultipleLayers(name, description) # elif token.lower().strip() == 'vector point': # out = OutputVector(datatype=[dataobjects.TYPE_VECTOR_POINT]) # elif token.lower().strip() == 'vector line': # out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_LINE]) # elif token.lower().strip() == 'vector polygon': # out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_POLYGON]) # elif token.lower().strip().startswith('table'): # out = OutputTable() elif token.lower().strip().startswith('outputhtml'): out = QgsProcessingOutputHtml(name, description) # elif token.lower().strip().startswith('file'): # out = OutputFile() # ext = token.strip()[len('file') + 1:] # if ext: # out.ext = ext elif token.lower().strip().startswith('outputfolder'): out = QgsProcessingOutputFolder(name, description) elif token.lower().strip().startswith('outputnumber'): out = QgsProcessingOutputNumber(name, description) elif token.lower().strip().startswith('outputstring'): out = QgsProcessingOutputString(name, description) # elif token.lower().strip().startswith('extent'): # out = OutputExtent() return out except: return None
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterBand(self.BAND, self.tr('Band number'), 1, self.INPUT)) self.addParameter(QgsProcessingParameterNumber(self.BINS, self.tr('number of bins'), minValue=2, defaultValue=10)) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Histogram'), self.tr('HTML files (*.html)'))) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Histogram')))
def initAlgorithm(self, config=None): """ Algorithm initialization """ for p in self.params: # We use createOutput argument for automatic output creation res = self.addParameter(p, True) # File destinations are not automatically added as outputs if (isinstance(p, QgsProcessingParameterFileDestination) and p.defaultFileExtension().lower() == 'html'): self.addOutput( QgsProcessingOutputHtml(p.name(), p.description()))
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), types=[QgsProcessing.TypeVector])) self.addParameter(QgsProcessingParameterField(self.FIELDS, self.tr('Target field(s)'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Any, allowMultiple=True)) self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Unique values'), optional=True, defaultValue='')) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT_HTML_FILE, self.tr('HTML report'), self.tr('HTML files (*.html)'), None, True)) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT_HTML_FILE, self.tr('HTML report'))) self.addOutput(QgsProcessingOutputNumber(self.TOTAL_VALUES, self.tr('Total unique values'))) self.addOutput(QgsProcessingOutputString(self.UNIQUE_VALUES, self.tr('Unique values')))
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterField(self.NAME_FIELD, self.tr('Category name field'), None, self.INPUT, QgsProcessingParameterField.Any)) self.addParameter(QgsProcessingParameterField(self.VALUE_FIELD, self.tr('Value field'), None, self.INPUT, QgsProcessingParameterField.Numeric)) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Bar plot'), self.tr('HTML files (*.html)'))) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Bar plot')))
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterVectorLayer(self.INPUT, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterBoolean(self.SUMMARY_ONLY, self.tr('Summary output only'), defaultValue=True)) self.addParameter(QgsProcessingParameterBoolean(self.NO_METADATA, self.tr('Suppress metadata info'), defaultValue=False)) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Layer information'), self.tr('HTML files (*.html)'))) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Layer information')))
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterField(self.XFIELD, self.tr('X attribute'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Numeric)) self.addParameter(QgsProcessingParameterField(self.YFIELD, self.tr('Y attribute'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Numeric)) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Scatterplot'), self.tr('HTML files (*.html)'))) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Scatterplot')))
def __init__(self): super().__init__() self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterField(self.NAME_FIELD, self.tr('Category name field'), None, self.INPUT, QgsProcessingParameterField.Any)) self.addParameter(QgsProcessingParameterField(self.VALUE_FIELD, self.tr('Value field'), None, self.INPUT, QgsProcessingParameterField.Numeric)) self.addParameter(QgsProcessingParameterFileOutput(self.OUTPUT, self.tr('Added'), self.tr('HTML files (*.html)'))) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Bar plot')))
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'), [QgsProcessing.TypeVectorPoint])) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT_HTML_FILE, self.tr('Nearest neighbour'), self.tr('HTML files (*.html)'), None, True)) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT_HTML_FILE, self.tr('Nearest neighbour'))) self.addOutput(QgsProcessingOutputNumber(self.OBSERVED_MD, self.tr('Observed mean distance'))) self.addOutput(QgsProcessingOutputNumber(self.EXPECTED_MD, self.tr('Expected mean distance'))) self.addOutput(QgsProcessingOutputNumber(self.NN_INDEX, self.tr('Nearest neighbour index'))) self.addOutput(QgsProcessingOutputNumber(self.POINT_COUNT, self.tr('Number of points'))) self.addOutput(QgsProcessingOutputNumber(self.Z_SCORE, self.tr('Z-Score')))
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterBand(self.BAND, self.tr('Band number'), 1, self.INPUT)) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT_HTML_FILE, self.tr('Statistics'), self.tr('HTML files (*.html)'), None, True)) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT_HTML_FILE, self.tr('Statistics'))) self.addOutput(QgsProcessingOutputNumber(self.MIN, self.tr('Minimum value'))) self.addOutput(QgsProcessingOutputNumber(self.MAX, self.tr('Maximum value'))) self.addOutput(QgsProcessingOutputNumber(self.RANGE, self.tr('Range'))) self.addOutput(QgsProcessingOutputNumber(self.SUM, self.tr('Sum'))) self.addOutput(QgsProcessingOutputNumber(self.MEAN, self.tr('Mean value'))) self.addOutput(QgsProcessingOutputNumber(self.STD_DEV, self.tr('Standard deviation'))) self.addOutput(QgsProcessingOutputNumber(self.SUM_OF_SQUARES, self.tr('Sum of the squares')))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input table'))) self.addParameter( QgsProcessingParameterField(self.NAME_FIELD, self.tr('Category name field'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Any)) self.addParameter( QgsProcessingParameterField(self.VALUE_FIELD, self.tr('Value field'), parentLayerParameterName=self.INPUT)) self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT, self.tr('Plot'), self.tr('HTML files (*.html)'))) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Plot')))
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterBoolean(self.MIN_MAX, self.tr('Force computation of the actual min/max values for each band'), defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.STATS, self.tr('Read and display image statistics (force computation if necessary)'), defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.NO_GCP, self.tr('Suppress GCP info'), defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.NO_METADATA, self.tr('Suppress metadata info'), defaultValue=False)) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Layer information'), self.tr('HTML files (*.html)'))) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Layer information')))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterRasterLayer(information.INPUT, self.tr('Input layer'), optional=False)) self.addParameter( QgsProcessingParameterBoolean(information.NOGCP, self.tr('Suppress GCP info'), defaultValue=False)) self.addParameter( QgsProcessingParameterBoolean(information.NOMETADATA, self.tr('Suppress metadata info'), defaultValue=False)) self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT, self.tr('Layer information'), self.tr('HTML files (*.html)'))) self.addOutput( QgsProcessingOutputHtml(self.OUTPUT, self.tr('Layer information')))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'))) self.addParameter( QgsProcessingParameterField( self.FIELD, self.tr('Attribute'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Numeric)) self.addParameter( QgsProcessingParameterNumber(self.BINS, self.tr('number of bins'), minValue=2, defaultValue=10)) self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT, self.tr('Histogram'), self.tr('HTML files (*.html)'))) self.addOutput( QgsProcessingOutputHtml(self.OUTPUT, self.tr('Histogram')))
def initAlgorithm(self, config=None): self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'))) self.addParameter(QgsProcessingParameterField(self.NAME_FIELD, self.tr('Category name field'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Any)) self.addParameter(QgsProcessingParameterField(self.VALUE_FIELD, self.tr('Value field'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Numeric)) msd = [self.tr('Show Mean'), self.tr('Show Standard Deviation'), self.tr('Don\'t show Mean and Standard Deviation') ] self.addParameter(QgsProcessingParameterEnum( self.MSD, self.tr('Additional Statistic Lines'), options=msd, defaultValue=0)) self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT, self.tr('Box plot'), self.tr('HTML files (*.html)'))) self.addOutput(QgsProcessingOutputHtml(self.OUTPUT, self.tr('Box plot')))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterFeatureSource(self.INPUT_LAYER, self.tr('Input layer'))) self.addParameter( QgsProcessingParameterField( self.FIELD_NAME, self.tr('Field to calculate statistics on'), None, self.INPUT_LAYER, QgsProcessingParameterField.Any)) self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT_HTML_FILE, self.tr('Statistics'), self.tr('HTML files (*.html)'), None, True)) self.addOutput( QgsProcessingOutputHtml(self.OUTPUT_HTML_FILE, self.tr('Statistics'))) self.addOutput(QgsProcessingOutputNumber(self.COUNT, self.tr('Count'))) self.addOutput( QgsProcessingOutputNumber(self.UNIQUE, self.tr('Number of unique values'))) self.addOutput( QgsProcessingOutputNumber( self.EMPTY, self.tr('Number of empty (null) values'))) self.addOutput( QgsProcessingOutputNumber(self.FILLED, self.tr('Number of non-empty values'))) self.addOutput( QgsProcessingOutputNumber(self.MIN, self.tr('Minimum value'))) self.addOutput( QgsProcessingOutputNumber(self.MAX, self.tr('Maximum value'))) self.addOutput( QgsProcessingOutputNumber(self.MIN_LENGTH, self.tr('Minimum length'))) self.addOutput( QgsProcessingOutputNumber(self.MAX_LENGTH, self.tr('Maximum length'))) self.addOutput( QgsProcessingOutputNumber(self.MEAN_LENGTH, self.tr('Mean length'))) self.addOutput( QgsProcessingOutputNumber(self.CV, self.tr('Coefficient of Variation'))) self.addOutput(QgsProcessingOutputNumber(self.SUM, self.tr('Sum'))) self.addOutput( QgsProcessingOutputNumber(self.MEAN, self.tr('Mean value'))) self.addOutput( QgsProcessingOutputNumber(self.STD_DEV, self.tr('Standard deviation'))) self.addOutput(QgsProcessingOutputNumber(self.RANGE, self.tr('Range'))) self.addOutput( QgsProcessingOutputNumber(self.MEDIAN, self.tr('Median'))) self.addOutput( QgsProcessingOutputNumber( self.MINORITY, self.tr('Minority (rarest occurring value)'))) self.addOutput( QgsProcessingOutputNumber( self.MAJORITY, self.tr('Majority (most frequently occurring value)'))) self.addOutput( QgsProcessingOutputNumber(self.FIRSTQUARTILE, self.tr('First quartile'))) self.addOutput( QgsProcessingOutputNumber(self.THIRDQUARTILE, self.tr('Third quartile'))) self.addOutput( QgsProcessingOutputNumber(self.IQR, self.tr('Interquartile Range (IQR)')))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterVectorLayer( "inputlayer", "Input Layer", types=[QgsProcessing.TypeVectorPolygon], defaultValue=None, )) self.addParameter( QgsProcessingParameterVectorLayer( "overlaylayer", "Overlay Layer (Data Source)", types=[QgsProcessing.TypeVectorPolygon], defaultValue=None, )) param = QgsProcessingParameterField( "identifierfieldforreport", "Identifier Field for Report", optional=True, type=QgsProcessingParameterField.Any, parentLayerParameterName="inputlayer", allowMultiple=False, defaultValue="", ) param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(param) self.addParameter( QgsProcessingParameterField( "fieldtoaverage", "Field to Average", type=QgsProcessingParameterField.Numeric, parentLayerParameterName="overlaylayer", allowMultiple=False, defaultValue=None, )) param = QgsProcessingParameterField( "additionalfields", "Additional Fields to Keep for Report", optional=True, type=QgsProcessingParameterField.Any, parentLayerParameterName="overlaylayer", allowMultiple=True, ) param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(param) self.addParameter( QgsProcessingParameterFeatureSink( "result", "Result", type=QgsProcessing.TypeVectorAnyGeometry, createByDefault=True, defaultValue=None, )) self.addParameter( QgsProcessingParameterFeatureSink( "reportaslayer", "Report as Layer", type=QgsProcessing.TypeVectorAnyGeometry, createByDefault=True, defaultValue=None, )) self.addParameter( QgsProcessingParameterFileDestination( "reportasHTML", self.tr("Report as HTML"), self.tr("HTML files (*.html)"), None, True, )) # read usage with open(os.path.join(cmd_folder, "usage_counter.log"), "r") as f: counter = int(f.readline()) # check if counter is milestone if (counter + 1) % 25 == 0: self.addOutput( QgsProcessingOutputHtml("Message", "Area Weighted Average")) # check if new version is available of the plugin if (counter + 1) % 4 == 0: try: # try except because this is not a critical part avail_version = check_avail_plugin_version( "Area Weighted Average") if avail_version != curr_version and avail_version: upgradeMessage() except: pass
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterFeatureSource(self.INPUT, self.tr('Input layer'))) self.addParameter( QgsProcessingParameterEnum(self.PLOT_TYPE, self.tr('Plot type'), options=self.PLOT_TYPE_OPTIONS)) self.addParameter( QgsProcessingParameterString(self.PLOT_TITLE, self.tr('Plot title'), optional=True)) self.addParameter( QgsProcessingParameterField(self.XFIELD, self.tr('X Field'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Any, optional=True)) self.addParameter( QgsProcessingParameterField(self.YFIELD, self.tr('Y Field'), parentLayerParameterName=self.INPUT, type=QgsProcessingParameterField.Any, optional=True)) self.addParameter( QgsProcessingParameterEnum(self.IN_COLOR, self.tr('Color'), optional=True, options=self.IN_COLOR_OPTIONS)) self.addParameter( QgsProcessingParameterString( self.IN_COLOR_HTML, self. tr('Color (any valid HTML color) If set, this is used instead of the color set in the previous input.' ), optional=True)) self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT_HTML_FILE, self.tr('HTML File'), self.tr('HTML files (*.html)'))) # need to add an output for it to allow to see it in Processus results viewer self.addOutput( QgsProcessingOutputHtml( self.OUTPUT_HTML_FILE, self.tr('Dataplotly - Generic plot HTML output'))) # Add an file to return a response in JSON format self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT_JSON_FILE, self.tr('JSON file'), self.tr('JSON Files (*.json)'))) # need to add an output for it to allow to see it in Processus results viewer self.addOutput( QgsProcessingOutputFile( self.OUTPUT_JSON_FILE, self.tr('Dataplotly - Generic plot JSON output')))
def initAlgorithm(self, config=None): self.addParameter( QgsProcessingParameterVectorLayer( "areaboundary", "Area Boundary", types=[QgsProcessing.TypeVectorPolygon], defaultValue=None, )) param = QgsProcessingParameterFeatureSource( "cnlookup", "CN_Lookup.csv", optional=True, types=[QgsProcessing.TypeVector], defaultValue="", ) param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(param) param = QgsProcessingParameterBoolean( "drainedsoilsleaveuncheckedifnotsure", "Drained Soils? [leave unchecked if not sure]", defaultValue=False, ) param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced) self.addParameter(param) self.addParameter( QgsProcessingParameterBoolean( "OutputNLCDLandCoverRaster", "Output NLCD Land Cover Raster", defaultValue=False, )) self.addParameter( QgsProcessingParameterBoolean( "OutputNLCDLandCoverVector", "Output NLCD Land Cover Vector", defaultValue=False, )) self.addParameter( QgsProcessingParameterBoolean( "OutputNLCDImperviousRaster", "Output NLCD Impervious Surface Raster", defaultValue=False, )) self.addParameter( QgsProcessingParameterBoolean("OutputSoilLayer", "Output Soil Layer", defaultValue=False)) self.addParameter( QgsProcessingParameterBoolean( "OutputCurveNumberLayer", "Output Curve Number Layer", defaultValue=False, )) # read usage with open(os.path.join(cmd_folder, "usage_counter.log"), "r+") as f: counter = int(f.readline()) # check if counter is milestone if (counter + 1) % 25 == 0: self.addOutput( QgsProcessingOutputHtml("Message", "Curve Number Generator")) # check if new version is available of the plugin try: # try except because this is not a critical part avail_version = check_avail_plugin_version( "Curve Number Generator") if avail_version != curr_version: upgradeMessage() except: pass