Skip to content
Permalink
Browse files

partially revert d2189ac

  • Loading branch information
alexbruy committed Sep 14, 2016
1 parent d2189ac commit 3d72b09e11c8e70ace2af45581d1a270b3f84c29
Showing with 21 additions and 22 deletions.
  1. +21 −22 python/plugins/processing/algs/qgis/SinglePartsToMultiparts.py
@@ -29,7 +29,7 @@

from qgis.PyQt.QtGui import QIcon

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

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -67,7 +67,7 @@ def processAlgorithm(self, progress):
geomType = self.singleToMultiGeom(layer.wkbType())

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layer.fields().toList(), geomType, layer.crs())
layer.pendingFields().toList(), geomType, layer.crs())

inFeat = QgsFeature()
outFeat = QgsFeature()
@@ -92,7 +92,7 @@ def processAlgorithm(self, progress):
if first:
attrs = atMap
first = False
inGeom = inFeat.geometry()
inGeom = QgsGeometry(inFeat.geometry())
vType = inGeom.type()
feature_list = self.extractAsMulti(inGeom)
multi_feature.extend(feature_list)
@@ -108,35 +108,34 @@ def processAlgorithm(self, progress):

del writer
else:
raise GeoAlgorithmExecutionException(
self.tr('At least two features must have same attribute value! Please choose another field...'))
raise GeoAlgorithmExecutionException(self.tr('Invalid unique ID field'))

def singleToMultiGeom(self, wkbType):
try:
if wkbType in (QgsWkbTypes.Point, QgsWkbTypes.MultiPoint,
QgsWkbTypes.Point25D, QgsWkbTypes.MultiPoint25D):
return QgsWkbTypes.MultiPoint
elif wkbType in (QgsWkbTypes.LineString, QgsWkbTypes.MultiLineString,
QgsWkbTypes.MultiLineString25D,
QgsWkbTypes.LineString25D):

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

return QgsWkbTypes.MultiPolygon
if wkbType in (QGis.WKBPoint, QGis.WKBMultiPoint,
QGis.WKBPoint25D, QGis.WKBMultiPoint25D):
return QGis.WKBMultiPoint
elif wkbType in (QGis.WKBLineString, QGis.WKBMultiLineString,
QGis.WKBMultiLineString25D,
QGis.WKBLineString25D):

return QGis.WKBMultiLineString
elif wkbType in (QGis.WKBPolygon, QGis.WKBMultiPolygon,
QGis.WKBMultiPolygon25D, QGis.WKBPolygon25D):

return QGis.WKBMultiPolygon
else:
return QgsWkbTypes.Unknown
return QGis.WKBUnknown
except Exception:
pass

def extractAsMulti(self, geom):
if geom.type() == QgsWkbTypes.PointGeometry:
if geom.type() == QGis.Point:
if geom.isMultipart():
return geom.asMultiPoint()
else:
return [geom.asPoint()]
elif geom.type() == QgsWkbTypes.LineGeometry:
elif geom.type() == QGis.Line:
if geom.isMultipart():
return geom.asMultiPolyline()
else:
@@ -148,9 +147,9 @@ def extractAsMulti(self, geom):
return [geom.asPolygon()]

def convertGeometry(self, geom_list, vType):
if vType == QgsWkbTypes.PointGeometry:
if vType == QGis.Point:
return QgsGeometry().fromMultiPoint(geom_list)
elif vType == QgsWkbTypes.LineGeometry:
elif vType == QGis.Line:
return QgsGeometry().fromMultiPolyline(geom_list)
else:
return QgsGeometry().fromMultiPolygon(geom_list)

0 comments on commit 3d72b09

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