Followup 594fafe73b8, Also fix processing

This commit is contained in:
Matthias Kuhn 2015-11-24 16:13:26 +01:00
parent 594fafe73b
commit 2e7c33281c
4 changed files with 41 additions and 41 deletions

View File

@ -32,7 +32,7 @@
from PyQt4.QtCore import SIGNAL, QObject, Qt, QFile, QThread, QVariant from PyQt4.QtCore import SIGNAL, QObject, Qt, QFile, QThread, QVariant
from PyQt4.QtGui import QDialog, QDoubleValidator, QDialogButtonBox, QMessageBox from PyQt4.QtGui import QDialog, QDoubleValidator, QDialogButtonBox, QMessageBox
from qgis.core import QGis, QgsVectorFileWriter, QgsFeature, QgsGeometry, QgsFields, QgsField, QgsFeatureRequest, QgsPoint, QgsDistanceArea, QgsMessageLog, QgsWKBTypes from qgis.core import QGis, QgsVectorFileWriter, QgsFeature, QgsGeometry, QgsFields, QgsField, QgsFeatureRequest, QgsPoint, QgsDistanceArea, QgsWKBTypes
from ui_frmGeoprocessing import Ui_Dialog from ui_frmGeoprocessing import Ui_Dialog
import ftools_utils import ftools_utils
@ -204,14 +204,14 @@ class GeoprocessingDialog(QDialog, Ui_Dialog):
self.inShapeA.addItems(myListA) self.inShapeA.addItems(myListA)
self.inShapeB.addItems(myListB) self.inShapeB.addItems(myListB)
#1: Buffer # 1: Buffer
#2: Convex Hull # 2: Convex Hull
#3: Difference # 3: Difference
#4: Dissolve # 4: Dissolve
#5: Intersection # 5: Intersection
#6: Union # 6: Union
#7: Symmetrical Difference # 7: Symmetrical Difference
#8: Clip # 8: Clip
def geoprocessing(self, myLayerA, myLayerB, myParam, myMerge, mySelectionA, mySelectionB, mySegments): def geoprocessing(self, myLayerA, myLayerB, myParam, myMerge, mySelectionA, mySelectionB, mySegments):
check = QFile(self.shapefileName) check = QFile(self.shapefileName)
@ -966,7 +966,7 @@ class geoprocessingThread(QThread):
if geom.intersects(tmpGeom): if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes() atMapB = inFeatB.attributes()
int_geom = QgsGeometry(geom.intersection(tmpGeom)) int_geom = QgsGeometry(geom.intersection(tmpGeom))
if int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection: if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = geom.combine(tmpGeom) int_com = geom.combine(tmpGeom)
int_sym = geom.symDifference(tmpGeom) int_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym)) int_geom = QgsGeometry(int_com.difference(int_sym))
@ -1001,7 +1001,7 @@ class geoprocessingThread(QThread):
if geom.intersects(tmpGeom): if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes() atMapB = inFeatB.attributes()
int_geom = QgsGeometry(geom.intersection(tmpGeom)) int_geom = QgsGeometry(geom.intersection(tmpGeom))
if int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection: if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = geom.combine(tmpGeom) int_com = geom.combine(tmpGeom)
int_sym = geom.symDifference(tmpGeom) int_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym)) int_geom = QgsGeometry(int_com.difference(int_sym))
@ -1040,7 +1040,7 @@ class geoprocessingThread(QThread):
if geom.intersects(tmpGeom): if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes() atMapB = inFeatB.attributes()
int_geom = QgsGeometry(geom.intersection(tmpGeom)) int_geom = QgsGeometry(geom.intersection(tmpGeom))
if int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection: if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = geom.combine(tmpGeom) int_com = geom.combine(tmpGeom)
int_sym = geom.symDifference(tmpGeom) int_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym)) int_geom = QgsGeometry(int_com.difference(int_sym))
@ -1072,7 +1072,7 @@ class geoprocessingThread(QThread):
if geom.intersects(tmpGeom): if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes() atMapB = inFeatB.attributes()
int_geom = QgsGeometry(geom.intersection(tmpGeom)) int_geom = QgsGeometry(geom.intersection(tmpGeom))
if ( int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection ): if (int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection):
int_com = geom.combine(tmpGeom) int_com = geom.combine(tmpGeom)
int_sym = geom.symDifference(tmpGeom) int_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym)) int_geom = QgsGeometry(int_com.difference(int_sym))
@ -1161,7 +1161,7 @@ class geoprocessingThread(QThread):
else: else:
int_geom = QgsGeometry(int_geom) int_geom = QgsGeometry(int_geom)
if int_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection: if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
# intersection produced different geometry types # intersection produced different geometry types
temp_list = int_geom.asGeometryCollection() temp_list = int_geom.asGeometryCollection()
for i in temp_list: for i in temp_list:
@ -1197,7 +1197,7 @@ class geoprocessingThread(QThread):
intB = QgsGeometry.unaryUnion(lstIntersectingB) intB = QgsGeometry.unaryUnion(lstIntersectingB)
diff_geom = diff_geom.difference(intB) diff_geom = diff_geom.difference(intB)
if diff_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection: if diff_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
temp_list = diff_geom.asGeometryCollection() temp_list = diff_geom.asGeometryCollection()
for i in temp_list: for i in temp_list:
if i.type() == geom.type(): if i.type() == geom.type():
@ -1415,7 +1415,7 @@ class geoprocessingThread(QThread):
try: try:
cur_geom = QgsGeometry(outFeat.geometry()) cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(geom.intersection(cur_geom)) new_geom = QgsGeometry(geom.intersection(cur_geom))
if new_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection: if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = QgsGeometry(geom.combine(cur_geom)) int_com = QgsGeometry(geom.combine(cur_geom))
int_sym = QgsGeometry(geom.symDifference(cur_geom)) int_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym)) new_geom = QgsGeometry(int_com.difference(int_sym))
@ -1459,7 +1459,7 @@ class geoprocessingThread(QThread):
try: try:
cur_geom = QgsGeometry(outFeat.geometry()) cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(geom.intersection(cur_geom)) new_geom = QgsGeometry(geom.intersection(cur_geom))
if new_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection: if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = QgsGeometry(geom.combine(cur_geom)) int_com = QgsGeometry(geom.combine(cur_geom))
int_sym = QgsGeometry(geom.symDifference(cur_geom)) int_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym)) new_geom = QgsGeometry(int_com.difference(int_sym))
@ -1511,7 +1511,7 @@ class geoprocessingThread(QThread):
try: try:
cur_geom = QgsGeometry(outFeat.geometry()) cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(geom.intersection(cur_geom)) new_geom = QgsGeometry(geom.intersection(cur_geom))
if new_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection: if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = QgsGeometry(geom.combine(cur_geom)) int_com = QgsGeometry(geom.combine(cur_geom))
int_sym = QgsGeometry(geom.symDifference(cur_geom)) int_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym)) new_geom = QgsGeometry(int_com.difference(int_sym))
@ -1557,7 +1557,7 @@ class geoprocessingThread(QThread):
try: try:
cur_geom = QgsGeometry(outFeat.geometry()) cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(geom.intersection(cur_geom)) new_geom = QgsGeometry(geom.intersection(cur_geom))
if new_geom.wkbType() == 0 or QgsWKBTypes.flatType( int_geom.geometry().wkbType() ) == QgsWKBTypes.GeometryCollection: if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = QgsGeometry(geom.combine(cur_geom)) int_com = QgsGeometry(geom.combine(cur_geom))
int_sym = QgsGeometry(geom.symDifference(cur_geom)) int_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym)) new_geom = QgsGeometry(int_com.difference(int_sym))

