Matthias Kuhn bb79d13e82 Remove deprecated Qgis::WKBType and API cleanup (#3325)
* Remove deprecated Qgis::WKBType and API cleanup

Renames QgsWKBTypes to QgsWkbTypes

Replaces usage of the enums:

* Qgis::WKBType with QgsWkbTypes::Type
* Qgis::GeometryType with QgsWkbTypes::GeometryType

Their values should be forward compatible (a fact that was already
explited up to now by casting between the types)

Renames some SSLxxx to SslXxx and URIxxx to UriXxx

* Fix build warnings and simplify type handling

* Add a fixer to rewrite imports

* The forgotten rebase conflictThe forgotten rebase conflicts

* QgsDataSourcURI > QgsDataSourceUri

* QgsWKBTypes > QgsWkbTypes

* Qgis.WKBGeom > QgsWkbTypes.Geom

* Further python fixes

* Guess what... Qgis::wkbDimensions != QgsWkbTypes::wkbDimensions

* Fix tests

* Python 3 updates

* [travis] pull request caching cannot be disabled

so at least use it in r/w mode

* Fix python3 print in plugins
2016-08-04 09:10:08 +02:00

45 lines
1.2 KiB
Python

##Vector geometry tools=group
##Polygons=vector
##Max_area=number 100000
##Results=output vector
from qgis.core import Qgis, QgsFeature, QgsGeometry, QgsWkbTypes
from shapely.geometry import Polygon, MultiPolygon
from shapely.wkb import loads
from shapely.wkt import dumps
polyLayer = processing.getObject(Polygons)
polyPrder = polyLayer.dataProvider()
n = polyLayer.featureCount()
l = 0
writer = processing.VectorWriter(Results, None, polyPrder.fields(),
QgsWkbTypes.MultiPolygon, polyPrder.crs())
resgeom = QgsGeometry()
resfeat = QgsFeature()
for feat in processing.features(polyLayer):
progress.setPercentage(int(100 * l / n))
l += 1
g = loads(feat.geometry().asWkb())
if g.geom_type == 'MultiPolygon':
resg = [Polygon(p.exterior,
[r for r in p.interiors if Polygon(r).area > Max_area]) for p in g]
else:
resg = [Polygon(g.exterior,
[r for r in g.interiors if Polygon(r).area > Max_area])]
resgeom = QgsGeometry().fromWkt(dumps(MultiPolygon(resg)))
resfeat.setAttributes(feat.attributes())
resfeat.setGeometry(resgeom)
writer.addFeature(resfeat)
del writer