Skip to content

Commit

Permalink
indentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 28, 2013
1 parent 84728d3 commit 7734cd3
Show file tree
Hide file tree
Showing 53 changed files with 413 additions and 409 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ def __init__(self):
self.alglist = [ImportVectorIntoGeoServer(), ImportRasterIntoGeoServer(),
CreateWorkspace(), DeleteWorkspace(), DeleteDatastore(),
CreateStyleGeoServer()]
try:

try:
self.alglist.append(ImportIntoPostGIS())
self.alglist.append(PostGISExecuteSQL())
except:
pass
pass

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
Expand Down
14 changes: 7 additions & 7 deletions python/plugins/sextante/algs/BarPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ class BarPlot(GeoAlgorithm):
INPUT = "INPUT"
OUTPUT = "OUTPUT"
NAME_FIELD = "NAME_FIELD"
VALUE_FIELD = "VALUE_FIELD"
VALUE_FIELD = "VALUE_FIELD"

def processAlgorithm(self, progress):
uri = self.getParameterValue(self.INPUT)
layer = QGisLayers.getObjectFromUri(uri)
namefieldname = self.getParameterValue(self.NAME_FIELD)
valuefieldname = self.getParameterValue(self.VALUE_FIELD)
valuefieldname = self.getParameterValue(self.VALUE_FIELD)
output = self.getOutputValue(self.OUTPUT)
values = vector.getAttributeValues(layer, namefieldname, valuefieldname)
plt.close()

ind = np.arange(len(values[namefieldname]))
width = 0.8
plt.bar(ind, values[valuefieldname], width, color='r')

plt.xticks(ind, values[namefieldname], rotation = 45)
plt.xticks(ind, values[namefieldname], rotation = 45)
plotFilename = output +".png"
lab.savefig(plotFilename)
lab.savefig(plotFilename)
f = open(output, "w")
f.write("<img src=\"" + plotFilename + "\"/>")
f.close()
Expand All @@ -66,8 +66,8 @@ def defineCharacteristics(self):
self.name = "Bar plot"
self.group = "Graphics"
self.addParameter(ParameterTable(self.INPUT, "Input table"))
self.addParameter(ParameterTableField(self.NAME_FIELD, "Category name field", self.INPUT))
self.addParameter(ParameterTableField(self.VALUE_FIELD, "Value field", self.INPUT))
self.addParameter(ParameterTableField(self.NAME_FIELD, "Category name field", self.INPUT))
self.addParameter(ParameterTableField(self.VALUE_FIELD, "Value field", self.INPUT))
self.addOutput(OutputHTML(self.OUTPUT, "Output"))


Expand Down
14 changes: 7 additions & 7 deletions python/plugins/sextante/algs/JoinAttributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def processAlgorithm(self, progress):
# Layer 2
layer2 = QGisLayers.getObjectFromUri(input2)
provider2 = layer2.dataProvider()

joinField2Index = layer2.fieldNameIndex(field2)

# Output
outFields = []
outFields.extend(provider.fields())
outFields.extend(provider2.fields())
outFields.extend(provider2.fields())

writer = output.getVectorWriter(outFields, provider.geometryType(), layer.crs())

Expand All @@ -83,17 +83,17 @@ def processAlgorithm(self, progress):
for inFeat in features:
inGeom = inFeat.geometry()
attrs = inFeat.attributes()
joinValue1 = attrs[joinField1Index].toString()
joinValue1 = attrs[joinField1Index].toString()
features2 = QGisLayers.features(layer2);
for inFeat2 in features2:
for inFeat2 in features2:
## Maybe it should cache this entries...
attrs2 = inFeat2.attributes()
joinValue2 = attrs2[joinField2Index].toString()
if joinValue1 == joinValue2:
# create the new feature
outFeat.setGeometry(inGeom)
attrs.extend(attrs2)
break;
outFeat.setGeometry(inGeom)
attrs.extend(attrs2)
break;
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)

