[Qgis-developer] How to scale a polygon from pyQgis
Geo DrinX
geodrinx at gmail.com
Fri Feb 6 03:53:05 PST 2015
Hello,
I need to scale a polygon from python code.
An extract of source code is the following :
for feat in iter:
geom = feat.geometry()
rect = geom.boundingBox()
x1 = rect.xMinimum()
y1 = rect.yMinimum()
x2 = rect.xMaximum()
y2 = rect.yMinimum()
xc = (x2 + x1) / 2.0
yc = (y2 + y1) / 2.0
elem = geom.asPolygon()
fat = float(scale) / 100.
for i in range(geom.exportToWkt().count(',')):
vertex = geom.vertexAt(i)
x,y = vertex.x(),
vertex.y()
xR, yR = x-xc , y-yc
xS, yS = xR*fat, yR*fat
xT, yT = xS + xc, yS + yc
geom.moveVertex(xT, yT, i)
Because the polygon do not change, sure I miss something, to save the
modified element, also if the layer is in editing.
Someone could help me to understand what I wrong ?
Thank you
Roberto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150206/6a63f629/attachment.html>
More information about the Qgis-developer
mailing list