lunes, junio 06, 2011

Scripts as algorithms

i have been improving the command-line interface and I have added one new feature that I guess will be interesting for SEXTANTE power users.

The command line interface allows the creation of scripts that can be put in a separate file and then executed with the source(filename) command. If a method is written to to that file, then executing the file will make the method available in the current command-line session.

For instance, if we have a method like the next one,

mymethod(rasterLayer, vectorLayer){
//do something with those layers
}

executing the corresponding file will add a new method calle "mymethod" that I can use anytime.

Since we are running a scripting language, there is no need to specify data types for method parameters. However, now, if you add some information about those types as comments before the method, SEXTANTE can not just execute them from the command line, but also from the toolbox as a normal algorithm.

The above method should be something like this:

//rasterLayer=raster
//vectorLayer=vector
mymethod(rasterLayer, vectorLayer){
//do something with those layer
}

Those two comments are used by SEXTANTE to create the corresponding dialog.

If you put the bsh file in the scripts folder (which now you can define in the settings dialog), the method it contains will appear automatically in the toolbox as any other algorithm or model.

I still have to work more on this and document it, but I guess it's a nice beginning for a rather intereesting idea.

1 comentario:

giohappy dijo...

Thanks Victor, it's a great enhancement!
I've used this facility within MapWindow, a .NET open source GIS, which lets you write-save-load-launch scripts from a console window, and I've found it very usefull for power users.
I think this would be the first implementation of such a feature in the OS gis panorama (except MapWindow).