2014-07-10 22:35:40 +02:00
|
|
|
##Vector geometry tools=group
|
|
|
|
##Polygons=vector
|
|
|
|
##Max_area=number 100000
|
|
|
|
##Results=output vector
|
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
from qgis.core import QGis, QgsFeature, QgsGeometry
|
2014-07-10 22:35:40 +02:00
|
|
|
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
|
|
|
|
|
2014-07-14 14:19:09 +02:00
|
|
|
writer = processing.VectorWriter(Results, None, polyPrder.fields(),
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
QGis.WKBMultiPolygon, polyPrder.crs())
|
2014-07-13 17:16:24 +02:00
|
|
|
|
2014-07-10 22:35:40 +02:00
|
|
|
|
|
|
|
resgeom = QgsGeometry()
|
|
|
|
resfeat = QgsFeature()
|
|
|
|
|
|
|
|
for feat in processing.features(polyLayer):
|
2015-08-22 14:29:41 +02:00
|
|
|
progress.setPercentage(int(100 * l / n))
|
|
|
|
l += 1
|
2014-07-13 17:16:24 +02:00
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
g = loads(feat.geometry().asWkb())
|
2014-07-13 17:16:24 +02:00
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
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]
|
2014-07-13 17:16:24 +02:00
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
else:
|
|
|
|
resg = [Polygon(g.exterior,
|
|
|
|
[r for r in g.interiors if Polygon(r).area > Max_area])]
|
2014-07-10 22:35:40 +02:00
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
resgeom = QgsGeometry().fromWkt(dumps(MultiPolygon(resg)))
|
2014-07-13 17:16:24 +02:00
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
resfeat.setAttributes(feat.attributes())
|
|
|
|
resfeat.setGeometry(resgeom)
|
|
|
|
writer.addFeature(resfeat)
|
2014-07-10 22:35:40 +02:00
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
del writer
|