V1_0.java [src/java/m/watershed/cost_distance] 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.cost_distance;
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.*;
/**
* cost distance
*
* @author JK (using OD's template)
*/
@Name("cost_distance")
@Description("cost_distance")
@Path("m/cost_distance/1.0")
@Resource(file = "/python/cost_distance.py", type = FILE, id = "cost_distance")
@Resource(file = "gdalwarp", type = REFERENCE, id = "gdalwarp")
@Resource(file = "python", type = REFERENCE, id = "python")
public class V1_0 extends ModelDataService {
File result_file = null;
// 2) watershed
@Override
protected void doProcess() throws Exception {
File ws = workspace().getDir();
String wd = ws.toString();
String file1 = parameter().getString("cost_raster");
File file_1 = attachments().getFile(file1);
String cr_path = file_1.getPath();
/*Executable e = resources().getExe("gdalwarp");
e.addArguments("-t_srs", "EPSG:5070", cr_path, wd+"/cost_5070.tif", "-multi");
e.exec();*/
Executable e = resources().getExe("gdalwarp");
e.addArguments("-t_srs", "EPSG:4326", cr_path, wd + "/cost_4326.tif", "-multi");
e.exec();
String x_start_gcs = parameter().getString("x_start_gcs");
String y_start_gcs = parameter().getString("y_start_gcs");
String x_end_gcs = parameter().getString("x_end_gcs");
String y_end_gcs = parameter().getString("y_end_gcs");
File f_1 = resources().getFile("cost_distance");
e = resources().getExe("python");
e.addArguments(f_1.getAbsolutePath(), cr_path, wd + "/cost_4326.tif", wd + "/output.tif", wd + "/output_4326.tif", x_start_gcs, y_start_gcs, x_end_gcs, y_end_gcs);
e.exec();
}
// 3) provide the temperature as a result.
@Override
protected void postProcess() throws Exception {
File ws = workspace().getDir();
results().put(new File(ws, "output.tif"), "cost distance");
results().put(new File(ws, "result.csv"), "cost distance");
}
}