Showing with 593 additions and 227 deletions.
  1. +3 −6 python/plugins/sextante/ftools/DensifyGeometries.py
  2. +156 −0 python/plugins/sextante/ftools/DensifyGeometriesInterval.py
  3. +2 −0 python/plugins/sextante/grass/CMakeLists.txt
  4. +26 −18 python/plugins/sextante/grass/GrassAlgorithm.py
  5. +3 −3 python/plugins/sextante/grass/GrassUtils.py
  6. +4 −4 python/plugins/sextante/grass/description/r.average.txt
  7. +4 −4 python/plugins/sextante/grass/description/r.basins.fill.txt
  8. +2 −2 python/plugins/sextante/grass/description/r.bilinear.txt
  9. +2 −2 python/plugins/sextante/grass/description/r.bitpattern.txt
  10. +2 −2 python/plugins/sextante/grass/description/r.buffer.txt
  11. +4 −4 python/plugins/sextante/grass/description/r.carve.txt
  12. +2 −2 python/plugins/sextante/grass/description/r.clump.txt
  13. +1 −0 python/plugins/sextante/grass/description/r.coin.txt
  14. +4 −7 python/plugins/sextante/grass/description/r.composite.txt
  15. +3 −2 python/plugins/sextante/grass/description/r.contour.level.txt
  16. +3 −2 python/plugins/sextante/grass/description/r.contour.step.txt
  17. +0 −11 python/plugins/sextante/grass/description/r.contour.txt
  18. +6 −6 python/plugins/sextante/grass/description/r.cost.txt
  19. +3 −2 python/plugins/sextante/grass/description/r.covar.txt
  20. +1 −1 python/plugins/sextante/grass/description/v.buffer.column.txt
  21. +1 −1 python/plugins/sextante/grass/description/v.buffer.distance.txt
  22. +1 −0 python/plugins/sextante/grass/description/v.class.txt
  23. +3 −3 python/plugins/sextante/grass/description/v.clean.txt
  24. +2 −2 python/plugins/sextante/grass/description/v.db.select.txt
  25. +1 −1 python/plugins/sextante/grass/description/v.delaunay.txt
  26. +2 −2 python/plugins/sextante/grass/description/v.dissolve.txt
  27. +3 −3 python/plugins/sextante/grass/description/v.distance.toattr.txt
  28. +3 −3 python/plugins/sextante/grass/description/v.distance.txt
  29. +2 −2 python/plugins/sextante/grass/description/v.drape.txt
  30. +3 −3 python/plugins/sextante/grass/description/v.extract.txt
  31. +0 −12 python/plugins/sextante/grass/description/v.extrude.txt
  32. +2 −2 python/plugins/sextante/grass/description/v.generalize.txt
  33. +2 −2 python/plugins/sextante/grass/description/v.hull.txt
  34. +1 −0 python/plugins/sextante/grass/description/v.info.txt
  35. +2 −2 python/plugins/sextante/grass/description/v.kcv.txt
  36. +3 −3 python/plugins/sextante/grass/description/v.lidar.correction.txt
  37. +2 −2 python/plugins/sextante/grass/description/v.lidar.edgedetection.txt
  38. +3 −3 python/plugins/sextante/grass/description/v.lidar.growing.txt
  39. +3 −3 python/plugins/sextante/grass/description/v.mkgrid.txt
  40. +2 −2 python/plugins/sextante/grass/description/v.neighbors.txt
  41. +1 −0 python/plugins/sextante/grass/description/v.normal.txt
  42. +3 −3 python/plugins/sextante/grass/description/v.outlier.txt
  43. +3 −3 python/plugins/sextante/grass/description/v.overlay.txt
  44. +2 −2 python/plugins/sextante/grass/description/v.parallel.txt
  45. +2 −2 python/plugins/sextante/grass/description/v.patch.txt
  46. +1 −1 python/plugins/sextante/grass/description/v.perturb.txt
  47. +4 −4 python/plugins/sextante/grass/description/v.qcount.txt
  48. +1 −2 python/plugins/sextante/grass/description/v.random.txt
  49. +0 −10 python/plugins/sextante/grass/description/v.rast.stats.txt
  50. +3 −3 python/plugins/sextante/grass/description/v.reclass.txt
  51. +2 −1 python/plugins/sextante/grass/description/v.report.txt
  52. +4 −4 python/plugins/sextante/grass/description/v.sample.txt
  53. +3 −3 python/plugins/sextante/grass/description/v.segment.txt
  54. +0 −7 python/plugins/sextante/grass/description/v.select.txt
  55. +2 −2 python/plugins/sextante/grass/description/v.split.txt
  56. +4 −5 python/plugins/sextante/grass/description/v.surf.bspline.txt
  57. +2 −3 python/plugins/sextante/grass/description/v.surf.idw.txt
  58. +2 −2 python/plugins/sextante/grass/description/v.surf.rst.cvdev.txt
  59. +7 −7 python/plugins/sextante/grass/description/v.surf.rst.txt
  60. +0 −10 python/plugins/sextante/grass/description/v.to.3d.txt
  61. +2 −3 python/plugins/sextante/grass/description/v.to.points.txt
  62. +3 −3 python/plugins/sextante/grass/description/v.to.rast.attribute.txt
  63. +3 −3 python/plugins/sextante/grass/description/v.to.rast.value.txt
  64. +2 −3 python/plugins/sextante/grass/description/v.transform.txt
  65. +1 −1 python/plugins/sextante/grass/description/v.univar.txt
  66. +3 −3 python/plugins/sextante/grass/description/v.voronoi.txt
  67. 0 python/plugins/sextante/grass/postproc/__init__.py
  68. +36 −0 python/plugins/sextante/grass/postproc/r_coin.py
  69. +36 −0 python/plugins/sextante/grass/postproc/r_covar.py
  70. +36 −0 python/plugins/sextante/grass/postproc/v_class.py
  71. +36 −0 python/plugins/sextante/grass/postproc/v_info.py
  72. +36 −0 python/plugins/sextante/grass/postproc/v_normal.py
  73. +36 −0 python/plugins/sextante/grass/postproc/v_report.py
  74. +36 −0 python/plugins/sextante/grass/postproc/v_univar.py
  75. +2 −2 python/plugins/sextante/gui/AlgorithmExecutionDialog.py
  76. +1 −1 python/plugins/sextante/gui/ParametersPanel.py
  77. +6 −5 python/plugins/sextante/parameters/ParameterNumber.py
