V1_0.java [src/java/m/watershed/slope] 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.slope;
import csip.api.server.Executable;
import csip.ModelDataService;
import csip.annotations.Resource;
import static csip.annotations.ResourceType.*;
import javax.ws.rs.Path;
import csip.annotations.*;
import java.io.*;
/**
* slope
*
* @author JK (using OD's template)
*/
@Name("slope")
@Description("Example of slope")
@Path("m/slope/1.0")
@Resource(file = "/python/zonalstats.py", type = FILE, id = "zonalstats")
@Resource(file = "gdalwarp", type = REFERENCE, id = "gdalwarp")
@Resource(file = "ogr2ogr", type = REFERENCE, id = "ogr")
//@Resource(file = "mpirun", type = REFERENCE, id = "mpirun")
@Resource(file = "python", type = REFERENCE, id = "python")
@Resource(file = "/bin/lin-amd64/pitremove", type = EXECUTABLE, id = "pitremove")
@Resource(file = "/bin/lin-amd64/d8flowdir", type = EXECUTABLE, id = "d8flowdir")
public class V1_0 extends ModelDataService {
File result_file = null;
// 2) watershed
@Override
protected void doProcess() throws Exception {
String ip = request().getRemoteAddr();
//if ("127.0.0.1".equals(ip)){
File ws = workspace().getDir();
String wd = ws.toString();
String file1 = parameter().getString("boundary");
File file_1 = attachments().getFile(file1);
String boundary_path = file_1.getPath();
Executable e = resources().getExe("ogr");
e.addArguments("-t_srs", "EPSG:5070", "-s_srs", "EPSG:4326", wd + "/boundary.shp", boundary_path);
e.exec();
String x_min = parameter().getString("l");
String y_min = parameter().getString("b");
String x_max = parameter().getString("r");
String y_max = parameter().getString("t");
e = resources().getExe("gdalwarp");
e.addArguments("/mnt/csip-watershed/DEM.vrt", wd + "/DEM_clip.tif", "-te", x_min, y_min, x_max, y_max, "-multi");
e.exec();
//e = resources().getExe("mpirun");
//File e2 = resources().getFile("pitremove");
e = resources().getExe("pitremove");
//e.addArguments("-np", "2", "-host", "localhost", e2.getAbsolutePath(), "-z", wd+ "/DEM_clip.tif", "-fel", wd + "/dem_fill.tif");
e.addArguments("-z", wd + "/DEM_clip.tif", "-fel", wd + "/dem_fill.tif");
e.exec();
//e = resources().getExe("mpirun");
//e2 = resources().getFile("d8flowdir");
e = resources().getExe("d8flowdir");
//e.addArguments("-np", "2", "-host", "localhost", e2.getAbsolutePath(), "-fel", wd+ "/dem_fill.tif", "-sd8", wd + "/sd8.tif", "-p", wd + "/p.tif");
e.addArguments("-fel", wd + "/dem_fill.tif", "-sd8", wd + "/sd8.tif", "-p", wd + "/p.tif");
e.exec();
File f_1 = resources().getFile("zonalstats");
e = resources().getExe("python");
e.addArguments(f_1.getAbsolutePath(), wd + "/boundary.shp", wd + "/sd8.tif");
e.exec();
}
// 3) provide the temperature as a result.
@Override
protected void postProcess() throws Exception {
File ws = workspace().getDir();
results().put(new File(ws, "sd8.tif"), "cutoff direction");
results().put(new File(ws, "results.csv"), "cutoff direction");
}
}