<HTML><HEAD><TITLE>Re: [Gvsig_desarrolladores] vista - exportar - imagen - jython</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.17080" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText13766>
<DIV><FONT face="Times New Roman" color=#000000 size=3>Hola, Steffen:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>Creo que lo que estás intentando hacer no es muy apropiado para un programa como gvSIG. Lo normal es usar un renderizador como Mapnik o un servidor de mapas como Mapserver.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>Sobre tus dudas:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>Cuando obtienes una geometría de una capa y&nbsp;su extent, las unidades son las del mapa (casi siempre grados decimales o metros), pero en la pantalla (y cuando creas azulejos o tiles) la unidad es el pixel. Esos métodos de la clase ViewPort te ayudan a pasar de coordenadas del mapa (grados o metros) a coordenadas de la pantalla (pixels). Necesitas saber cuántos pixels ocupa un tile, y qué desplazamiento (en pixels) tiene cada tile respecto a los bordes del mapa, etc.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>He hecho la siguiente prueba:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>- Cargo una capa WMS (por ejemplo <A href="http://www.gis.nrw.de/wms/DGM50">http://www.gis.nrw.de/wms/DGM50</A>? )</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>- añado un shapefile </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>y veo esto:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3><A href="http://www.prodevelop.es/files/fm/public/screenshots/gvsig_desktop/jythonview.jpg">http://www.prodevelop.es/files/fm/public/screenshots/gvsig_desktop/jythonview.jpg</A></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>A continuación abro una consola de scripting y pego todo este párrafo:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3></FONT>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>import time; from java.awt.image import *; from javax.imageio import ImageIO; from java.io import File; from gvsiglib import *; view = gvSIG.getActiveDocument(); mctrl = view.getMapControl(); mcon = mctrl.getMapContext(); vp = mctrl.getViewPort(); lyr=mcon.getLayers().getLayer(1); lyr.getSource().start(); indazu = 0; azu0=lyr.getSource().getShape(indazu); w = vp.fromMapDistance(azu0.getBounds2D().getWidth()); h = vp.fromMapDistance(azu0.getBounds2D().getHeight()); bimg = BufferedImage(w,h, BufferedImage.TYPE_INT_RGB); graf = bimg.createGraphics(); offsetxmap = azu0.getBounds2D().getMinX()-vp.getAdjustedExtent().getMinX(); offsetymap = vp.getAdjustedExtent().getMaxY()-azu0.getBounds2D().getMaxY(); offsetxpix = vp.fromMapDistance(offsetxmap); offsetypix = vp.fromMapDistance(offsetymap); vpwpix = vp.getImageWidth(); vphpix = vp.getImageHeight(); graf.drawImage(mctrl.getImage(), -offsetxpix, -offsetypix, vpwpix, vphpix, None); ImageIO.write(bimg,'png',File('c:/tempo/azulejo.png')); </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>Debes tener cuidado con el índice de la capa. Creo que los índices van de abajo hacia arriba, es decir, en este caso la capa 0 es el WMS y la capa 1 es el shapefile, por eso escribo:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>lyr=mcon.getLayers().getLayer(1);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>Debe existir una carpeta c:\tempo en tu ordenador, y entonces se crea un archivo c:/tempo/azulejo.png como este:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3><A href="http://www.prodevelop.es/files/fm/public/screenshots/gvsig_desktop/azulejo.png">http://www.prodevelop.es/files/fm/public/screenshots/gvsig_desktop/azulejo.png</A></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>La explicación del párrafo es:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>===================</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// imports</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>import time;</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>from java.awt.image import *;</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>from javax.imageio import ImageIO;</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>from java.io import File;</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>from gvsiglib import *;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// obtener capa con rectangulos (azulejos o tiles)</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>view = gvSIG.getActiveDocument();</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>mctrl = view.getMapControl();</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>mcon = mctrl.getMapContext();</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>vp = mctrl.getViewPort();</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>lyr=mcon.getLayers().getLayer(1);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// obtener azulejo 0</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>lyr.getSource().start();</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>indazu = 0;</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>azu0=lyr.getSource().getShape(indazu);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// obtener tamaño del azulejo en la pantalla (en pixels)</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>w = vp.fromMapDistance(azu0.getBounds2D().getWidth());</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>h = vp.fromMapDistance(azu0.getBounds2D().getHeight());</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// craer imagen del mismo tamaño (vacia)</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>bimg = BufferedImage(w,h, BufferedImage.TYPE_INT_RGB);</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>graf = bimg.createGraphics();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// calcular desplazamiento del azulejo con respecto al borde del mapa (en unidades del mapa)</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>offsetxmap = azu0.getBounds2D().getMinX()-vp.getAdjustedExtent().getMinX();</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>offsetymap = vp.getAdjustedExtent().getMaxY()-azu0.getBounds2D().getMaxY();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// calcular desplazamiento del azulejo con respecto al borde del mapa (en pixels)</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>offsetxpix = vp.fromMapDistance(offsetxmap);</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>offsetypix = vp.fromMapDistance(offsetymap);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// obtener tamaño del mapa completo (vista) en pixels</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>vpwpix = vp.getImageWidth();</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>vphpix = vp.getImageHeight();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// dibujar el mapa encima de la imagen que tiene mismo tamaño que azulejo</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// se usa el desplazamiento. esto es como un "clipping", es decir, la mayor parte</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// de la imagen cae fuera del azulejo</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>graf.drawImage(mctrl.getImage(), -offsetxpix, -offsetypix, vpwpix, vphpix, None);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>// escribir imagen</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>ImageIO.write(bimg,'png',File('c:/tempo/azulejo.png')); </FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3>===================</FONT></DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3></FONT>&nbsp;</DIV>
<DIV><FONT face="Times New Roman" color=#000000 size=3></FONT>&nbsp;</DIV>
<DIV>Saludos,</DIV></DIV>
<DIV id=idSignature99388>
<DIV><FONT face="Courier New" size=2><FONT face="Times New Roman" size=3>Juan Lucas Domínguez Rubio<BR></FONT>---</FONT></DIV>
<DIV><FONT face="Courier New" size=2><FONT face="Courier New" size=2><FONT face="Courier New" size=2>Prodevelop SL, Valencia (España)</FONT></DIV>
<DIV>
<DIV><FONT face="Courier New" size=2>Tlf.: 96.351.06.12 -- Fax: 96.351.09.68<BR></FONT><A href="http://www.prodevelop.es/"><FONT face="Courier New" size=2>http://www.prodevelop.es</FONT></A><BR><FONT face="Courier New" size=2>---</FONT></DIV></FONT></DIV></FONT></DIV>
<DIV><BR>
<HR>
<FONT face=Tahoma size=2><B>De:</B> gvsig_desarrolladores-bounces@listserv.gva.es en nombre de Steffen Koch<BR><B>Enviado el:</B> mié 06/10/2010 19:12<BR><B>Para:</B> gvsig_desarrolladores@listserv.gva.es<BR><B>Asunto:</B> Re: [Gvsig_desarrolladores] vista - exportar - imagen - jython<BR></FONT><BR></DIV>
<DIV><BR>
<P><FONT size=2>Hola Juan Lucas,<BR><BR>muchas gracias por tu ayuda, estoy aprendiendo poco a poco. He hecho alguna<BR>pruebas pero todavia no entiendo bien tu scripting, igual estoy un poco<BR>bloqueado. Por ejemplo la linea:<BR>w = vp.fromMapDistance(azu0.getBounds2D().getWidth());<BR>por que no funcionaria solamente azu0.getBounds2D().getWidth(), la funcion<BR>frommapdistance no entiendo bien en este caso. Luego he cambiado los<BR>desplazamientos, como por ejemplo 0, -80 y plus 80. He anandido los<BR>imagenes, al final creo que el tamano del imagen tiene que ser mas pequeno,<BR>no se....<BR><BR>Saludos, steffen<BR><A href="http://osgeo-org.1803224.n2.nabble.com/file/n5607993/plus80_desplazamiento.png">http://osgeo-org.1803224.n2.nabble.com/file/n5607993/plus80_desplazamiento.png</A><BR><A href="http://osgeo-org.1803224.n2.nabble.com/file/n5607993/minus80_desplazamiento.png">http://osgeo-org.1803224.n2.nabble.com/file/n5607993/minus80_desplazamiento.png</A><BR><A href="http://osgeo-org.1803224.n2.nabble.com/file/n5607993/sindesplazamiento.png">http://osgeo-org.1803224.n2.nabble.com/file/n5607993/sindesplazamiento.png</A><BR><A href="http://osgeo-org.1803224.n2.nabble.com/file/n5607993/4azulejos.png">http://osgeo-org.1803224.n2.nabble.com/file/n5607993/4azulejos.png</A><BR>--<BR>View this message in context: <A href="http://osgeo-org.1803224.n2.nabble.com/vista-exportar-imagen-jython-tp5490718p5607993.html">http://osgeo-org.1803224.n2.nabble.com/vista-exportar-imagen-jython-tp5490718p5607993.html</A><BR>Sent from the gvSIG desarrolladores mailing list archive at Nabble.com.<BR>_______________________________________________<BR>gvSIG_desarrolladores mailing list<BR>gvSIG_desarrolladores@listserv.gva.es<BR><A href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_desarrolladores</A><BR></FONT></P></DIV></BODY></HTML>