9 changes: 3 additions & 6 deletions python/plugins/sextante/ftools/DensifyGeometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os.path

from PyQt4 import QtGui
from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers
from sextante.core.SextanteLog import SextanteLog

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterNumber import ParameterNumber
Expand Down Expand Up @@ -63,8 +60,7 @@ def defineCharacteristics(self):
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
useSelection = self.getParameterValue(self.USE_SELECTION)
vertices =self.getParameterValue(self.VERTICES)
output = self.getOutputValue(self.OUTPUT)
vertices =self.getParameterValue(self.VERTICES)

isPolygon = layer.geometryType() == QGis.Polygon

Expand All @@ -76,7 +72,8 @@ def processAlgorithm(self, progress):

current = 0
if useSelection:
total = 100.0 / float(len(layer.selectedFeatures()))
selection = layer.selectedFeatures()
total = 100.0 / float(len(selection))
for f in selection:
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributeMap()
Expand Down
156 changes: 156 additions & 0 deletions python/plugins/sextante/ftools/DensifyGeometriesInterval.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
DensifyGeometriesInterval.py by Anita Graser, Dec 2012
based on
DensifyGeometries.py
---------------------
Date : October 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Anita Graser'
__date__ = 'Dec 2012'
__copyright__ = '(C) 2012, Anita Graser'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from math import sqrt

from PyQt4.QtCore import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.QGisLayers import QGisLayers

from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.parameters.ParameterBoolean import ParameterBoolean

from sextante.outputs.OutputVector import OutputVector

class DensifyGeometriesInterval(GeoAlgorithm):