View File

@ -25,7 +25,7 @@ __copyright__ = '(C) 2012, Victor Olaya'
__revision__ = '$Format:%H$' __revision__ = '$Format:%H$'
from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest from qgis.core import QgsFeature, QgsGeometry, QgsFeatureRequest, QgsWKBTypes
from processing.core.GeoAlgorithm import GeoAlgorithm from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector from processing.core.parameters import ParameterVector
@ -103,7 +103,7 @@ class Clip(GeoAlgorithm):
try: try:
cur_geom = QgsGeometry(outFeat.geometry()) cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(geom.intersection(cur_geom)) new_geom = QgsGeometry(geom.intersection(cur_geom))
if new_geom.wkbType() == 0: if new_geom.wkbType() == 0 or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = QgsGeometry(geom.combine(cur_geom)) int_com = QgsGeometry(geom.combine(cur_geom))
int_sym = QgsGeometry(geom.symDifference(cur_geom)) int_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym)) new_geom = QgsGeometry(int_com.difference(int_sym))

View File

@ -25,7 +25,7 @@ __copyright__ = '(C) 2012, Victor Olaya'
__revision__ = '$Format:%H$' __revision__ = '$Format:%H$'
from qgis.core import QGis, QgsFeatureRequest, QgsFeature, QgsGeometry from qgis.core import QGis, QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWKBTypes
from processing.core.GeoAlgorithm import GeoAlgorithm from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog from processing.core.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector from processing.core.parameters import ParameterVector
@ -79,7 +79,7 @@ class Intersection(GeoAlgorithm):
if geom.intersects(tmpGeom): if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes() atMapB = inFeatB.attributes()
int_geom = QgsGeometry(geom.intersection(tmpGeom)) int_geom = QgsGeometry(geom.intersection(tmpGeom))
if int_geom.wkbType() == QGis.WKBUnknown: if int_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
int_com = geom.combine(tmpGeom) int_com = geom.combine(tmpGeom)
int_sym = geom.symDifference(tmpGeom) int_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym)) int_geom = QgsGeometry(int_com.difference(int_sym))

