<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi Sinorfavela,</p>
<p>QGIS has something called "Atlas printing" - which allows you to iterate over each feature and create an image per feature or a PDF-page in a multi-page file. Have a look in the QGIS manual and search for Atlas printing. See <a href="http://docs.qgis.org/2.18/en/docs/user_manual/print_composer/create_output.html#generate-an-atlas">http://docs.qgis.org/2.18/en/docs/user_manual/print_composer/create_output.html#generate-an-atlas</a></p>
<p>Most likely, you don't need a script to do what you want.</p>
<p>Let us know if that works.</p>
<p>Andreas</p>
<p>On 2017-07-26 14:15, sinorfavela wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">Hi all,<br /> <br /> I prepared, with a huge help of the Spannish community, a script for GVSig<br /> that save a view (in png) of each element into a layer centered in the<br /> viewport. Now I'm using QGis and I need to adapt the same script. Anyone<br /> could help me?<br /> <br /> <br /> #---------><-- script start --><-----------------<br /> <br /> from gvsig import *<br /> from commonsdialog import *<br /> from geom import *<br /> from com.sun.jimi.core import Jimi<br /> from org.gvsig.app import ApplicationLocator<br /> <br /> import time<br /> <br /> def centrarEnPunto(mapcontext, punto):<br /> # 1 - To obtain the extension of the map<br /> envelope = mapcontext.getViewPort().getAdjustedEnvelope()<br /> <br /> # 2 - To calcule the displacement of the map to center it in the<br /> desired point<br /> movX = punto.getX()-envelope.getCenter(0)<br /> movY = punto.getY()-envelope.getCenter(1)<br /> <br /> # 3 - To calcule new corner of the view.<br /> minx = envelope.getLowerCorner().getX() + movX;<br /> miny = envelope.getLowerCorner().getY() + movY;<br /> maxX = envelope.getUpperCorner().getX() + movX;<br /> maxY = envelope.getUpperCorner().getY() + movY;<br /> <br /> # 4 - To define the new envelope of the view<br /> newenvelope = GeometryLocator.getGeometryManager().createEnvelope(<br /> minx, miny,<br /> maxX, maxY,<br /> Geometry.SUBTYPES.GEOM2D);<br /> <br /> # 5 - Asignamos el nuevo encuadre<br /> mapcontext.getViewPort().setEnvelope(newenvelope);<br /> <br /> def main(*args):<br /> application = ApplicationLocator.getManager()<br /> docvista = currentView()<br /> capa = currentLayer()<br /> if docvista == None:<br /> msgbox("An active viewport is needed")<br /> return<br /> if capa == None:<br /> msgbox("An active layer with geometries is needed")<br /> return<br /> <br /> docwin = application.getDocumentWindow(docvista())<br /> n = 1<br /> for f in capa.features():<br /> <br /> # 6 - To select the element <br /> capa.getSelection().deselectAll()<br /> capa.getSelection().select(f)<br /> <br /> # 7 - To center the view in the selected geometry<br /> centrarEnPunto(docvista.getMapContext(), f.geometry().centroid() )<br /> # 8- To wait a time to paint the view.<br /> time.sleep(2) <br /> #9 - To obtain the image of the view<br /> img = docwin.getMapControl().getImage()<br /> pathname = "C:\\Users\\fmgm\\Desktop/kk/Barrios/Barrios%02d.png" % n<br /> #msgbox(pathname)<br /> Jimi.putImage(img,pathname)<br /> n += 1<br /> <br /> #---------><-- script end --><-----------------<br /> <br /> <br /> <br /> <br /> <br /> --<br /> View this message in context: <a href="http://osgeo-org.1560.x6.nabble.com/Adapt-GVSig-script-to-QGIS-tp5329297.html">http://osgeo-org.1560.x6.nabble.com/Adapt-GVSig-script-to-QGIS-tp5329297.html</a><br /> Sent from the QGIS - User mailing list archive at Nabble.com.<br /> _______________________________________________<br /> Qgis-user mailing list<br /> <a href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a><br /> List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><br /> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a></div>
</blockquote>
<p><br /></p>
</body></html>