[processing] more clean in QGIS algs

This commit is contained in:
Alexander Bruy 2016-08-05 16:48:59 +03:00
parent acdde31b3d
commit 885cc82c3c
2 changed files with 17 additions and 18 deletions

View File

@ -29,7 +29,7 @@ import os
from qgis.PyQt.QtGui import QIcon 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.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@ -57,7 +57,6 @@ class MultipartToSingleparts(GeoAlgorithm):
def processAlgorithm(self, progress): def processAlgorithm(self, progress):
layer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT)) layer = dataobjects.getObjectFromUri(self.getParameterValue(self.INPUT))
geomType = self.multiToSingleGeom(layer.wkbType()) geomType = self.multiToSingleGeom(layer.wkbType())
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter( writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
@ -87,41 +86,41 @@ class MultipartToSingleparts(GeoAlgorithm):
def multiToSingleGeom(self, wkbType): def multiToSingleGeom(self, wkbType):
try: try:
if wkbType in (Qgis.WKBPoint, Qgis.WKBMultiPoint, if wkbType in (QgsWkbTypes.Point, QgsWkbTypes.MultiPoint,
Qgis.WKBPoint25D, Qgis.WKBMultiPoint25D): QgsWkbTypes.Point25D, QgsWkbTypes.MultiPoint25D):
return Qgis.WKBPoint return QgsWkbTypes.Point
elif wkbType in (Qgis.WKBLineString, Qgis.WKBMultiLineString, elif wkbType in (QgsWkbTypes.LineString, QgsWkbTypes.MultiLineString,
Qgis.WKBMultiLineString25D, QgsWkbTypes.MultiLineString25D,
Qgis.WKBLineString25D): QgsWkbTypes.LineString25D):
return Qgis.WKBLineString return QgsWkbTypes.LineString
elif wkbType in (Qgis.WKBPolygon, Qgis.WKBMultiPolygon, elif wkbType in (QgsWkbTypes.Polygon, QgsWkbTypes.MultiPolygon,
Qgis.WKBMultiPolygon25D, Qgis.WKBPolygon25D): QgsWkbTypes.MultiPolygon25D, QgsWkbTypes.Polygon25D):
return Qgis.WKBPolygon return QgsWkbTypes.Polygon
else: else:
return Qgis.WKBUnknown return QgsWkbTypes.Unknown
except Exception as err: except Exception as err:
raise GeoAlgorithmExecutionException(unicode(err)) raise GeoAlgorithmExecutionException(unicode(err))
def extractAsSingle(self, geom): def extractAsSingle(self, geom):
multiGeom = QgsGeometry() multiGeom = QgsGeometry()
geometries = [] geometries = []
if geom.type() == Qgis.Point: if geom.type() == QgsWkbTypes.PointGeometry:
if geom.isMultipart(): if geom.isMultipart():
multiGeom = geom.asMultiPoint() multiGeom = geom.asMultiPoint()
for i in multiGeom: for i in multiGeom:
geometries.append(QgsGeometry().fromPoint(i)) geometries.append(QgsGeometry().fromPoint(i))
else: else:
geometries.append(geom) geometries.append(geom)
elif geom.type() == Qgis.Line: elif geom.type() == QgsWkbTypes. LineGeometry:
if geom.isMultipart(): if geom.isMultipart():
multiGeom = geom.asMultiPolyline() multiGeom = geom.asMultiPolyline()
for i in multiGeom: for i in multiGeom:
geometries.append(QgsGeometry().fromPolyline(i)) geometries.append(QgsGeometry().fromPolyline(i))
else: else:
geometries.append(geom) geometries.append(geom)
elif geom.type() == Qgis.Polygon: elif geom.type() == QgsWkbTypes.PolygonGeometry:
if geom.isMultipart(): if geom.isMultipart():
multiGeom = geom.asMultiPolygon() multiGeom = geom.asMultiPolygon()
for i in multiGeom: for i in multiGeom:

View File

@ -30,7 +30,7 @@ import math
from qgis.PyQt.QtGui import QIcon 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.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog from processing.core.ProcessingLog import ProcessingLog
@ -98,7 +98,7 @@ class RectanglesOvalsDiamondsVariable(GeoAlgorithm):
writer = self.getOutputFromName( writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter( self.OUTPUT_LAYER).getVectorWriter(
layer.fields().toList(), layer.fields().toList(),
Qgis.WKBPolygon, QgsWkbTypes.Polygon,
layer.crs()) layer.crs())
outFeat = QgsFeature() outFeat = QgsFeature()