V1_0.java [src/java/m/watershed/d8flowdir] Revision: default Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package m.watershed.d8flowdir;
import csip.ModelDataService;
import javax.ws.rs.Path;
import csip.annotations.*;
import java.io.*;
import csip.annotations.Resource;
import static csip.annotations.ResourceType.*;
import csip.api.server.Executable;
/**
* flow direction
*
* @author JK (using OD's template)
*/
@Name("d8flowdir")
@Description("Example of eight flow direction")
@Path("m/d8flowdir/1.0")
//@Resource(file = "mpirun", type = REFERENCE, id = "mpirun")
@Resource(file = "/bin/lin-amd64/d8flowdir", type = EXECUTABLE, id = "d8flowdir")
public class V1_0 extends ModelDataService {
// 2) watershed
@Override
protected void doProcess() throws Exception {
String file1 = parameter().getString("dem_fill");
File file_obj = attachments().getFile(file1);
String DEM_fill_path = file_obj.getPath();
String wd = workspace().getDir().toString();
//Executable e = resources().getExe("mpirun");
//File e2 = resources().getFile("d8flowdir");
Executable e = resources().getExe("d8flowdir");
//e.addArguments("-np", "2", "-host", "localhost", e2.getAbsolutePath(), "-fel", DEM_fill_path, "-sd8", wd + "/sd8.tif", "-p", wd +"/p.tif");
e.addArguments("-fel", DEM_fill_path, "-sd8", wd + "/sd8.tif", "-p", wd + "/p.tif");
e.exec();
}
// 3) provide a result.
@Override
protected void postProcess() throws Exception {
File ws = workspace().getDir();
results().put(new File(ws, "sd8.tif"), "slope raster");
results().put(new File(ws, "p.tif"), "flow direction raster");
}
}