Пример #1
0
    def processAlgorithm(self, progress):
        layer = dataobjects.getObjectFromUri(
            self.getParameterValue(self.INPUT))
        nbins = self.getParameterValue(self.BINS)

        outputplot = self.getOutputValue(self.PLOT)
        outputtable = self.getOutputFromName(self.TABLE)

        values = raster.scanraster(layer, progress)

        # ALERT: this is potentially blocking if the layer is too big
        plt.close()
        valueslist = []
        for v in values:
            if v is not None:
                valueslist.append(v)
        (n, bins, values) = plt.hist(valueslist, nbins)

        fields = [QgsField('CENTER_VALUE', QVariant.Double),
                  QgsField('NUM_ELEM', QVariant.Double)]
        writer = outputtable.getTableWriter(fields)
        for i in range(len(values)):
            writer.addRecord([str(bins[i]) + '-' + str(bins[i + 1]), n[i]])

        plotFilename = outputplot + '.png'
        lab.savefig(plotFilename)
        with open(outputplot, 'w') as f:
            f.write('<html><img src="' + plotFilename + '"/></html>')
Пример #2
0
    def processAlgorithm(self, progress):
        outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
        uri = self.getParameterValue(self.INPUT)
        layer = dataobjects.getObjectFromUri(uri)
        values = raster.scanraster(layer, progress)

        n = 0
        nodata = 0
        mean = 0
        M2 = 0
        sum = 0
        minvalue = None
        maxvalue = None

        for v in values:
            if v is not None:
                sum += v
                n = n + 1
                delta = v - mean
                mean = mean + delta / n
                M2 = M2 + delta * (v - mean)
                if minvalue is None:
                    minvalue = v
                    maxvalue = v
                else:
                    minvalue = min(v, minvalue)
                    maxvalue = max(v, maxvalue)
            else:
                nodata += 1

        variance = M2 / (n - 1)
        stddev = math.sqrt(variance)

        data = []
        data.append('Valid cells: ' + unicode(n))
        data.append('No-data cells: ' + unicode(nodata))
        data.append('Minimum value: ' + unicode(minvalue))
        data.append('Maximum value: ' + unicode(maxvalue))
        data.append('Sum: ' + unicode(sum))
        data.append('Mean value: ' + unicode(mean))
        data.append('Standard deviation: ' + unicode(stddev))

        self.createHTML(outputFile, data)

        self.setOutputValue(self.COUNT, n)
        self.setOutputValue(self.NO_DATA_COUNT, nodata)
        self.setOutputValue(self.MIN, minvalue)
        self.setOutputValue(self.MAX, maxvalue)
        self.setOutputValue(self.SUM, sum)
        self.setOutputValue(self.MEAN, mean)
        self.setOutputValue(self.STD_DEV, stddev)
Пример #3
0
    def processAlgorithm(self, parameters, context, feedback):
        outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
        uri = self.getParameterValue(self.INPUT)
        layer = QgsProcessingUtils.mapLayerFromString(uri, context)
        values = raster.scanraster(layer, feedback)

        n = 0
        nodata = 0
        mean = 0
        M2 = 0
        sum = 0
        minvalue = None
        maxvalue = None

        for v in values:
            if v is not None:
                sum += v
                n = n + 1
                delta = v - mean
                mean = mean + delta / n
                M2 = M2 + delta * (v - mean)
                if minvalue is None:
                    minvalue = v
                    maxvalue = v
                else:
                    minvalue = min(v, minvalue)
                    maxvalue = max(v, maxvalue)
            else:
                nodata += 1

        variance = M2 / (n - 1)
        stddev = math.sqrt(variance)

        data = []
        data.append('Valid cells: ' + str(n))
        data.append('No-data cells: ' + str(nodata))
        data.append('Minimum value: ' + str(minvalue))
        data.append('Maximum value: ' + str(maxvalue))
        data.append('Sum: ' + str(sum))
        data.append('Mean value: ' + str(mean))
        data.append('Standard deviation: ' + str(stddev))

        self.createHTML(outputFile, data)

        self.setOutputValue(self.COUNT, n)
        self.setOutputValue(self.NO_DATA_COUNT, nodata)
        self.setOutputValue(self.MIN, minvalue)
        self.setOutputValue(self.MAX, maxvalue)
        self.setOutputValue(self.SUM, sum)
        self.setOutputValue(self.MEAN, mean)
        self.setOutputValue(self.STD_DEV, stddev)
