V1_0.java [src/java/m/watershed/userupload] 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.userupload;
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.*;
/**
* user_upload
*
* @author JK
*/
@Name("userupload")
@Description("userupload")
@Path("m/userupload/1.0")
@Resource(file = "/python/zonalstats_cat.py", type = FILE, id = "zonalstats")
@Resource(file = "gdalwarp", type = REFERENCE, id = "gdalwarp")
@Resource(file = "python", type = REFERENCE, id = "python")
public class V1_0 extends ModelDataService {
File result_file = null;
@Override
protected void doProcess() throws Exception {
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();
String file2 = parameter().getString("raster");
File file_2 = attachments().getFile(file2);
String raster_path = file_2.getPath();
//int no_data = -9999;
File f_1 = resources().getFile("zonalstats");
Executable e = resources().getExe("python");
e.addArguments(f_1.getAbsolutePath(), boundary_path, raster_path, "results_1.csv", "False");
e.exec();
e = resources().getExe("python");
e.addArguments(f_1.getAbsolutePath(), boundary_path, raster_path, "results_cat.csv", "True");
e.exec();
e = resources().getExe("gdalwarp");
e.addArguments(raster_path, wd + "/watershed_whp.tif", "-crop_to_cutline", "-cutline", boundary_path, "-multi");
e.exec();
}
// 3) provide the temperature as a result.
@Override
protected void postProcess() throws Exception {
File ws = workspace().getDir();
results().put(new File(ws, "results_1.csv"), "userfile_1");
results().put(new File(ws, "results_cat.csv"), "userfile_2");
results().put(new File(ws, "watershed_whp.tif"), "userfile_3");
}
}