SoilParamsAoA.java [src/java/d/soils/wwe01_wwesoilparams] 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 d.soils.wwe01_wwesoilparams;
import csip.api.server.ServiceException;
import csip.SessionLogger;
import gisobjects.GISObject;
import gisobjects.GISObjectException;
import static gisobjects.GISObjectFactory.createGISObject;
import static gisobjects.GISObjectFactory.setFixBadGeometries;
import gisobjects.db.GISEngine;
import gisobjects.db.GISEngineFactory;
import static gisobjects.db.GISEngineFactory.createGISEngine;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import soils.MapUnit;
import soils.db.SOILS_DATA;
/**
*
* @author scase
*/
public abstract class SoilParamsAoA extends soils.AoA {
protected String mupolygonkey = "";
protected GISEngine gisEngine = null;
public SoilParamsAoA(SOILS_DATA soilsDb, Connection gisDb, JSONObject geometry, SessionLogger LOG) throws GISObjectException, SQLException, JSONException, IOException, ServiceException {
super(soilsDb, LOG);
setFixBadGeometries(true);
gisEngine = createGISEngine(gisDb);
shape = createGISObject(geometry, gisEngine);
shape.makeValid(GISObject.UsePurpose.all_purposes, GISObject.GISType.all_types);
// String wkt = shape.toWKT();
// if (!tEngine.isSQLValidGeometry(wkt)) {
// shape = createGISObject(tEngine.makeValidGeometry(wkt), tEngine);
// shape.hasChanged(true);
// }
area = shape.areaInAcres();
if (area > 10000.0) {
throw new ServiceException("Feature specified has an area greater than 10,000 acres. Area is too large.");
}
// Is it only a POINT? (We don't allow this anymore)
if (shape.toWKT().toUpperCase().contains("POINT")) {
throw new ServiceException("Feature specified has a location specified that is a point value, not a polygon. This version does not allow point locations.");
}
}
public SoilParamsAoA(SOILS_DATA soilsDb, Connection gisDb, String mupolygonkey, SessionLogger LOG) throws GISObjectException, SQLException, JSONException, IOException, ServiceException {
super(soilsDb, LOG);
setFixBadGeometries(true);
shape = null;
area = 0.0;
gisEngine = GISEngineFactory.createGISEngine(gisDb);
this.mupolygonkey = mupolygonkey;
}
public abstract void findSoils() throws SQLException, ServiceException, GISObjectException;
protected abstract void setOutputs(MapUnit mapUnit) throws ServiceException;
public JSONArray toJSON() throws JSONException, ServiceException {
JSONArray mapunitData = new JSONArray();
for (MapUnit mapUnit : map_units.values()) {
if (!mapUnit.isExcluded()) {
setOutputs(mapUnit);
mapunitData.put(mapUnit.toJSON(true, new ArrayList<>(Arrays.asList("WATER", "WIND"))));
}
}
return mapunitData;
}
}