<body class="mceContentBody " style="DISPLAY: block"><span style="font-size: 9pt;"><span style="font-family: verdana,geneva;"><span style="background-color: transparent;"><span style="color: #000000;"><span style="color: #000000;">Hola Juan Lucas,<br /><br />perfecto ahora funciona y entiendo mejor tu srcipting. Muchas gracias por tu ayuda y tu paciencia.<br /><br />Saludos, Steffen<br /></span></span></span></span></span><span style="font-size: 9pt;"><span style="font-family: verdana,geneva;"><span style="background-color: transparent;"><span style="color: #000000;"><span style="color: #000000;"><br /></span></span></span></span></span><span style="font-size: 9pt;"><span style="font-family: verdana,geneva;"><span style="background-color: transparent;"><span style="color: #000000;"><span style="color: #000000;">
<blockquote style="border-left: 2px solid blue; margin-left: 5px; padding-left: 5px; padding-top: 5px;">
<hr />
<b>Von:</b> "Juan Lucas Dominguez Rubio" &lt;jldominguez@prodevelop.es&gt;<br /><b>Gesendet:</b> 08.10.2010 13:33:12<br /><b>An:</b> "Lista de Desarrolladores de gvSIG" &lt;gvsig_desarrolladores@listserv.gva.es&gt;, gvsig_desarrolladores@listserv.gva.es<br /><b>Betreff:</b> Re: [Gvsig_desarrolladores] vista - exportar - imagen - jython<br /><br />
<div>
<div id="idOWAReplyText13766">
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">Hola, Steffen:</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">Creo que lo que est&aacute;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.</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">Sobre tus dudas:</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">Cuando obtienes una geometr&iacute;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&eacute;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&aacute;ntos pixels ocupa un tile, y qu&eacute; desplazamiento (en pixels) tiene cada tile respecto a los bordes del mapa, etc.</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">He hecho la siguiente prueba:</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">- Cargo una capa WMS (por ejemplo <a href="http://www.gis.nrw.de/wms/DGM50">http://www.gis.nrw.de/wms/DGM50</a>? )</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">- a&ntilde;ado un shapefile </span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">y veo esto:</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;"><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></span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">A continuaci&oacute;n abro una consola de scripting y pego todo este p&aacute;rrafo:</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;"></span>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">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')); </span></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">Debes tener cuidado con el &iacute;ndice de la capa. Creo que los &iacute;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:</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">lyr=mcon.getLayers().getLayer(1);</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">Debe existir una carpeta c:\tempo en tu ordenador, y entonces se crea un archivo c:/tempo/azulejo.png como este:</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;"><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></span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">La explicaci&oacute;n del p&aacute;rrafo es:</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">===================</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// imports</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">import time;</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">from java.awt.image import *;</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">from javax.imageio import ImageIO;</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">from java.io import File;</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">from gvsiglib import *;</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// obtener capa con rectangulos (azulejos o tiles)</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">view = gvSIG.getActiveDocument();</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">mctrl = view.getMapControl();</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">mcon = mctrl.getMapContext();</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">vp = mctrl.getViewPort();</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">lyr=mcon.getLayers().getLayer(1);</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// obtener azulejo 0</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">lyr.getSource().start();</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">indazu = 0;</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">azu0=lyr.getSource().getShape(indazu);</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// obtener tama&ntilde;o del azulejo en la pantalla (en pixels)</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">w = vp.fromMapDistance(azu0.getBounds2D().getWidth());</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">h = vp.fromMapDistance(azu0.getBounds2D().getHeight());</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// craer imagen del mismo tama&ntilde;o (vacia)</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">bimg = BufferedImage(w,h, BufferedImage.TYPE_INT_RGB);</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">graf = bimg.createGraphics();</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// calcular desplazamiento del azulejo con respecto al borde del mapa (en unidades del mapa)</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">offsetxmap = azu0.getBounds2D().getMinX()-vp.getAdjustedExtent().getMinX();</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">offsetymap = vp.getAdjustedExtent().getMaxY()-azu0.getBounds2D().getMaxY();</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// calcular desplazamiento del azulejo con respecto al borde del mapa (en pixels)</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">offsetxpix = vp.fromMapDistance(offsetxmap);</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">offsetypix = vp.fromMapDistance(offsetymap);</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// obtener tama&ntilde;o del mapa completo (vista) en pixels</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">vpwpix = vp.getImageWidth();</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">vphpix = vp.getImageHeight();</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// dibujar el mapa encima de la imagen que tiene mismo tama&ntilde;o que azulejo</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// se usa el desplazamiento. esto es como un "clipping", es decir, la mayor parte</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// de la imagen cae fuera del azulejo</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">graf.drawImage(mctrl.getImage(), -offsetxpix, -offsetypix, vpwpix, vphpix, None);</span></div>
<div>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">// escribir imagen</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">ImageIO.write(bimg,'png',File('c:/tempo/azulejo.png')); </span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;">===================</span></div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;"></span>&nbsp;</div>
<div><span style="font-family: Times New Roman; color: #000000; font-size: small;"></span>&nbsp;</div>
<div>Saludos,</div>
</div>
<div id="idSignature99388">
<div><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Times New Roman; font-size: small;">Juan Lucas Dom&iacute;nguez Rubio<br /></span>---</span></div>
<div><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;"><span style="font-family: Courier New; font-size: x-small;">Prodevelop SL, Valencia (Espa&ntilde;a)</span></span></span></div>
<div>
<div><span style="font-family: Courier New; font-size: x-small;">Tlf.: 96.351.06.12 -- Fax: 96.351.09.68<br /></span><a href="http://www.prodevelop.es/"><span style="font-family: Courier New; font-size: x-small;">http://www.prodevelop.es</span></a><br /><span style="font-family: Courier New; font-size: x-small;">---</span></div>
</div>
</div>
<div><br />
<hr />
<span style="font-family: Tahoma; font-size: x-small;"><b>De:</b> gvsig_desarrolladores-bounces@listserv.gva.es en nombre de Steffen Koch<br /><b>Enviado el:</b> mi&eacute; 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 /></span></div>
<div><br />
<p><span style="font-size: x-small;">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 /></span></p>
</div>
</div>
</blockquote>
</span></span></span></span></span>&nbsp;&nbsp;<br><br><table cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="#000000"><img src="https://img.web.de/p.gif" width="1" height="1" border="0" alt="" /></td></tr><tr><td style="font-family:verdana; font-size:12px; line-height:17px;">Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief!  &nbsp;&nbsp;&nbsp;<br>Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02</td></tr></table>
</body>