<div dir="ltr"><div>Hi</div><div><br></div><div>From QGIS 2.8 there is QgsGeometry.transform() method that works with QTransform. The following code will scale the sample line segment:</div><div><br></div><div>from PyQt4.QtGui import QTransform</div><div>g = QgsGeometry.fromPolyline([QgsPoint(-1,0),QgsPoint(1,0)])<br></div><div><div>g.transform( QTransform().scale(2,2) )<br></div><div>print g.asPolyline()<br></div><div><br></div><div>The code will print [(-2,0), (2,0)]</div></div><div><br></div><div>Cheers</div><div>Martin</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 6, 2015 at 6:53 PM, Geo DrinX <span dir="ltr"><<a href="mailto:geodrinx@gmail.com" target="_blank">geodrinx@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hello,<br><br><br></div>I need to scale a polygon from python code.<br><br>An extract of source code is the following :<br></div><div><div><div><br> for feat in iter:<br> geom = feat.geometry()<br> rect = geom.boundingBox()<br> <br> x1 = rect.xMinimum()<br> y1 = rect.yMinimum()<br> <br> x2 = rect.xMaximum()<br> y2 = rect.yMinimum()<br> <br> xc = (x2 + x1) / 2.0 <br> yc = (y2 + y1) / 2.0<br> <br> elem = geom.asPolygon()<br><br> fat = float(scale) / 100.<br><br> for i in range(geom.exportToWkt().count(',')):<br> <br> vertex = geom.vertexAt(i)<br><br> x,y = vertex.x(), vertex.y() <br><br> xR, yR = x-xc , y-yc<br> xS, yS = xR*fat, yR*fat<br> <br> xT, yT = xS + xc, yS + yc <br> <br> geom.moveVertex(xT, yT, i)<br><br><br></div><div>Because the polygon do not change, sure I miss something, to save the modified element, also if the layer is in editing.<br><br></div><div>Someone could help me to understand what I wrong ?<br><br><br></div><div>Thank you<br><br></div><div>Roberto<br></div><div><br></div></div></div></div>
<br>_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br></blockquote></div><br></div>