Skip to content
Permalink
Browse files

updated remaining ftools algorithms to new architecture

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@348 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf
volayaf committed Aug 15, 2012
1 parent 0a29cc0 commit 8c42295ae42de4828cb27f925bf696c34722b641
@@ -4,9 +4,7 @@
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.core.SextanteLog import SextanteLog

def buffering(progress, output, distance, field, useSelection, useField, layer, dissolve, segments ):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
def buffering(progress, writer, distance, field, useSelection, useField, layer, dissolve, segments ):
GEOS_EXCEPT = True
FEATURE_EXCEPT = True
vproviderA = layer.dataProvider()
@@ -15,10 +13,6 @@ def buffering(progress, output, distance, field, useSelection, useField, layer,
fields = vproviderA.fields()
if useField:
field = vproviderA.fieldNameIndex(field)
writer = QgsVectorFileWriter(output, systemEncoding, fields, QGis.WKBPolygon, vproviderA.crs() )
# check if writer was created properly, if not, return with error
if writer.hasError():
raise GeoAlgorithmExecutionException("Could not create output file");
outFeat = QgsFeature()
inFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -64,9 +58,9 @@ def buffering(progress, output, distance, field, useSelection, useField, layer,
for inFeat in selectionA:
atMap = inFeat.attributeMap()
if useField:
value = atMap[ self.myParam ].toDouble()[ 0 ]
value = atMap[ field ].toDouble()[ 0 ]
else:
value = self.myParam
value = distance
inGeom = QgsGeometry( inFeat.geometry() )
try:
outGeom = inGeom.buffer( float( value ), segments )
@@ -28,14 +28,9 @@ def defineCharacteristics(self):
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(Centroids.INPUT_LAYER))

outFileName = self.getOutputValue(Centroids.OUTPUT_LAYER)

provider = layer.dataProvider()

settings = QSettings()
encoding = settings.value( "/UI/encoding", "System" ).toString()

writer = QgsVectorFileWriter(outFileName, encoding, provider.fields(),
writer = self.getOutputFromName(Centroids.OUTPUT_LAYER).getVectorWriter(provider.fields(),
QGis.WKBPoint, provider.crs())

allAttrs = provider.attributeIndexes()
@@ -19,9 +19,6 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/delaunay.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(Delaunay.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(Delaunay.INPUT))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
@@ -30,7 +27,7 @@ def processAlgorithm(self, progress):
0 : QgsField( "POINTA", QVariant.Double ),
1 : QgsField( "POINTB", QVariant.Double ),
2 : QgsField( "POINTC", QVariant.Double ) }
writer = QgsVectorFileWriter( output, systemEncoding, fields, QGis.WKBPolygon, vprovider.crs() )
writer = self.getOutputFromName(Delaunay.OUTPUT).getVectorWriter(fields, QGis.WKBPolygon, vprovider.crs() )
inFeat = QgsFeature()
c = voronoi.Context()
pts = []
@@ -24,9 +24,6 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/difference.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(Difference.OUTPUT)
useSelection = self.getParameterValue(Difference.USE_SELECTED)
useSelection2 = self.getParameterValue(Difference.USE_SELECTED2)
vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Difference.INPUT))
@@ -48,7 +45,7 @@ def processAlgorithm(self, progress):
else:
if not crsA != crsB:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Difference. Non-matching CRSs. Results might be unexpected")
writer = QgsVectorFileWriter(output, systemEncoding, fields, vproviderA.geometryType(), vproviderA.crs() )
writer = self.getOutputFromName(Difference.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
inFeatA = QgsFeature()
inFeatB = QgsFeature()
outFeat = QgsFeature()
@@ -24,9 +24,6 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/dissolve.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(Dissolve.OUTPUT)
useSelection = self.getParameterValue(Dissolve.USE_SELECTED)
useField = not self.getParameterValue(Dissolve.USE_SELECTED)
fieldname = self.getParameterValue(Dissolve.FIELD)
@@ -37,7 +34,7 @@ def processAlgorithm(self, progress):
vproviderA = vlayerA.dataProvider()
allAttrsA = vproviderA.attributeIndexes()
fields = vproviderA.fields()
writer = QgsVectorFileWriter( output, systemEncoding, fields, vproviderA.geometryType(), vproviderA.crs() )
writer = self.getOutputFromName(Dissolve.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
if writer.hasError():
raise GeoAlgorithmExecutionException("Could not create output file");
inFeat = QgsFeature()
@@ -17,15 +17,12 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/export_geometry.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(ExportGeometryInfo.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(ExportGeometryInfo.INPUT))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
( fields, index1, index2 ) = self.checkGeometryFields(vlayer)
writer = QgsVectorFileWriter( output, systemEncoding,fields, vprovider.geometryType(), vprovider.crs() )
writer = self.getOutputFromName(ExportGeometryInfo.OUTPUT).getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -17,9 +17,6 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/layer_extent.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(ExtentFromLayer.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(ExtentFromLayer.INPUT))
fields = {
0 : QgsField( "MINX", QVariant.Double ),
@@ -33,7 +30,7 @@ def processAlgorithm(self, progress):
8 : QgsField( "HEIGHT", QVariant.Double ),
9 : QgsField( "WIDTH", QVariant.Double ) }

writer = QgsVectorFileWriter(output, systemEncoding, fields, QGis.WKBPolygon, vlayer.crs() )
writer = self.getOutputFromName(ExtentFromLayer.OUTPUT).getVectorWriter(fields, QGis.WKBPolygon, vlayer.crs() )
rect = vlayer.extent()
minx = rect.xMinimum()
miny = rect.yMinimum()
@@ -18,15 +18,12 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/extract_nodes.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(ExtractNodes.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(ExtractNodes.INPUT))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
writer = QgsVectorFileWriter( output, systemEncoding, fields, QGis.WKBPoint, vprovider.crs() )
writer = self.getOutputFromName(ExtractNodes.OUTPUT).getVectorWriter(fields, QGis.WKBPoint, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -25,13 +25,17 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/buffer.png")

def processAlgorithm(self, progress):
output = self.getOutputValue(FixedDistanceBuffer.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(FixedDistanceBuffer.INPUT))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select(allAttrs)
writer = self.getOutputFromName(FixedDistanceBuffer.OUTPUT).getVectorWriter(vprovider.fields(), QGis.WKBPolygon, vprovider.crs() )
useSelection = self.getParameterValue(FixedDistanceBuffer.USE_SELECTED)
distance = self.getParameterValue(FixedDistanceBuffer.DISTANCE)
dissolve = self.getParameterValue(FixedDistanceBuffer.DISSOLVE)
segments = int(self.getParameterValue(FixedDistanceBuffer.SEGMENTS))
layer = QGisLayers.getObjectFromUri(self.getParameterValue(FixedDistanceBuffer.INPUT))
buff.buffering(progress, output, distance, None, useSelection, False, layer, dissolve, segments)
buff.buffering(progress, writer, distance, None, useSelection, False, layer, dissolve, segments)

def defineCharacteristics(self):
self.name = "Fixed distance buffer"
@@ -24,9 +24,6 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/intersect.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(Intersection.OUTPUT)
useSelection = self.getParameterValue(Intersection.USE_SELECTED)
useSelection2 = self.getParameterValue(Intersection.USE_SELECTED2)
vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT))
@@ -51,7 +48,7 @@ def processAlgorithm(self, progress):
longNames = ftools_utils.checkFieldNameLength( fields )
if not longNames.isEmpty():
raise GeoAlgorithmExecutionException("Following field names are longer than 10 characters:\n" + longNames.join('\n') )
writer = QgsVectorFileWriter( output, systemEncoding, fields, vproviderA.geometryType(), vproviderA.crs() )
writer = self.getOutputFromName(Intersection.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
inFeatA = QgsFeature()
inFeatB = QgsFeature()
outFeat = QgsFeature()
@@ -18,9 +18,6 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/layer_extent.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(LayerFromExtent.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(LayerFromExtent.INPUT))
fields = {
0 : QgsField( "MINX", QVariant.Double ),
@@ -34,7 +31,7 @@ def processAlgorithm(self, progress):
8 : QgsField( "HEIGHT", QVariant.Double ),
9 : QgsField( "WIDTH", QVariant.Double ) }

writer = QgsVectorFileWriter( output, systemEncoding, fields, QGis.WKBPolygon, self.vlayer.crs() )
writer = self.getOutputFromName(LayerFromExtent.OUTPUT).getVectorWriter(fields, QGis.WKBPolygon, self.vlayer.crs() )
rect = vlayer.extent()
minx = rect.xMinimum()
miny = rect.yMinimum()
@@ -23,9 +23,6 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/intersections.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(LinesIntersection.OUTPUT)
layer1 = QGisLayers.getObjectFromUri(self.getParameterValue(LinesIntersection.INPUT1))
layer2 = QGisLayers.getObjectFromUri(self.getParameterValue(LinesIntersection.INPUT2))
field1 = self.getParameterValue(LinesIntersection.FIELD1)
@@ -46,11 +43,7 @@ def processAlgorithm(self, progress):
field2.setName(unicode(field2.name()) + "_2")
fieldList = {0:field1, 1:field2}
sRs = provider1.crs()
check = QFile(output)
if check.exists():
if not QgsVectorFileWriter.deleteShapeFile(output):
raise GeoAlgorithmExecutionException("Could not delete existing output file")
writer = QgsVectorFileWriter(output, systemEncoding, fieldList, QGis.WKBPoint, sRs)
writer = self.getOutputFromName(LinesIntersection.OUTPUT).getVectorWriter(fieldList, QGis.WKBPoint, sRs)
#writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, QGis.WKBPoint, sRs)
inFeat = QgsFeature()
inFeatB = QgsFeature()
@@ -17,15 +17,12 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/to_lines.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(LinesToPolygons.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(LinesToPolygons.INPUT))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
writer = QgsVectorFileWriter( output, systemEncoding, fields, QGis.WKBPolygon, vprovider.crs() )
writer = self.getOutputFromName(LinesToPolygons.OUTPUT).getVectorWriter(fields, QGis.WKBPolygon, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -22,9 +22,6 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/mean.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(MeanCoords.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(MeanCoords.POINTS))
weightField = self.getParameterValue(MeanCoords.WEIGHT)
uniqueField = self.getParameterValue(MeanCoords.UID)
@@ -42,7 +39,7 @@ def processAlgorithm(self, progress):
uniqueValues = [QVariant(1)]
single = True
fieldList = { 0 : QgsField("MEAN_X", QVariant.Double), 1 : QgsField("MEAN_Y", QVariant.Double), 2 : QgsField("UID", QVariant.String) }
writer = QgsVectorFileWriter(output, systemEncoding, fieldList, QGis.WKBPoint, sRs)
writer = self.getOutputFromName(MeanCoords.OUTPUT).getVectorWriter(fieldList, QGis.WKBPoint, sRs)
outfeat = QgsFeature()
points = []
weights = []
@@ -18,17 +18,13 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/multi_to_single.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputValue(self.OUTPUT)
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
geomType = self.multiToSingleGeom(vprovider.geometryType())
writer = QgsVectorFileWriter( output, systemEncoding,
fields, geomType, vprovider.crs() )
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields, geomType, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -23,9 +23,6 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/sum_points.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(PointsInPolygon.OUTPUT)
inField = self.getParameterValue(PointsInPolygon.FIELD)
polyLayer = QGisLayers.getObjectFromUri(self.getParameterValue(PointsInPolygon.POLYGONS))
pointLayer = QGisLayers.getObjectFromUri(self.getParameterValue(PointsInPolygon.POINTS))
@@ -45,11 +42,7 @@ def processAlgorithm(self, progress):
field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15, "point count field")
fieldList[index] = field
sRs = polyProvider.crs()
check = QFile(output)
if check.exists():
if not QgsVectorFileWriter.deleteShapeFile(output):
raise GeoAlgorithmExecutionException("could not delete file: " + output)
writer = QgsVectorFileWriter(output, systemEncoding, fieldList, polyProvider.geometryType(), sRs)
writer = self.getOutputFromName(PointsInPolygon.OUTPUT).getVectorWriter(fieldList, polyProvider.geometryType(), sRs)
inFeat = QgsFeature()
inFeatB = QgsFeature()
outFeat = QgsFeature()
@@ -18,28 +18,22 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/to_lines.png")

def processAlgorithm(self, progress):
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
output = self.getOutputValue(PolygonsToLines.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(PolygonsToLines.INPUT))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
writer = QgsVectorFileWriter( output, systemEncoding,fields, QGis.WKBLineString, vprovider.crs() )
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields, QGis.WKBLineString, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
outGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
#self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
#self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
while vprovider.nextFeature(inFeat):
multi = False
nElement += 1
progress.setPercentage(int(nElement/nFeat * 100))
#self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
inGeom = inFeat.geometry()
if inGeom.isMultipart():
multi = True

0 comments on commit 8c42295

Please sign in to comment.
You can’t perform that action at this time.