Expand Down
12 changes: 6 additions & 6 deletions python/plugins/sextante/algs/MeanAndStdDevPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ def processAlgorithm(self, progress):
output = self.getOutputValue(self.OUTPUT)
values = vector.getAttributeValues(layer, namefieldname, meanfieldname, stddevfieldname)
plt.close()


ind = np.arange(len(values[namefieldname]))
width = 0.8
plt.bar(ind, values[meanfieldname], width,
color='r',
yerr=values[stddevfieldname],
error_kw=dict(ecolor='yellow'))

plt.xticks(ind, values[namefieldname], rotation = 45)
plt.xticks(ind, values[namefieldname], rotation = 45)
plotFilename = output +".png"
lab.savefig(plotFilename)
lab.savefig(plotFilename)
f = open(output, "w")
f.write("<img src=\"" + plotFilename + "\"/>")
f.close()
Expand All @@ -73,8 +73,8 @@ def defineCharacteristics(self):
self.name = "Mean and standard deviation plot"
self.group = "Graphics"
self.addParameter(ParameterTable(self.INPUT, "Input table"))
self.addParameter(ParameterTableField(self.NAME_FIELD, "Category name field", self.INPUT,ParameterTableField.DATA_TYPE_ANY))
self.addParameter(ParameterTableField(self.MEAN_FIELD, "Mean field", self.INPUT))
self.addParameter(ParameterTableField(self.NAME_FIELD, "Category name field", self.INPUT,ParameterTableField.DATA_TYPE_ANY))
self.addParameter(ParameterTableField(self.MEAN_FIELD, "Mean field", self.INPUT))
self.addParameter(ParameterTableField(self.STDDEV_FIELD, "StdDev field", self.INPUT))
self.addOutput(OutputHTML(self.OUTPUT, "Output"))

Expand Down
14 changes: 7 additions & 7 deletions python/plugins/sextante/algs/PolarPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ class PolarPlot(GeoAlgorithm):
INPUT = "INPUT"
OUTPUT = "OUTPUT"
NAME_FIELD = "NAME_FIELD"
VALUE_FIELD = "VALUE_FIELD"
VALUE_FIELD = "VALUE_FIELD"

def processAlgorithm(self, progress):
uri = self.getParameterValue(self.INPUT)
layer = QGisLayers.getObjectFromUri(uri)
namefieldname = self.getParameterValue(self.NAME_FIELD)
valuefieldname = self.getParameterValue(self.VALUE_FIELD)
valuefieldname = self.getParameterValue(self.VALUE_FIELD)
output = self.getOutputValue(self.OUTPUT)
values = vector.getAttributeValues(layer, namefieldname, valuefieldname)
plt.close()

fig = figure(figsize=(8,8))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
N = len(values[valuefieldname])
theta = np.arange(0.0, 2*np.pi, 2*np.pi/N)
radii = values[valuefieldname]
width = 2*np.pi/N
ax.bar(theta, radii, width=width, bottom=0.0)
ax.bar(theta, radii, width=width, bottom=0.0)
plotFilename = output +".png"
lab.savefig(plotFilename)
lab.savefig(plotFilename)
f = open(output, "w")
f.write("<img src=\"" + plotFilename + "\"/>")
f.close()
Expand All @@ -70,8 +70,8 @@ def defineCharacteristics(self):
self.name = "Polar plot"
self.group = "Graphics"
self.addParameter(ParameterTable(self.INPUT, "Input table"))
self.addParameter(ParameterTableField(self.NAME_FIELD, "Category name field", self.INPUT))
self.addParameter(ParameterTableField(self.VALUE_FIELD, "Value field", self.INPUT))
self.addParameter(ParameterTableField(self.NAME_FIELD, "Category name field", self.INPUT))
self.addParameter(ParameterTableField(self.VALUE_FIELD, "Value field", self.INPUT))
self.addOutput(OutputHTML(self.OUTPUT, "Output"))


