<HTML dir=ltr><HEAD><TITLE>Re: [Gvsig_english] Distance using Jython</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.16945" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText43501 dir=ltr>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>Hello, Simon:</FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr>JTS is briefly mentioned and praised in the credits dialog: 'Help - About - gvSIG tab' (pull down scroll bar). The word 'VividSolutions' does not appear, but there is a direct link to their website.</DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr>> Can you clarify if gvSIG uses the JTS library?</DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr>Sure it does. I would rather say that gvSIG was born in the lap of JTS :)</DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr>Regards,</DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3></FONT> </DIV></DIV>
<DIV id=idSignature93034 dir=ltr>
<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 dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>De:</B> gvsig_internacional-bounces@listserv.gva.es en nombre de Simon Cropper (Botanicus Australia Pty Ltd)<BR><B>Enviado el:</B> jue 10/12/2009 5:54<BR><B>Para:</B> Users and Developers mailing list<BR><B>Asunto:</B> Re: [Gvsig_english] Distance using Jython<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2>Hi Juan Lucas,<BR><BR>Thanks for the various links. It is filling in a variety of gaps in my<BR>knowledge of java, python and scripting.<BR><BR>I followed your instructions and it work as described.<BR><BR>Can you clarify if gvSIG uses the JTS library. I can't see<BR>acknowledgment of Vivid Solutions in the "About gvSIG" dialog, or is the<BR>library distributed with Java?<BR><BR>Cheers Simon<BR><BR>Simon Cropper<BR>Botanicus Australia Pty Ltd<BR>PO Box 160, Sunshine, Victoria 3020.<BR>P: 9311 5822. M: 041 830 3437.<BR>mailto: scropper@botanicusaustralia.com.au<BR><<A href="mailto:scropper@botanicusaustralia.com.au">mailto:scropper@botanicusaustralia.com.au</A>><BR>web: www.botanicusaustralia.com.au <<A href="http://www.botanicusaustralia.com.au/">http://www.botanicusaustralia.com.au</A>><BR><BR><BR><BR>Juan Lucas Dominguez Rubio wrote:<BR>> Hello.<BR>> To compute the distance between two features of the same layer, you<BR>> can do this:<BR>> <BR>> - Add the layer to the view<BR>> - Set the layer as the only active layer (by clicking on it in the TOC)<BR>> - Select the two features for which you wish to know the distance. You<BR>> must have exactly two features selected<BR>> - Click on the menu option: "File - Scripting - Jython console"<BR>> - Paste this long line:<BR>> <BR>> import com.iver.andami; import com.iver.andami.ui.mdiManager; v =<BR>> com.iver.andami.PluginServices.getMDIManager().getActiveWindow(); mc =<BR>> v.getMapControl(); mx = mc.getMapContext(); lyrs = mx.getLayers();<BR>> lyract = lyrs.getActives()[0]; selsup = lyract.getSelectionSupport();<BR>> sel = selsup.getSelection(); firstsel = sel.nextSetBit(0); secondsel =<BR>> sel.nextSetBit(firstsel+1); vf = lyract.getSource(); fgeom =<BR>> vf.getShape(firstsel); sgeom = vf.getShape(secondsel); fjtsgeom =<BR>> fgeom.toJTSGeometry(); sjtsgeom = sgeom.toJTSGeometry();<BR>> fjtsgeom.distance(sjtsgeom)<BR>> <BR>> - Then hit enter and you should see the distance in map units as seen<BR>> here:<BR>> <BR>> <A href="http://www.prodevelop.es/files/fm/public/downloads/images/jython_dist.jpg">http://www.prodevelop.es/files/fm/public/downloads/images/jython_dist.jpg</A><BR>> <BR>> For a more elegant way to do this, see:<BR>> <BR>> <A href="ftp://downloads.gvsig.org/gva/descargas/manuales/gvsig-1_0-scripting-tutorial-v2-en.zip">ftp://downloads.gvsig.org/gva/descargas/manuales/gvsig-1_0-scripting-tutorial-v2-en.zip</A><BR>> <BR>> I'm not saying this is the only way to do it, though.<BR>> <BR>> The script shown above uses the distance function implemented in the<BR>> widely used JTS library:<BR>> <BR>> <A href="http://www.vividsolutions.com/Jts/javadoc/com/vividsolutions/jts/geom/Geometry.html#distance(com.vividsolutions.jts.geom.Geometry">http://www.vividsolutions.com/Jts/javadoc/com/vividsolutions/jts/geom/Geometry.html#distance(com.vividsolutions.jts.geom.Geometry</A><BR>> <<A href="http://www.vividsolutions.com/Jts/javadoc/com/vividsolutions/jts/geom/Geometry.html#distance%28com.vividsolutions.jts.geom.Geometry">http://www.vividsolutions.com/Jts/javadoc/com/vividsolutions/jts/geom/Geometry.html#distance%28com.vividsolutions.jts.geom.Geometry</A>>)<BR>> <BR>> <BR>> Regards,<BR>> <BR>> Juan Lucas Domínguez Rubio<BR>> ---<BR>> Prodevelop SL, Valencia (España)<BR>> Tlf.: 96.351.06.12 -- Fax: 96.351.09.68<BR>> <A href="http://www.prodevelop.es/">http://www.prodevelop.es</A> <<A href="http://www.prodevelop.es/">http://www.prodevelop.es/</A>><BR>> ---<BR>> <BR>> ------------------------------------------------------------------------<BR>><BR>> _______________________________________________<BR>> Gvsig_internacional mailing list<BR>> Gvsig_internacional@listserv.gva.es<BR>> <A href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</A><BR>> <BR>_______________________________________________<BR>Gvsig_internacional mailing list<BR>Gvsig_internacional@listserv.gva.es<BR><A href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</A><BR></FONT></P></DIV></BODY></HTML>