Skip to content
Permalink
Browse files

Followup 436c30f, Also fix processing

And some code fixes
  • Loading branch information
m-kuhn committed Nov 24, 2015
1 parent 436c30f commit 62591d9453b59dfa5d059a48f197934c97e9dfb4
@@ -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 @@ def populateLayers(self):
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 @@ def intersect(self):
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 @@ def intersect(self):
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 @@ def intersect(self):
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 @@ def intersect(self):
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 @@ def union(self):
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 @@ def union(self):
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(diff_geom.geometry().wkbType()) == QgsWKBTypes.GeometryCollection:
temp_list = diff_geom.asGeometryCollection()
for i in temp_list:
if i.type() == geom.type():
@@ -1415,7 +1415,7 @@ def clip(self):
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(new_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 @@ def clip(self):
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(new_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 @@ def clip(self):
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(new_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 @@ def clip(self):
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(new_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))
@@ -25,7 +25,7 @@

__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 @@ def processAlgorithm(self, progress):
try:
cur_geom = QgsGeometry(outFeat.geometry())
new_geom = QgsGeometry(geom.intersection(cur_geom))
if new_geom.wkbType() == 0:
if new_geom.wkbType() == QGis.WKBUnknown or QgsWKBTypes.flatType(new_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))
@@ -25,7 +25,7 @@

__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 @@ def processAlgorithm(self, progress):
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))
@@ -25,7 +25,7 @@

__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 @@ def processAlgorithm(self, progress):
else:
int_geom = QgsGeometry(int_geom)

if int_geom.wkbType() == 0:
if int_geom.wkbType() == QGis.WKBUnknown 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 @@ def processAlgorithm(self, progress):
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)

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)
# 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 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())

0 comments on commit 62591d9

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