Expand Down
12 changes: 6 additions & 6 deletions python/plugins/sextante/algs/RasterLayerHistogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,32 @@ class RasterLayerHistogram(GeoAlgorithm):

def processAlgorithm(self, progress):
uri = self.getParameterValue(self.INPUT)
layer = QGisLayers.getObjectFromUri(uri)
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()
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)
writer = outputtable.getTableWriter(fields)
for i in xrange(len(values)):
writer.addRecord([str(bins[i]) + "-" + str(bins[i+1]) , n[i]])
writer.addRecord([str(bins[i]) + "-" + str(bins[i+1]) , n[i]])
plotFilename = outputplot +".png"
lab.savefig(plotFilename)
lab.savefig(plotFilename)
f = open(outputplot, "w")
f.write("<img src=\"" + plotFilename + "\"/>")
f.close()

def defineCharacteristics(self):
self.name = "Raster layer histogram"
self.group = "Graphics"
self.addParameter(ParameterRaster(self.INPUT, "Input layer"))
self.addParameter(ParameterRaster(self.INPUT, "Input layer"))
self.addParameter(ParameterNumber(self.BINS, "Number of bins", 2, None, 10))
self.addOutput(OutputHTML(self.PLOT, "Output plot"))
self.addOutput(OutputTable(self.TABLE, "Output table"))
Expand Down
48 changes: 24 additions & 24 deletions python/plugins/sextante/algs/RasterLayerStatistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,34 @@

class RasterLayerStatistics(GeoAlgorithm):

INPUT = "INPUT"
INPUT = "INPUT"

MIN = "MIN"
MAX = "MAX"
SUM = "SUM"
MEAN = "MEAN"
COUNT = "COUNT"
NO_DATA_COUNT = "NO_DATA_COUNT"
NO_DATA_COUNT = "NO_DATA_COUNT"
STD_DEV = "STD_DEV"
OUTPUT_HTML_FILE = "OUTPUT_HTML_FILE"

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)
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
if v is not None:
sum += v
n = n + 1
delta = v - mean
mean = mean + delta/n
Expand All @@ -76,42 +76,42 @@ def processAlgorithm(self, progress):
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("No-data cells: " + unicode(nodata))
data.append("Minimum value: " + unicode(minvalue))
data.append("Maximum value: " + unicode(maxvalue))
data.append("Maximum value: " + unicode(maxvalue))
data.append("Sum: " + unicode(sum))
data.append("Mean value: " + unicode(mean))
data.append("Standard deviation: " + unicode(stddev))
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.MAX, maxvalue)
self.setOutputValue(self.SUM, sum)
self.setOutputValue(self.MEAN, mean)
self.setOutputValue(self.MEAN, mean)
self.setOutputValue(self.STD_DEV, stddev)


def defineCharacteristics(self):
self.name = "Raster layer statistics"
self.group = "Raster tools"
self.addParameter(ParameterRaster(self.INPUT, "Input layer"))
self.addOutput(OutputHTML(self.OUTPUT_HTML_FILE, "Statistics"))
self.addParameter(ParameterRaster(self.INPUT, "Input layer"))
self.addOutput(OutputHTML(self.OUTPUT_HTML_FILE, "Statistics"))
self.addOutput(OutputNumber(self.MIN, "Minimum value"))
self.addOutput(OutputNumber(self.MAX, "Maximum value"))
self.addOutput(OutputNumber(self.SUM, "Sum"))
self.addOutput(OutputNumber(self.MEAN, "Mean value"))
self.addOutput(OutputNumber(self.COUNT, "valid cells count"))
self.addOutput(OutputNumber(self.COUNT, "No-data cells count"))
self.addOutput(OutputNumber(self.STD_DEV, "Standard deviation"))
self.addOutput(OutputNumber(self.COUNT, "No-data cells count"))
self.addOutput(OutputNumber(self.STD_DEV, "Standard deviation"))

def createHTML(self, outputFile, algData):
f = open(outputFile, "w")
Expand Down

0 comments on commit 7734cd3

Please sign in to comment.