<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ojwiki.soldin.de/index.php?action=history&amp;feed=atom&amp;title=Example_Plugin_For_Accessing_Sextante_Algorithms</id>
	<title>Example Plugin For Accessing Sextante Algorithms - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://ojwiki.soldin.de/index.php?action=history&amp;feed=atom&amp;title=Example_Plugin_For_Accessing_Sextante_Algorithms"/>
	<link rel="alternate" type="text/html" href="https://ojwiki.soldin.de/index.php?title=Example_Plugin_For_Accessing_Sextante_Algorithms&amp;action=history"/>
	<updated>2026-08-26T03:21:46Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://ojwiki.soldin.de/index.php?title=Example_Plugin_For_Accessing_Sextante_Algorithms&amp;diff=380&amp;oldid=prev</id>
		<title>Mentaer: Created page with &#039;The following plugin code enables to derive convex hull for a point layer whereby the convexh hull algorithm (minimum enclosing polygon) utilized is taken from the [http://forge.…&#039;</title>
		<link rel="alternate" type="text/html" href="https://ojwiki.soldin.de/index.php?title=Example_Plugin_For_Accessing_Sextante_Algorithms&amp;diff=380&amp;oldid=prev"/>
		<updated>2009-10-22T19:38:45Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;The following plugin code enables to derive convex hull for a point layer whereby the convexh hull algorithm (minimum enclosing polygon) utilized is taken from the [http://forge.…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The following plugin code enables to derive convex hull for a point layer whereby the convexh hull algorithm (minimum enclosing polygon) utilized is taken from the [http://forge.osor.eu/plugins/wiki/index.php?id=13&amp;amp;type=g Sextante] processing libraries. (Note, Sextante actually uses the JTS algorithm, which is also used in our standard implementation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
package org.openjump.core.ui.plugin.tools;&lt;br /&gt;
&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
&lt;br /&gt;
import javax.swing.JComboBox;&lt;br /&gt;
&lt;br /&gt;
import com.vividsolutions.jts.geom.GeometryFactory;&lt;br /&gt;
import com.vividsolutions.jump.feature.FeatureCollection;&lt;br /&gt;
import com.vividsolutions.jump.task.TaskMonitor;&lt;br /&gt;
import com.vividsolutions.jump.workbench.WorkbenchContext;&lt;br /&gt;
import com.vividsolutions.jump.workbench.model.Layer;&lt;br /&gt;
import com.vividsolutions.jump.workbench.model.StandardCategoryNames;&lt;br /&gt;
import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;&lt;br /&gt;
import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;&lt;br /&gt;
import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;&lt;br /&gt;
import com.vividsolutions.jump.workbench.plugin.PlugInContext;&lt;br /&gt;
import com.vividsolutions.jump.workbench.plugin.ThreadedPlugIn;&lt;br /&gt;
import com.vividsolutions.jump.workbench.ui.GUIUtil;&lt;br /&gt;
import com.vividsolutions.jump.workbench.ui.MultiInputDialog;&lt;br /&gt;
import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;&lt;br /&gt;
&lt;br /&gt;
import es.unex.sextante.core.OutputFactory;&lt;br /&gt;
import es.unex.sextante.core.OutputObjectsSet;&lt;br /&gt;
import es.unex.sextante.core.ParametersSet;&lt;br /&gt;
import es.unex.sextante.core.Sextante;&lt;br /&gt;
import es.unex.sextante.dataObjects.IVectorLayer;&lt;br /&gt;
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;&lt;br /&gt;
import es.unex.sextante.openjump.core.OpenJUMPOutputFactory;&lt;br /&gt;
import es.unex.sextante.openjump.core.OpenJUMPVectorLayer;&lt;br /&gt;
import es.unex.sextante.outputs.Output;&lt;br /&gt;
import es.unex.sextante.parameters.Parameter;&lt;br /&gt;
import es.unex.sextante.vectorTools.minimumEnclosingPolygon.MinimumEnclosingPolygonAlgorithm;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @description: OpenJUMP plugin to demonstrate the utilization and access to Sextante algorithms&lt;br /&gt;
 *	&lt;br /&gt;
 * @author sstein&lt;br /&gt;
 *&lt;br /&gt;
 **/&lt;br /&gt;
public class SextanteTestPlugIn extends AbstractPlugIn implements ThreadedPlugIn{&lt;br /&gt;
&lt;br /&gt;
    private String sSidebar =&amp;quot;Testplugin that uses an algorithm that generates a convex hull (i.e. minimum enclosing polygon) from Sextante&amp;quot;;   &lt;br /&gt;
    private final String sLAYERPTS = &amp;quot;Layer with Point Geometries&amp;quot;;    &lt;br /&gt;
    private Layer input = null;&lt;br /&gt;
    private MultiInputDialog dialog;&lt;br /&gt;
    private PlugInContext context = null;&lt;br /&gt;
    &lt;br /&gt;
    GeometryFactory gfactory = new GeometryFactory();&lt;br /&gt;
        &lt;br /&gt;
    public void initialize(PlugInContext context) throws Exception {&lt;br /&gt;
    				&lt;br /&gt;
	        FeatureInstaller featureInstaller = new FeatureInstaller(context.getWorkbenchContext());&lt;br /&gt;
	    	featureInstaller.addMainMenuItem(&lt;br /&gt;
	    	        this,								//exe&lt;br /&gt;
	                new String[] {&amp;quot;OJ-Sextante&amp;quot;}, 	//menu path&lt;br /&gt;
	                &amp;quot;Sextante Test Plugin&amp;quot;, &lt;br /&gt;
	                //AbstractPlugIn.createName(CalculateMinimumConvexPolygonPlugIn.class),&lt;br /&gt;
	                false,			//checkbox&lt;br /&gt;
	                null,			//icon&lt;br /&gt;
	                createEnableCheck(context.getWorkbenchContext())); //enable check&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static MultiEnableCheck createEnableCheck(WorkbenchContext workbenchContext) {&lt;br /&gt;
        EnableCheckFactory checkFactory = new EnableCheckFactory(workbenchContext);&lt;br /&gt;
&lt;br /&gt;
        return new MultiEnableCheck()&lt;br /&gt;
                        .add(checkFactory.createAtLeastNLayersMustExistCheck(1));&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
	public boolean execute(PlugInContext context) throws Exception{&lt;br /&gt;
        //Unlike ValidatePlugIn, here we always call #initDialog because we want&lt;br /&gt;
        //to update the layer comboboxes.&lt;br /&gt;
        initDialog(context);&lt;br /&gt;
        dialog.setVisible(true);&lt;br /&gt;
        if (!dialog.wasOKPressed()) {&lt;br /&gt;
            return false;&lt;br /&gt;
        }&lt;br /&gt;
        else{&lt;br /&gt;
        	this.getDialogValues(dialog); &lt;br /&gt;
        }&lt;br /&gt;
        return true;	    &lt;br /&gt;
	}&lt;br /&gt;
    &lt;br /&gt;
    public void run(TaskMonitor monitor, PlugInContext context) throws Exception{            		&lt;br /&gt;
	    	System.gc(); //flush garbage collector&lt;br /&gt;
	    	this.context = context;&lt;br /&gt;
	    	monitor.allowCancellationRequests();&lt;br /&gt;
	    	FeatureCollection resultC = this.calculateHull(this.input, context, monitor);&lt;br /&gt;
	        if(resultC != null){&lt;br /&gt;
	        	context.addLayer(StandardCategoryNames.RESULT, this.input.getName() + &amp;quot;-hull&amp;quot;, resultC);&lt;br /&gt;
	        }&lt;br /&gt;
    	    System.gc();    		&lt;br /&gt;
    	}&lt;br /&gt;
&lt;br /&gt;
	private void initDialog(PlugInContext context) {&lt;br /&gt;
    	&lt;br /&gt;
        dialog = new MultiInputDialog(context.getWorkbenchFrame(), &amp;quot;Generate Hull&amp;quot;, true);&lt;br /&gt;
        dialog.setSideBarDescription(sSidebar);&lt;br /&gt;
        try {&lt;br /&gt;
        	JComboBox addLayerComboBoxRegions = dialog.addLayerComboBox(this.sLAYERPTS, context.getCandidateLayer(0), null, context.getLayerManager());&lt;br /&gt;
        }&lt;br /&gt;
        catch (IndexOutOfBoundsException e) {}&lt;br /&gt;
        GUIUtil.centreOnWindow(dialog);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    private void getDialogValues(MultiInputDialog dialog) {&lt;br /&gt;
    	this.input =  dialog.getLayer(this.sLAYERPTS); &lt;br /&gt;
      }&lt;br /&gt;
    &lt;br /&gt;
	private FeatureCollection calculateHull(Layer stefanspoints,&lt;br /&gt;
			PlugInContext context, TaskMonitor monitor) &lt;br /&gt;
			throws GeoAlgorithmExecutionException, IOException {&lt;br /&gt;
		&lt;br /&gt;
		OutputFactory outputFactory = new OpenJUMPOutputFactory(context.getWorkbenchContext());&lt;br /&gt;
		&lt;br /&gt;
		monitor.report(&amp;quot;initialize sextante&amp;quot;);&lt;br /&gt;
		Sextante.initialize();&lt;br /&gt;
		&lt;br /&gt;
		monitor.report(&amp;quot;prepare computation&amp;quot;);&lt;br /&gt;
		OpenJUMPVectorLayer layer = new OpenJUMPVectorLayer();&lt;br /&gt;
		layer.create(stefanspoints);&lt;br /&gt;
		MinimumEnclosingPolygonAlgorithm alg = new MinimumEnclosingPolygonAlgorithm();&lt;br /&gt;
		&lt;br /&gt;
		ParametersSet params = alg.getParameters();&lt;br /&gt;
		Parameter layerParam = (Parameter)params.getParameter(MinimumEnclosingPolygonAlgorithm.POINTS);&lt;br /&gt;
		boolean worked = layerParam.setParameterValue(layer);&lt;br /&gt;
		if(worked){&lt;br /&gt;
			//method values: 0 - for convex hull, 1 - for circle, 2 - envelope&lt;br /&gt;
			params.getParameter(MinimumEnclosingPolygonAlgorithm.METHOD).setParameterValue(new Integer(2));&lt;br /&gt;
			params.getParameter(MinimumEnclosingPolygonAlgorithm.USECLASSES).setParameterValue(false);&lt;br /&gt;
			//-- not sure why the following param needs to be set, if I set false before&lt;br /&gt;
			params.getParameter(MinimumEnclosingPolygonAlgorithm.FIELD).setParameterValue(new Integer(0));&lt;br /&gt;
			&lt;br /&gt;
			OutputObjectsSet outputs = alg.getOutputObjects();&lt;br /&gt;
			Output polygon = outputs.getOutput(MinimumEnclosingPolygonAlgorithm.RESULT);&lt;br /&gt;
			monitor.report(&amp;quot;computation&amp;quot;);&lt;br /&gt;
			alg.execute(null, outputFactory);&lt;br /&gt;
			&lt;br /&gt;
			monitor.report(&amp;quot;retrieving results&amp;quot;);&lt;br /&gt;
			IVectorLayer result = (IVectorLayer)polygon.getOutputObject();&lt;br /&gt;
			Layer resultOJLayer = (Layer)result.getBaseDataObject();&lt;br /&gt;
			return resultOJLayer.getFeatureCollectionWrapper().getWrappee();&lt;br /&gt;
		}&lt;br /&gt;
		else{&lt;br /&gt;
			context.getWorkbenchFrame().warnUser(&amp;quot;layer not a point layer; has ShapeType: &amp;quot; + layer.getShapeType());&lt;br /&gt;
			return null;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
  &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mentaer</name></author>
	</entry>
</feed>