[Qgis-user] Adapt GVSig script to QGIS
sinorfavela
fircorreo at yahoo.es
Wed Jul 26 05:15:18 PDT 2017
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.
More information about the Qgis-user
mailing list