V1_0.java [src/java/m/watershed/gage_watershed] 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.gage_watershed;
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;
/**
* gage_watershed
*
* @author JK (using OD's template)
*/
@Name("gage_watershed")
@Description("Example of gage watershed")
@Path("m/gage_watershed/1.0")
@Resource(file = "ogr2ogr", type = REFERENCE, id = "ogr")
//@Resource(file = "mpirun", type = REFERENCE, id = "mpirun")
@Resource(file = "gdal_polygonize.py", type = REFERENCE, id = "gdal_polygonize")
@Resource(file = "/bin/lin-amd64/gagewatershed", type = EXECUTABLE, id = "gagewatershed")
public class V1_0 extends ModelDataService {
// 2) watershed
@Override
protected void doProcess() throws Exception {
String file1 = parameter().getString("flow_dir");
File file_1 = attachments().getFile(file1);
String flow_dir_path = file_1.getPath();
String file2 = parameter().getString("outlet");
File file_2 = attachments().getFile(file2);
String input_outlet_path = file_2.getPath();
String wd = workspace().getDir().toString();
Executable e = resources().getExe("gagewatershed");
e.addArguments("-p", flow_dir_path, "-o", input_outlet_path, "-gw", wd + "/gage_watershed.tif", "-id", wd + "/idfile.txt");
e.exec();
e = resources().getExe("gdal_polygonize");
e.addArguments(wd + "/gage_watershed.tif", "-f", "ESRI Shapefile", wd + "/b_watershed.shp");
e.exec();
e = resources().getExe("ogr");
e.addArguments("-t_srs", "EPSG:4326", wd + "/total_watershed.shp", wd + "/b_watershed.shp");
e.exec();
}
// 3) provide the temperature as a result.
@Override
protected void postProcess() throws Exception {
File ws = workspace().getDir();
results().put(new File(ws, "idfile.txt"), "id file");
results().put(new File(ws, "gage_watershed.tif"), "gauged watershed");
results().put(new File(ws, "total_watershed.dbf"), "total watershed");
results().put(new File(ws, "total_watershed.shx"), "total watershed");
results().put(new File(ws, "total_watershed.shp"), "total watershed");
}
}