mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
[processing] more clean in QGIS algs
This commit is contained in:
parent
acdde31b3d
commit
885cc82c3c
@ -29,7 +29,7 @@ import os
|
||||
|
||||
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 @@ class MultipartToSingleparts(GeoAlgorithm):
|
||||
|
||||
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 @@ class MultipartToSingleparts(GeoAlgorithm):
|
||||
|
||||
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):
|
||||
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 Qgis.WKBLineString
|
||||
elif wkbType in (Qgis.WKBPolygon, Qgis.WKBMultiPolygon,
|
||||
Qgis.WKBMultiPolygon25D, Qgis.WKBPolygon25D):
|
||||
return QgsWkbTypes.LineString
|
||||
elif wkbType in (QgsWkbTypes.Polygon, QgsWkbTypes.MultiPolygon,
|
||||
QgsWkbTypes.MultiPolygon25D, QgsWkbTypes.Polygon25D):
|
||||
|
||||
return Qgis.WKBPolygon
|
||||
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 @@ import math
|
||||
|
||||
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 @@ class RectanglesOvalsDiamondsVariable(GeoAlgorithm):
|
||||
writer = self.getOutputFromName(
|
||||
self.OUTPUT_LAYER).getVectorWriter(
|
||||
layer.fields().toList(),
|
||||
Qgis.WKBPolygon,
|
||||
QgsWkbTypes.Polygon,
|
||||
layer.crs())
|
||||
|
||||
outFeat = QgsFeature()
|
||||
|
Loading…
x
Reference in New Issue
Block a user