INPUT = "INPUT"
#VERTICES = "VERTICES"
INTERVAL = "INTERVAL"
USE_SELECTION = "USE_SELECTION"
OUTPUT = "OUTPUT"

def defineCharacteristics(self):
self.name = "Densify geometries given an interval"
self.group = "Geometry tools"

self.addParameter(ParameterVector(self.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
#self.addParameter(ParameterNumber(self.VERTICES, "Vertices to add", 1, 10000000, 1))
self.addParameter(ParameterNumber(self.INTERVAL, "Interval between Vertices to add", 1, 10000000, 1))
self.addParameter(ParameterBoolean(self.USE_SELECTION, "Use only selected features", False))

self.addOutput(OutputVector(self.OUTPUT, "Simplified layer"))

def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
useSelection = self.getParameterValue(self.USE_SELECTION)
interval =self.getParameterValue(self.INTERVAL)

isPolygon = layer.geometryType() == QGis.Polygon

provider = layer.dataProvider()
layer.select(layer.pendingAllAttributesList())

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
layer.wkbType(), provider.crs())

current = 0
if useSelection:
selection = layer.selectedFeatures()
total = 100.0 / float(len(selection))
for f in selection:
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributeMap()
newGeometry = self.densifyGeometry(featGeometry, interval, isPolygon)

feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributeMap(attrMap)
writer.addFeature(feature)

current += 1
progress.setPercentage(int(current * total))
else:
total = 100.0 / float(provider.featureCount())
f = QgsFeature()
while layer.nextFeature(f):
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributeMap()
newGeometry = self.densifyGeometry(featGeometry, interval, isPolygon)

feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributeMap(attrMap)
writer.addFeature(feature)

current += 1
progress.setPercentage(int(current * total))

del writer

def densifyGeometry(self, geometry, interval, isPolygon):
output = []
if isPolygon:
if geometry.isMultipart():
polygons = geometry.asMultiPolygon()
for poly in polygons:
p = []
for ring in poly:
p.append(self.densify(ring, interval))
output.append(p)
return QgsGeometry.fromMultiPolygon(output)
else:
rings = geometry.asPolygon()
for ring in rings:
output.append(self.densify(ring, interval))
return QgsGeometry.fromPolygon(output)
else:
if geometry.isMultipart():
lines = geometry.asMultiPolyline()
for points in lines:
output.append(self.densify(points, interval))
return QgsGeometry.fromMultiPolyline(output)
else:
points = geometry.asPolyline()
output = self.densify(points, interval)
return QgsGeometry.fromPolyline(output)

def densify(self, polyline, interval):
output = []
for i in xrange(len(polyline) - 1):
p1 = polyline[i]
p2 = polyline[i + 1]
output.append(p1)
# calculate necessary number of points between p1 and p2
pointsNumber = sqrt(p1.sqrDist(p2)) / interval
if pointsNumber > 1:
multiplier = 1.0 / float(pointsNumber)
else:
multiplier = 1
for j in xrange(int(pointsNumber)):
delta = multiplier * (j + 1)
x = p1.x() + delta * (p2.x() - p1.x())
y = p1.y() + delta * (p2.y() - p1.y())
output.append(QgsPoint( x, y ))
if j + 1 == pointsNumber:
break
output.append(polyline[len(polyline) - 1])
return output
2 changes: 2 additions & 0 deletions python/plugins/sextante/grass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ FILE(GLOB PY_FILES *.py)
FILE(GLOB OTHER_FILES grass.txt)
FILE(GLOB DESCR_FILES description/*.txt)

ADD_SUBDIRECTORY(postproc)

PLUGIN_INSTALL(sextante grass ${PY_FILES} ${OTHER_FILES})
PLUGIN_INSTALL(sextante grass/description ${DESCR_FILES})
44 changes: 26 additions & 18 deletions python/plugins/sextante/grass/GrassAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* *
***************************************************************************
"""
import uuid

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -28,6 +26,9 @@
from qgis.core import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import uuid
from sextante.outputs.OutputHTML import OutputHTML
import importlib
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.parameters.ParameterTable import ParameterTable
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput
Expand Down Expand Up @@ -116,6 +117,7 @@ def defineCharacteristicsFromFile(self):
self.name = line
line = lines.readline().strip("\n").strip()
self.group = line
hasRasterOutput = False
while line != "":
try:
line = line.strip("\n").strip()
Expand All @@ -126,15 +128,19 @@ def defineCharacteristicsFromFile(self):
param.isAdvanced = True
self.addParameter(param)
else:
self.addOutput(OutputFactory.getFromString(line))
output = OutputFactory.getFromString(line)
self.addOutput(output);
if isinstance(output, OutputRaster):
hasRasterOutput = True
line = lines.readline().strip("\n").strip()
except Exception,e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open GRASS algorithm: " + self.descriptionFile + "\n" + line)
raise e
lines.close()

self.addParameter(ParameterExtent(self.GRASS_REGION_EXTENT_PARAMETER, "GRASS region extent"))
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER, "GRASS region cellsize (leave 0 for default)", 0, None, 0.0))
if hasRasterOutput:
self.addParameter(ParameterNumber(self.GRASS_REGION_CELLSIZE_PARAMETER, "GRASS region cellsize (leave 0 for default)", 0, None, 0.0))


def getDefaultCellsize(self):
Expand Down Expand Up @@ -230,10 +236,12 @@ def processAlgorithm(self, progress):
command +=" s=" + str(regionCoords[2])
command +=" e=" + str(regionCoords[1])
command +=" w=" + str(regionCoords[0])
if self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER) == 0:
command +=" res=" + str(self.getDefaultCellsize())
cellsize = self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER)
if cellsize:
command +=" res=" + str(cellsize);
else:
command +=" res=" + str(self.getParameterValue(self.GRASS_REGION_CELLSIZE_PARAMETER));
command +=" res=" + str(self.getDefaultCellsize())

commands.append(command)

#2: set parameters and outputs
Expand Down Expand Up @@ -268,7 +276,7 @@ def processAlgorithm(self, progress):
for out in self.outputs:
if isinstance(out, OutputFile):
command+=(" " + out.name + "=\"" + out.value + "\"");
else:
elif not isinstance(out, OutputHTML): #html files are not generated by grass, only by sextante to decorate grass output
#an output name to make sure it is unique if the session uses this algorithm several times
uniqueOutputName = out.name + uniqueSufix
command += (" " + out.name + "=" + uniqueOutputName)
Expand Down Expand Up @@ -310,24 +318,24 @@ def processAlgorithm(self, progress):
progress.setCommand(line)
loglines.append(line)
if SextanteConfig.getSetting(GrassUtils.GRASS_LOG_COMMANDS):
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
self.consoleOutput = GrassUtils.executeGrass(commands, progress, outputCommands);
self.postProcessResults();
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
self.consoleOutput = GrassUtils.executeGrass(commands, progress, outputCommands);
self.postProcessResults();
# if the session has been created outside of this algorithm, add the new GRASS layers to it
# otherwise finish the session
if existingSession:
GrassUtils.addSessionLayers(self.exportedLayers)
else:
GrassUtils.endGrassSession()

def postProcessResults(self):
name = self.commandLineName().replace('.','_')
try:
module = __import__ ('sextante.grass.postproc.' + name)
except ImportError:
def postProcessResults(self):
name = self.commandLineName().replace('.','_')[len('grass:'):]
try:
module = importlib.import_module('sextante.grass.postproc.' + name)
except ImportError:
return
if hasattr(module, 'postProcessResults'):
func = getattr(module,'postProcessResults')
if hasattr(module, 'postProcessResults'):
func = getattr(module,'postProcessResults')
func(self)

def exportVectorLayer(self, orgFilename):
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/sextante/grass/GrassUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def createGrassScript(commands):
#gisdbase = os.path.join(os.path.expanduser("~"), "sextante", "tempdata", "grassdata")
output.write("GISDBASE: " + gisdbase + "\n");
output.write("LOCATION_NAME: " + location + "\n");
output.write("MAPSET: PERMAMENT \n");
output.write("MAPSET: PERMANENT \n");
output.write("GRASS_GUI: text\n");
output.close()

Expand Down Expand Up @@ -248,9 +248,9 @@ def prepareGrassExecution(commands):
GrassUtils.createGrassBatchJobFileFromGrassCommands(commands)
os.chmod(GrassUtils.grassBatchJobFilename(), stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE)
if SextanteUtils.isMac():
command = GrassUtils.grassPath() + os.sep + "grass.sh " + GrassUtils.grassMapsetFolder() + "/user"
command = GrassUtils.grassPath() + os.sep + "grass.sh " + GrassUtils.grassMapsetFolder() + "/PERMANENT"
else:
command = "grass64 " + GrassUtils.grassMapsetFolder() + "/user"
command = "grass64 " + GrassUtils.grassMapsetFolder() + "/PERMANENT"

return command

Expand Down
8 changes: 4 additions & 4 deletions python/plugins/sextante/grass/description/r.average.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
r.average
r.average - Finds the average of values in a cover map within areas assigned the same category value in a user-specified base map.
r.average - Finds the average of values in a cover raster layer within areas assigned the same category value in a user-specified base layer.
Raster (r.*)
ParameterRaster|base|Name of base raster map|False
ParameterRaster|cover|Name of cover raster map|False
ParameterRaster|base|Base raster layer|False
ParameterRaster|cover|Cover raster layer|False
ParameterBoolean|-c|Cover values extracted from the category labels of the cover map|False
OutputRaster|output|Name for output raster map
OutputRaster|output|Average values
8 changes: 4 additions & 4 deletions python/plugins/sextante/grass/description/r.basins.fill.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
r.basins.fill
r.basins.fill - Generates watershed subbasins raster map.
Raster (r.*)
ParameterRaster|c_map|Name of input coded stream network raster map|False
ParameterRaster|t_map|Name of input thinned ridge network raster map|False
ParameterNumber|number|Number of passes through the dataset|None|None|0.0
OutputRaster|result|Name for output raster map
ParameterRaster|c_map|Input coded stream network raster layer|False
ParameterRaster|t_map|Input thinned ridge network raster layer|False
ParameterNumber|number|Number of passes through the dataset|None|None|1
OutputRaster|result|Watersheds
4 changes: 2 additions & 2 deletions python/plugins/sextante/grass/description/r.bilinear.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
r.bilinear
r.bilinear - Bilinear interpolation utility for raster map layers.
Raster (r.*)
ParameterRaster|input|Name of input raster map|False
ParameterRaster|input|Input raster layer|False
ParameterNumber|north|Specific input value to be assigned to the north and/or south poles for longitude-latitude grids|None|None|0
ParameterNumber|east|Specific input value to be assigned to the north and/or south poles for longitude-latitude grids|None|None|0
OutputRaster|output|Name for output raster map
OutputRaster|output|Output raster layer
4 changes: 2 additions & 2 deletions python/plugins/sextante/grass/description/r.bitpattern.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
r.bitpattern
r.bitpattern - Compares bit patterns with a raster map.
Raster (r.*)
ParameterRaster|input|Name of input raster map|False
ParameterRaster|input|Input raster layer|False
ParameterString|pattern|Bit pattern position(s)|
ParameterString|patval|Bit pattern value|
OutputRaster|output|Name for output raster map
OutputRaster|output|Output raster layer
4 changes: 2 additions & 2 deletions python/plugins/sextante/grass/description/r.buffer.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
r.buffer
r.buffer - Creates a raster map layer showing buffer zones surrounding cells that contain non-NULL category values.
Raster (r.*)
ParameterRaster|input|Name of input raster map|False
ParameterRaster|input|Input raster layer|False
ParameterString|distances|Distance zone(s) (e.g. 100,200,300)|
ParameterSelection|units|Units of distance|meters;kilometers;feet;miles;nautmiles
ParameterBoolean|-z|Ignore zero (0) data cells instead of NULL cells|False
OutputRaster|output|Name for output raster map
OutputRaster|output|Buffer
Loading