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.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
import ftools_utils
@ -204,14 +204,14 @@ class GeoprocessingDialog(QDialog, Ui_Dialog):
self.inShapeA.addItems(myListA)
self.inShapeB.addItems(myListB)
#1: Buffer
#2: Convex Hull
#3: Difference
#4: Dissolve
#5: Intersection
#6: Union
#7: Symmetrical Difference
#8: Clip
# 1: Buffer
# 2: Convex Hull
# 3: Difference
# 4: Dissolve
# 5: Intersection
# 6: Union
# 7: Symmetrical Difference
# 8: Clip
def geoprocessing(self, myLayerA, myLayerB, myParam, myMerge, mySelectionA, mySelectionB, mySegments):
check = QFile(self.shapefileName)
@ -966,7 +966,7 @@ class geoprocessingThread(QThread):
if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes()
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_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym))
@ -1001,7 +1001,7 @@ class geoprocessingThread(QThread):
if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes()
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_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym))
@ -1040,7 +1040,7 @@ class geoprocessingThread(QThread):
if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes()
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_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym))
@ -1072,7 +1072,7 @@ class geoprocessingThread(QThread):
if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes()
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_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym))
@ -1161,7 +1161,7 @@ class geoprocessingThread(QThread):
else:
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
temp_list = int_geom.asGeometryCollection()
for i in temp_list:
@ -1197,7 +1197,7 @@ class geoprocessingThread(QThread):
intB = QgsGeometry.unaryUnion(lstIntersectingB)
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()
for i in temp_list:
if i.type() == geom.type():
@ -1415,7 +1415,7 @@ class geoprocessingThread(QThread):
try:
cur_geom = QgsGeometry(outFeat.geometry())
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_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym))
@ -1459,7 +1459,7 @@ class geoprocessingThread(QThread):
try:
cur_geom = QgsGeometry(outFeat.geometry())
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_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym))
@ -1511,7 +1511,7 @@ class geoprocessingThread(QThread):
try:
cur_geom = QgsGeometry(outFeat.geometry())
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_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym))
@ -1557,7 +1557,7 @@ class geoprocessingThread(QThread):
try:
cur_geom = QgsGeometry(outFeat.geometry())
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_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym))

View File

@ -25,7 +25,7 @@ __copyright__ = '(C) 2012, Victor Olaya'
__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.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
@ -103,7 +103,7 @@ class Clip(GeoAlgorithm):
try:
cur_geom = QgsGeometry(outFeat.geometry())
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_sym = QgsGeometry(geom.symDifference(cur_geom))
new_geom = QgsGeometry(int_com.difference(int_sym))

View File

@ -25,7 +25,7 @@ __copyright__ = '(C) 2012, Victor Olaya'
__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.ProcessingLog import ProcessingLog
from processing.core.parameters import ParameterVector
@ -79,7 +79,7 @@ class Intersection(GeoAlgorithm):
if geom.intersects(tmpGeom):
atMapB = inFeatB.attributes()
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_sym = geom.symDifference(tmpGeom)
int_geom = QgsGeometry(int_com.difference(int_sym))

View File

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