Пример #4
0
    def processAlgorithm(self, progress):
        outputFile = self.getOutputValue(self.OUTPUT_HTML_FILE)
        uri = self.getParameterValue(self.INPUT)
        layer = QGisLayers.getObjectFromUri(uri)
        values = raster.scanraster(layer, progress)

        n = 0
        nodata = 0
        mean = 0
        M2 = 0
        sum = 0
        minvalue = None
        maxvalue = None

        for v in values:
            if v is not None:
                sum += v
                n = n + 1
                delta = v - mean
                mean = mean + delta / n
                M2 = M2 + delta * (v - mean)
                if minvalue is None:
                    minvalue = v
                    maxvalue = v
                else:
                    minvalue = min(v, minvalue)
                    maxvalue = max(v, maxvalue)
            else:
                nodata += 1

        variance = M2 / (n - 1)
        stddev = math.sqrt(variance)

        data = []
        data.append("Valid cells: " + unicode(n))
        data.append("No-data cells: " + unicode(nodata))
        data.append("Minimum value: " + unicode(minvalue))
        data.append("Maximum value: " + unicode(maxvalue))
        data.append("Sum: " + unicode(sum))
        data.append("Mean value: " + unicode(mean))
        data.append("Standard deviation: " + unicode(stddev))

        self.createHTML(outputFile, data)

        self.setOutputValue(self.COUNT, n)
        self.setOutputValue(self.NO_DATA_COUNT, nodata)
        self.setOutputValue(self.MIN, minvalue)
        self.setOutputValue(self.MAX, maxvalue)
        self.setOutputValue(self.SUM, sum)
        self.setOutputValue(self.MEAN, mean)
        self.setOutputValue(self.STD_DEV, stddev)
Пример #5
0
    def processAlgorithm(self, feedback):
        layer = dataobjects.getObjectFromUri(self.getParameterValue(
            self.INPUT))
        nbins = self.getParameterValue(self.BINS)

        output = self.getOutputValue(self.PLOT)

        # ALERT: this is potentially blocking if the layer is too big
        values = raster.scanraster(layer, feedback)

        valueslist = []
        for v in values:
            if v is not None:
                valueslist.append(v)

        data = [go.Histogram(x=valueslist, nbinsx=nbins)]
        plt.offline.plot(data, filename=output, auto_open=False)
Пример #6
0
    def processAlgorithm(self, parameters, context, feedback):
        layer = QgsProcessingUtils.mapLayerFromString(self.getParameterValue(self.INPUT), context)
        nbins = self.getParameterValue(self.BINS)

        output = self.getOutputValue(self.PLOT)

        # ALERT: this is potentially blocking if the layer is too big
        values = raster.scanraster(layer, feedback)

        valueslist = []
        for v in values:
            if v is not None:
                valueslist.append(v)

        data = [go.Histogram(x=valueslist,
                             nbinsx=nbins)]
        plt.offline.plot(data, filename=output, auto_open=False)
Пример #7
0
    def processAlgorithm(self, parameters, context, feedback):
        layer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        band = self.parameterAsInt(parameters, self.BAND, context)
        nbins = self.parameterAsInt(parameters, self.BINS, context)

        output = self.parameterAsFileOutput(parameters, self.OUTPUT, context)

        # ALERT: this is potentially blocking if the layer is too big
        values = raster.scanraster(layer, feedback, band)

        valueslist = []
        for v in values:
            if v is not None:
                valueslist.append(v)

        data = [go.Histogram(x=valueslist, nbinsx=nbins)]
        plt.offline.plot(data, filename=output, auto_open=False)

        return {self.OUTPUT: output}
Пример #8
0
    def processAlgorithm(self, parameters, context, feedback):
        layer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
        band = self.parameterAsInt(parameters, self.BAND, context)
        nbins = self.parameterAsInt(parameters, self.BINS, context)

        output = self.parameterAsFileOutput(parameters, self.OUTPUT, context)

        # ALERT: this is potentially blocking if the layer is too big
        values = raster.scanraster(layer, feedback, band)

        valueslist = []
        for v in values:
            if v is not None:
                valueslist.append(v)

        data = [go.Histogram(x=valueslist,
                             nbinsx=nbins)]
        plt.offline.plot(data, filename=output, auto_open=False)

        return {self.OUTPUT: output}
Пример #9
0
 def processAlgorithm(self, progress):
     uri = self.getParameterValue(self.INPUT)
     layer = QGisLayers.getObjectFromUri(uri)
     outputplot = self.getOutputValue(self.PLOT)
     outputtable = self.getOutputFromName(self.TABLE)
     values = raster.scanraster(layer, progress)
     nbins = self.getParameterValue(self.BINS)
     #ALERT:this is potentially blocking if the layer is too big
     plt.close()
     valueslist = []
     for v in values:
         if v is not None:
             valueslist.append(v)
     n, bins, values = plt.hist(valueslist, nbins)
     fields = [QgsField("CENTER_VALUE", QVariant.Double), QgsField("NUM_ELEM", QVariant.Double)]
     writer = outputtable.getTableWriter(fields)
     for i in xrange(len(values)):
         writer.addRecord([str(bins[i]) + "-" + str(bins[i+1]) , n[i]])
     plotFilename = outputplot +".png"
     lab.savefig(plotFilename)
     f = open(outputplot, "w")
     f.write("<img src=\"" + plotFilename + "\"/>")
     f.close()