[Qgis-user] Adapt GVSig script to QGIS

Neumann, Andreas a.neumann at carto.net
Wed Jul 26 08:43:30 PDT 2017


Hi Sinorfavela, 

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
http://docs.qgis.org/2.18/en/docs/user_manual/print_composer/create_output.html#generate-an-atlas


Most likely, you don't need a script to do what you want. 

Let us know if that works. 

Andreas 

On 2017-07-26 14:15, sinorfavela wrote:

> Hi all,
> 
> I prepared, with a huge help of the Spannish community, a script for GVSig
> that save a view (in png) of each element into a layer centered in the
> viewport. Now I'm using QGis and I need to adapt the same script. Anyone
> could help me?
> 
> #---------><-- script start --><-----------------
> 
> from gvsig import *
> from commonsdialog import *
> from geom import *
> from com.sun.jimi.core import Jimi
> from org.gvsig.app import ApplicationLocator
> 
> import time
> 
> def centrarEnPunto(mapcontext, punto):
> # 1 - To obtain the extension of the map
> envelope = mapcontext.getViewPort().getAdjustedEnvelope()
> 
> # 2 - To calcule the displacement of the map to center it in the
> desired point
> movX = punto.getX()-envelope.getCenter(0)
> movY = punto.getY()-envelope.getCenter(1)
> 
> # 3 - To calcule new corner of the view.
> minx = envelope.getLowerCorner().getX() + movX;
> miny = envelope.getLowerCorner().getY() + movY;
> maxX = envelope.getUpperCorner().getX() + movX;
> maxY = envelope.getUpperCorner().getY() + movY;
> 
> # 4 - To define the new envelope of the view
> newenvelope = GeometryLocator.getGeometryManager().createEnvelope(
> minx, miny,
> maxX, maxY,
> Geometry.SUBTYPES.GEOM2D);
> 
> # 5 - Asignamos el nuevo encuadre
> mapcontext.getViewPort().setEnvelope(newenvelope);
> 
> def main(*args):
> application = ApplicationLocator.getManager()
> docvista = currentView()
> capa = currentLayer()
> if docvista == None:
> msgbox("An active viewport is needed")
> return
> if capa == None:
> msgbox("An active layer with geometries is needed")
> return
> 
> docwin = application.getDocumentWindow(docvista())
> n = 1
> for f in capa.features():
> 
> # 6 - To select the element  
> capa.getSelection().deselectAll()
> capa.getSelection().select(f)
> 
> # 7 - To center the view in the selected geometry
> centrarEnPunto(docvista.getMapContext(), f.geometry().centroid() )
> # 8- To wait a time to paint the view.
> time.sleep(2) 
> #9 - To obtain the image of the view
> img = docwin.getMapControl().getImage()
> pathname = "C:\\Users\\fmgm\\Desktop/kk/Barrios/Barrios%02d.png" % n
> #msgbox(pathname)
> Jimi.putImage(img,pathname)
> n += 1
> 
> #---------><-- script end --><-----------------
> 
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/Adapt-GVSig-script-to-QGIS-tp5329297.html
> Sent from the QGIS - User mailing list archive at Nabble.com.
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20170726/4d3e2384/attachment.html>


More information about the Qgis-user mailing list