View File

@ -25,7 +25,7 @@ __copyright__ = '(C) 2012, Victor Olaya'
__revision__ = '$Format:%H$' __revision__ = '$Format:%H$'
from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry from qgis.core import QgsFeatureRequest, QgsFeature, QgsGeometry, QgsWKBTypes
from processing.core.GeoAlgorithm import GeoAlgorithm from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@ -99,7 +99,7 @@ class Union(GeoAlgorithm):
else: else:
int_geom = QgsGeometry(int_geom) int_geom = QgsGeometry(int_geom)
if int_geom.wkbType() == 0: if int_geom.wkbType() == 0 or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
# Intersection produced different geomety types # Intersection produced different geomety types
temp_list = int_geom.asGeometryCollection() temp_list = int_geom.asGeometryCollection()
for i in temp_list: for i in temp_list:
@ -117,24 +117,24 @@ class Union(GeoAlgorithm):
self.tr('Feature exception while computing union')) self.tr('Feature exception while computing union'))
try: try:
# the remaining bit of inFeatA's geometry # the remaining bit of inFeatA's geometry
# if there is nothing left, this will just silently fail and we're good # if there is nothing left, this will just silently fail and we're good
diff_geom = QgsGeometry(geom) diff_geom = QgsGeometry(geom)
if len(lstIntersectingB) != 0: if len(lstIntersectingB) != 0:
intB = QgsGeometry.unaryUnion(lstIntersectingB) intB = QgsGeometry.unaryUnion(lstIntersectingB)
diff_geom = diff_geom.difference(intB) diff_geom = diff_geom.difference(intB)
if diff_geom.wkbType() == 0: if diff_geom.wkbType() == 0 or QgsWKBTypes.flatType(int_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
temp_list = diff_geom.asGeometryCollection() temp_list = diff_geom.asGeometryCollection()
for i in temp_list: for i in temp_list:
if i.type() == geom.type(): if i.type() == geom.type():
diff_geom = QgsGeometry(i) diff_geom = QgsGeometry(i)
outFeat.setGeometry(diff_geom) outFeat.setGeometry(diff_geom)
outFeat.setAttributes(atMapA) outFeat.setAttributes(atMapA)
writer.addFeature(outFeat) writer.addFeature(outFeat)
except Exception as err: except Exception as err:
raise GeoAlgorithmExecutionException( raise GeoAlgorithmExecutionException(
self.tr('Feature exception while computing union')) self.tr('Feature exception while computing union'))
length = len(vproviderA.fields()) length = len(vproviderA.fields())