Skip to content

Commit

Permalink
[processing] more clean in QGIS algs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Aug 5, 2016
1 parent acdde31 commit 885cc82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
35 changes: 17 additions & 18 deletions python/plugins/processing/algs/qgis/MultipartToSingleparts.py
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 885cc82

Please sign in to comment.