[Gvsig_english] Distance using Jython

Simon Cropper (Botanicus Australia Pty Ltd) scropper at botanicusaustralia.com.au
Thu Dec 10 05:54:13 CET 2009


Hi Juan Lucas,

Thanks for the various links. It is filling in a variety of gaps in my 
knowledge of java, python and scripting.

I followed your instructions and it work as described.

Can you clarify if gvSIG uses the JTS library. I can't see 
acknowledgment of Vivid Solutions in the "About gvSIG" dialog, or is the 
library distributed with Java?

Cheers Simon

Simon Cropper
Botanicus Australia Pty Ltd
PO Box 160, Sunshine, Victoria 3020.
P: 9311 5822. M: 041 830 3437.
mailto: scropper at botanicusaustralia.com.au 
<mailto:scropper at botanicusaustralia.com.au>
web: www.botanicusaustralia.com.au <http://www.botanicusaustralia.com.au>



Juan Lucas Dominguez Rubio wrote:
> Hello.
> To compute the distance between two features of the same layer, you 
> can do this:
>  
> - Add the layer to the view
> - Set the layer as the only active layer (by clicking on it in the TOC)
> - Select the two features for which you wish to know the distance. You 
> must have exactly two features selected
> - Click on the menu option: "File - Scripting - Jython console"
> - Paste this long line:
>  
> 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)
>  
> - Then hit enter and you should see the distance in map units as seen 
> here:
>  
> http://www.prodevelop.es/files/fm/public/downloads/images/jython_dist.jpg
>  
> For a more elegant way to do this, see:
>  
> ftp://downloads.gvsig.org/gva/descargas/manuales/gvsig-1_0-scripting-tutorial-v2-en.zip
>  
> I'm not saying this is the only way to do it, though.
>  
> The script shown above uses the distance function implemented in the 
> widely used JTS library:
>  
> 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%28com.vividsolutions.jts.geom.Geometry>)
>  
>  
> Regards,
>  
> Juan Lucas Domínguez Rubio
> ---
> Prodevelop SL, Valencia (España)
> Tlf.: 96.351.06.12 -- Fax: 96.351.09.68
> http://www.prodevelop.es <http://www.prodevelop.es/>
> ---
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> Gvsig_internacional mailing list
> Gvsig_internacional at listserv.gva.es
> http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional
>   


More information about the Gvsig_internacional mailing list