V1_0.java [src/java/m/watershed/extract_SRTMDEM] 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.extract_SRTMDEM;
import csip.ModelDataService;
import javax.ws.rs.Path;
import csip.annotations.*;
import java.io.*;
import csip.api.server.Executable;
import csip.annotations.Resource;
import static csip.annotations.ResourceType.*;
/**
* Extract SRTM DEM
*
* @author JK (using OD's template)
*/
@Name("extract_SRTMDEM")
@Description("Example of SRTMDEM extraction")
@Resource(file = "gdalwarp", type = REFERENCE, id = "gdalwarp")
@Path("m/extract_SRTMDEM/1.0")
public class V1_0 extends ModelDataService {
// 2) watershed
@Override
protected void doProcess() throws Exception {
String bound_4326 = parameter().getString("bound_wkt");
String[] coord_2 = bound_4326.split(" ");
String[] xy_4326_1 = coord_2[1].split(",");
String x_min_1 = xy_4326_1[1];
String y_min_1 = xy_4326_1[0];
String[] xy_4326_2 = coord_2[2].split(",");
String x_max_1 = xy_4326_2[1];
String y_max_1 = xy_4326_2[0];
String bound_2 = x_min_1 + " " + y_min_1 + " " + x_max_1 + " " + y_max_1;
LOG.info(bound_2);
String wd = workspace().getDir().toString();
Executable e = resources().getExe("gdalwarp");
e.addArguments("/mnt/csip-watershed/srtm_dem.vrt", wd + "/DEM_4326.tif", "-te", x_min_1, y_min_1, x_max_1, y_max_1, "-multi");
e.exec();
e = resources().getExe("gdalwarp");
e.addArguments("-t_srs", "EPSG:3857", wd + "/DEM_4326.tif", wd + "/DEM_clip.tif", "-multi");
e.exec();
}
// 3) provide the temperature as a result.
@Override
protected void postProcess() throws Exception {
String ip = request().getRemoteAddr();
File ws = workspace().getDir();
results().put(new File(ws, "DEM_clip.tif"), "gauged watershed");
}
}