-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
188 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,144 +1,154 @@ | ||
from PyQt4.QtCore import * | ||
from PyQt4.QtGui import * | ||
|
||
from qgis.core import * | ||
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException | ||
|
||
from sextante.core.SextanteLog import SextanteLog | ||
|
||
def buffering(progress, writer, distance, field, useSelection, useField, layer, dissolve, segments ): | ||
def buffering(progress, writer, distance, field, useSelection, useField, layer, dissolve, segments): | ||
GEOS_EXCEPT = True | ||
FEATURE_EXCEPT = True | ||
vproviderA = layer.dataProvider() | ||
allAttrs = vproviderA.attributeIndexes() | ||
vproviderA.select( allAttrs ) | ||
fields = vproviderA.fields() | ||
|
||
layer.select(layer.pendingAllAttributesList()) | ||
|
||
if useField: | ||
field = vproviderA.fieldNameIndex(field) | ||
field = layer.fieldNameIndex(field) | ||
|
||
outFeat = QgsFeature() | ||
inFeat = QgsFeature() | ||
inGeom = QgsGeometry() | ||
outGeom = QgsGeometry() | ||
nElement = 0 | ||
|
||
current = 0 | ||
|
||
# there is selection in input layer | ||
if useSelection: | ||
nFeat = layer.selectedFeatureCount() | ||
selectionA = layer.selectedFeatures() | ||
# with dissolve | ||
if dissolve: | ||
first = True | ||
for inFeat in selectionA: | ||
atMap = inFeat.attributeMap() | ||
if useField: | ||
value = atMap[ field ].doDouble()[ 0 ] | ||
else: | ||
value = distance | ||
inGeom = QgsGeometry( inFeat.geometry() ) | ||
try: | ||
outGeom = inGeom.buffer( float( value ), segments) | ||
if first: | ||
tempGeom = QgsGeometry( outGeom ) | ||
first = False | ||
else: | ||
try: | ||
tempGeom = tempGeom.combine( outGeom ) | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
nElement += 1 | ||
progress.setPercentage(int(nElement/nFeat * 100)) | ||
try: | ||
outFeat.setGeometry( tempGeom ) | ||
writer.addFeature( outFeat ) | ||
except: | ||
FEATURE_EXCEPT = False | ||
# without dissolve | ||
else: | ||
for inFeat in selectionA: | ||
atMap = inFeat.attributeMap() | ||
if useField: | ||
value = atMap[ field ].toDouble()[ 0 ] | ||
else: | ||
value = distance | ||
inGeom = QgsGeometry( inFeat.geometry() ) | ||
try: | ||
outGeom = inGeom.buffer( float( value ), segments ) | ||
total = 100.0 / float(layer.selectedFeatureCount()) | ||
selection = layer.selectedFeatures() | ||
|
||
# with dissolve | ||
if dissolve: | ||
first = True | ||
for inFeat in selection: | ||
atMap = inFeat.attributeMap() | ||
if useField: | ||
value = atMap[field].doDouble()[0] | ||
else: | ||
value = distance | ||
|
||
inGeom = QgsGeometry(inFeat.geometry()) | ||
try: | ||
outGeom = inGeom.buffer(float(value), segments) | ||
if first: | ||
tempGeom = QgsGeometry(outGeom) | ||
first = False | ||
else: | ||
try: | ||
tempGeom = tempGeom.combine( outGeom ) | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
|
||
current += 1 | ||
progress.setPercentage(int(current * total)) | ||
try: | ||
outFeat.setGeometry( outGeom ) | ||
outFeat.setAttributeMap( atMap ) | ||
writer.addFeature( outFeat ) | ||
outFeat.setGeometry(tempGeom) | ||
writer.addFeature(outFeat) | ||
except: | ||
FEATURE_EXCEPT = False | ||
continue | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
nElement += 1 | ||
progress.setPercentage(int(nElement/nFeat * 100)) | ||
FEATURE_EXCEPT = False | ||
# without dissolve | ||
else: | ||
for inFeat in selection: | ||
atMap = inFeat.attributeMap() | ||
if useField: | ||
value = atMap[field].toDouble()[0] | ||
else: | ||
value = distance | ||
|
||
inGeom = QgsGeometry(inFeat.geometry()) | ||
try: | ||
outGeom = inGeom.buffer(float(value), segments) | ||
try: | ||
outFeat.setGeometry(outGeom) | ||
outFeat.setAttributeMap(atMap) | ||
writer.addFeature(outFeat) | ||
except: | ||
FEATURE_EXCEPT = False | ||
continue | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
|
||
current += 1 | ||
progress.setPercentage(int(current * total)) | ||
# there is no selection in input layer | ||
else: | ||
nFeat = vproviderA.featureCount() | ||
total = 100.0 / float(layer.featureCount()) | ||
|
||
# with dissolve | ||
if dissolve: | ||
first = True | ||
while vproviderA.nextFeature( inFeat ): | ||
atMap = inFeat.attributeMap() | ||
if useField: | ||
value = atMap[ field ].toDouble()[ 0 ] | ||
else: | ||
value = distance | ||
inGeom = QgsGeometry( inFeat.geometry() ) | ||
try: | ||
outGeom = inGeom.buffer( float( value ), segments) | ||
if first: | ||
tempGeom = QgsGeometry( outGeom ) | ||
first = False | ||
else: | ||
first = True | ||
while layer.nextFeature(inFeat): | ||
atMap = inFeat.attributeMap() | ||
if useField: | ||
value = atMap[field].toDouble()[0] | ||
else: | ||
value = distance | ||
|
||
inGeom = QgsGeometry(inFeat.geometry()) | ||
try: | ||
tempGeom = tempGeom.combine( outGeom ) | ||
outGeom = inGeom.buffer(float(value), segments) | ||
if first: | ||
tempGeom = QgsGeometry(outGeom) | ||
first = False | ||
else: | ||
try: | ||
tempGeom = tempGeom.combine(outGeom) | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
GEOS_EXCEPT = False | ||
continue | ||
|
||
current += 1 | ||
progress.setPercentage(int(current * total)) | ||
try: | ||
outFeat.setGeometry(tempGeom) | ||
writer.addFeature(outFeat) | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
nElement += 1 | ||
progress.setPercentage(int(nElement/nFeat * 100)) | ||
try: | ||
outFeat.setGeometry( tempGeom ) | ||
writer.addFeature( outFeat ) | ||
except: | ||
FEATURE_EXCEPT = False | ||
FEATURE_EXCEPT = False | ||
# without dissolve | ||
else: | ||
vproviderA.rewind() | ||
while vproviderA.nextFeature( inFeat ): | ||
atMap = inFeat.attributeMap() | ||
if useField: | ||
value = atMap[ field ].toDouble()[ 0 ] | ||
else: | ||
value = distance | ||
inGeom = QgsGeometry( inFeat.geometry() ) | ||
try: | ||
outGeom = inGeom.buffer( float( value ),segments ) | ||
try: | ||
outFeat.setGeometry( outGeom ) | ||
outFeat.setAttributeMap( atMap ) | ||
writer.addFeature( outFeat ) | ||
except: | ||
FEATURE_EXCEPT = False | ||
continue | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
nElement += 1 | ||
progress.setPercentage(int(nElement/nFeat * 100)) | ||
while layer.nextFeature(inFeat): | ||
atMap = inFeat.attributeMap() | ||
if useField: | ||
value = atMap[field].toDouble()[0] | ||
else: | ||
value = distance | ||
|
||
inGeom = QgsGeometry(inFeat.geometry()) | ||
try: | ||
outGeom = inGeom.buffer(float(value), segments) | ||
try: | ||
outFeat.setGeometry(outGeom) | ||
outFeat.setAttributeMap(atMap) | ||
writer.addFeature(outFeat) | ||
except: | ||
FEATURE_EXCEPT = False | ||
continue | ||
except: | ||
GEOS_EXCEPT = False | ||
continue | ||
|
||
current += 1 | ||
progress.setPercentage(int(current * total)) | ||
|
||
del writer | ||
|
||
if not GEOS_EXCEPT: | ||
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing buffer") | ||
if not FEATURE_EXCEPT: | ||
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing buffer") | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.