<HTML dir=ltr><HEAD>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.16939" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText5085 dir=ltr>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>Hello.</FONT></DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>To compute the distance between two features of the same layer, you can do this:</FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>- Add the layer to the view</FONT></DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>- Set the layer as the only active layer (by clicking on it in the TOC)</FONT></DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>- Select the two features for which you wish to know the distance. You must have exactly two features selected</FONT></DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>- Click on the menu option: "File - Scripting - Jython console"</FONT></DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>- Paste this long line:</FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>import com.iver.andami; import com.iver.andami.ui.mdiManager; v = com.iver.andami.PluginServices.getMDIManager().getActiveWindow(); mc = v.getMapControl(); mx = mc.getMapContext(); lyrs = mx.getLayers(); lyract = lyrs.getActives()[0]; selsup = lyract.getSelectionSupport(); sel = selsup.getSelection(); firstsel = sel.nextSetBit(0); secondsel = sel.nextSetBit(firstsel+1); vf = lyract.getSource(); fgeom = vf.getShape(firstsel); sgeom = vf.getShape(secondsel); fjtsgeom = fgeom.toJTSGeometry(); sjtsgeom = sgeom.toJTSGeometry(); fjtsgeom.distance(sjtsgeom)</FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>- Then hit enter and you should see the distance in map units as seen here:</FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3><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></FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>For a more elegant way to do this, see:</FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3><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></FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>I'm not saying this is the only way to do it, though.</FONT></DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3></FONT> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>The script shown above uses the distance function implemented in the widely used JTS library:</FONT></DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><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>)</DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr> </DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3>Regards,</FONT></DIV>
<DIV dir=ltr><FONT face="Times New Roman" color=#000000 size=3></FONT> </DIV></DIV>
<DIV id=idSignature42558 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><FONT size=2></FONT> </DIV></BODY></HTML>