Skip to content
Permalink
Browse files

[processing] more clean in QGIS algs

  • Loading branch information
alexbruy committed Aug 5, 2016
1 parent acdde31 commit 885cc82c3c95261e9fefacd74d206ec454a28325
@@ -29,7 +29,7 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import Qgis, QgsFeature, QgsGeometry, QgsWkbTypes, QgsWkbTypes
from qgis.core import QgsFeature, QgsGeometry, QgsWkbTypes

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -57,7 +57,6 @@ def defineCharacteristics(self):

def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT))

geomType = self.multiToSingleGeom(layer.wkbType())

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
@@ -87,41 +86,41 @@ def processAlgorithm(self, progress):

def multiToSingleGeom(self, wkbType):
try:
if wkbType in (Qgis.WKBPoint, Qgis.WKBMultiPoint,
Qgis.WKBPoint25D, Qgis.WKBMultiPoint25D):
return Qgis.WKBPoint
elif wkbType in (Qgis.WKBLineString, Qgis.WKBMultiLineString,
Qgis.WKBMultiLineString25D,
Qgis.WKBLineString25D):

return Qgis.WKBLineString
elif wkbType in (Qgis.WKBPolygon, Qgis.WKBMultiPolygon,
Qgis.WKBMultiPolygon25D, Qgis.WKBPolygon25D):

return Qgis.WKBPolygon
if wkbType in (QgsWkbTypes.Point, QgsWkbTypes.MultiPoint,
QgsWkbTypes.Point25D, QgsWkbTypes.MultiPoint25D):
return QgsWkbTypes.Point
elif wkbType in (QgsWkbTypes.LineString, QgsWkbTypes.MultiLineString,
QgsWkbTypes.MultiLineString25D,
QgsWkbTypes.LineString25D):

return QgsWkbTypes.LineString
elif wkbType in (QgsWkbTypes.Polygon, QgsWkbTypes.MultiPolygon,
QgsWkbTypes.MultiPolygon25D, QgsWkbTypes.Polygon25D):

return QgsWkbTypes.Polygon
else:
return Qgis.WKBUnknown
return QgsWkbTypes.Unknown
except Exception as err:
raise GeoAlgorithmExecutionException(unicode(err))

def extractAsSingle(self, geom):
multiGeom = QgsGeometry()
geometries = []
if geom.type() == Qgis.Point:
if geom.type() == QgsWkbTypes.PointGeometry:
if geom.isMultipart():
multiGeom = geom.asMultiPoint()
for i in multiGeom:
geometries.append(QgsGeometry().fromPoint(i))
else:
geometries.append(geom)
elif geom.type() == Qgis.Line:
elif geom.type() == QgsWkbTypes. LineGeometry:
if geom.isMultipart():
multiGeom = geom.asMultiPolyline()
for i in multiGeom:
geometries.append(QgsGeometry().fromPolyline(i))
else:
geometries.append(geom)
elif geom.type() == Qgis.Polygon:
elif geom.type() == QgsWkbTypes.PolygonGeometry:
if geom.isMultipart():
multiGeom = geom.asMultiPolygon()
for i in multiGeom:
@@ -30,7 +30,7 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import Qgis, QgsFeature, QgsGeometry, QgsPoint
from qgis.core import QgsWkbTypes, QgsFeature, QgsGeometry, QgsPoint

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
@@ -98,7 +98,7 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(
layer.fields().toList(),
Qgis.WKBPolygon,
QgsWkbTypes.Polygon,
layer.crs())

outFeat = QgsFeature()

0 comments on commit 885cc82

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