GIS_DB.java [src/java/adb] 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 adb;

import gisobjects.GISObject;
import csip.api.server.ServiceException;
import csip.utils.JSONUtils;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import soils.MapUnit;
import soils.db.SOILS_DATA;


/**
 *
 * @author Shaun Case
 */
public interface GIS_DB extends AutoCloseable {

    public static final String DEFAULT_GEOG_SRID = "4326";

    public static class FileQryResult {

        public String id;
        public String file_path;
        public String file_name;

        @Override
        public String toString() {
            return "{" + id + "|" + file_path + "|" + file_name + "}";
        }
    }

    public static class Soil {

        public String coFips;
        public String muSym;
        public String muKey;
        public String r2Path;
        public String r2Name;
        public String wepsPath;
        public String wepsName;
        public String muName;
        public String compName;
        public String kffact;
        public double tfact;
        public static final String TFACT_UNITS = "ton/acre/year";
        public double lengthR = 0.0;
        public static final String LENGTHR_UNITS = "feet";
        public double slopeR;
        public static final String SLOPER_UNITS = "%";
        public double sandtotalR;
        public static final String SANDTOTALR_UNITS = "%";
        public String coKey;
        public double percentAoi;
        public static final String PERCENTAOI_UNITS = "percent";
        public double sizeAoi;
        public static final String SIZEAOI_UNITS = "acres";
        public double perWind = 0.0;
        public static final String PERWIND_UNITS = "ton/acre/year";
        public double perWater = 0.0;
        public static final String PERWATER_UNITS = "ton/acre/year";

        public JSONArray toJSONSand() throws JSONException {
            JSONArray resultJSON = new JSONArray();

            resultJSON.put(JSONUtils.data("ssurgo_mukey", muKey));
            resultJSON.put(JSONUtils.data("ssurgo_cokey", coKey));
            resultJSON.put(JSONUtils.data("ssurgo_areasymbol", coFips));
            resultJSON.put(JSONUtils.data("ssurgo_compname", compName));
            resultJSON.put(JSONUtils.data("ssurgo_kffact", kffact));
            resultJSON.put(JSONUtils.data("ssurgo_tfact", tfact, TFACT_UNITS));
            resultJSON.put(JSONUtils.data("ssurgo_muname", muName));
            resultJSON.put(JSONUtils.data("ssurgo_musym", muSym));
            resultJSON.put(JSONUtils.data("per_water", perWater, PERWATER_UNITS));
            resultJSON.put(JSONUtils.data("per_wind", perWind, PERWIND_UNITS));
            resultJSON.put(JSONUtils.data("r2_r2name", r2Name));
            resultJSON.put(JSONUtils.data("r2_r2path", r2Path));
            resultJSON.put(JSONUtils.data("length_r", lengthR, LENGTHR_UNITS));
            resultJSON.put(JSONUtils.data("ssurgo_slopeR", slopeR, SLOPER_UNITS));
            resultJSON.put(JSONUtils.data("ssurgo_sandtotalR", sandtotalR, SANDTOTALR_UNITS));
            resultJSON.put(JSONUtils.data("percent_of_aoi", percentAoi, PERCENTAOI_UNITS));
            resultJSON.put(JSONUtils.data("acres_in_aoi", sizeAoi, SIZEAOI_UNITS));

            return resultJSON;
        }

        public JSONArray toJSONWeps() throws JSONException {
            JSONArray resultJSON = new JSONArray();

            resultJSON.put(JSONUtils.data("ssurgo_cokey", coKey));
            resultJSON.put(JSONUtils.data("ssurgo_mukey", muKey));
            resultJSON.put(JSONUtils.data("ssurgo_areasymbol", coFips));
            resultJSON.put(JSONUtils.data("ssurgo_compname", compName));
            resultJSON.put(JSONUtils.data("ssurgo_kffact", kffact));
            resultJSON.put(JSONUtils.data("ssurgo_tfact", tfact, TFACT_UNITS));
            resultJSON.put(JSONUtils.data("ssurgo_muname", muName));
            resultJSON.put(JSONUtils.data("ssurgo_musym", muSym));
            resultJSON.put(JSONUtils.data("per_water", perWater, PERWATER_UNITS));
            resultJSON.put(JSONUtils.data("per_wind", perWind, PERWIND_UNITS));
            resultJSON.put(JSONUtils.data("weps_name", wepsName));
            resultJSON.put(JSONUtils.data("weps_path", wepsPath));
            resultJSON.put(JSONUtils.data("length_r", lengthR, LENGTHR_UNITS));
            resultJSON.put(JSONUtils.data("ssurgo_slopeR", slopeR, SLOPER_UNITS));
//            resultJSON.put(JSONUtils.data("ssurgo_sandtotalR", sandtotalR, sandtotalRUnits));
            resultJSON.put(JSONUtils.data("percent_of_aoi", percentAoi, PERCENTAOI_UNITS));
            resultJSON.put(JSONUtils.data("acres_in_aoi", sizeAoi, SIZEAOI_UNITS));

            return resultJSON;
        }
    }

    public static class StationResult {

        public String country;
        public String state;
        public String name;
        public String stationId;
        public String stationX;
        public String stationY;
        public double distance;
        public String elevation;

        @Override
        public String toString() {
            return "{" + state + "|" + stationId + "|" + stationX + "|" + stationY + "|" + elevation + "}";
        }
    }

    public static class County {

        public String st_abbr;
        public String county_code;
        public String name;
        public String county_centroid_X;
        public String county_centroid_Y;

        @Override
        public String toString() {
            return "{" + st_abbr + county_code + "|" + name + "|" + county_centroid_X + "|" + county_centroid_Y + "}";
        }
    }

    // Look up table for slope length 
    static final double[][] LightleWeesiesSlopeLength = {{0, .75, 100},
    {.75, 1.5, 200},
    {1.5, 2.5, 300},
    {2.5, 3.5, 200},
    {3.5, 4.5, 180},
    {4.5, 5.5, 160},
    {5.5, 6.5, 150},
    {6.5, 7.5, 140},
    {7.5, 8.5, 130},
    {8.5, 9.5, 125},
    {9.5, 10.5, 120},
    {10.5, 11.5, 110},
    {11.5, 12.5, 100},
    {12.5, 13.5, 90},
    {13.5, 14.5, 80},
    {14.5, 15.5, 70},
    {15.5, 17.5, 60},
    {17.5, -1, 50}};
    static final double[][] PalouseSlopeLength = {{0, 5.5, 350},
    {5.5, 10.5, 275},
    {10.5, 15.5, 225},
    {15.5, 20.5, 175},
    {20.5, 25.5, 150},
    {25.5, 35.5, 125},
    {35.5, -1, 100}};
    static final List<String> PalouseAreas = Arrays.asList("ID607", "ID610", "OR021", "OR049", "OR055", "OR625",
            "OR667", "OR670", "OR673", "WA001", "WA021", "WA025",
            "WA043", "WA063", "WA071", "WA075", "WA603", "WA605",
            "WA613", "WA617", "WA623", "WA639", "WA676", "WA677");

    public boolean IsValidCliCoord(double lat, double lon) throws SQLException;

    public boolean IsValidManCoord(double lat, double lon) throws SQLException;

    public boolean IsValidSoiCoord(double lat, double lon) throws SQLException;

    public boolean IsValidGisCoord(double lat, double lon) throws SQLException;

    public boolean IsValidRusle2Soil(double lat, double lon) throws SQLException;

    public boolean IsValidWepsSoil(double lat, double lon) throws SQLException;

    public boolean IsInInterpolateBoundary(double lat, double lon) throws SQLException;

    public FileQryResult findSoils(double lat, double lon) throws SQLException;

    public FileQryResult findSoilsByCokey(String cokey, double lon) throws SQLException;

    public Collection<Soil> findSoilsForPolygon(String _polygon, double poly_longitude) throws SQLException;

    public Collection<Soil> findSoilsForPolygonWithSand(String _polygon, double poly_longitude) throws SQLException;

    public HashMap<String, MapUnit> findSoilsForPolygonWithSand(GISObject gisObject, double poly_longitude) throws SQLException, ServiceException;

    public Collection<Soil> findSoilsForPolygonWeps(String _polygon, double poly_longitude) throws SQLException;

    public FileQryResult findSoilsWeps(double lat, double lon) throws SQLException;

    public FileQryResult findSoilsWepsByCokey(String cokey, double lon) throws SQLException;

    public FileQryResult findClimate(double lat, double lon) throws SQLException;

    public County findCounty(double lat, double lon) throws SQLException;

    public StationResult findCligenStation(double lat, double lon) throws SQLException;

    public StationResult findWindgenStation(double lat, double lon) throws SQLException;

    public StationResult cliGeomIntersect(double lat, double lon) throws SQLException;

    public StationResult windGeomIntersect(double lat, double lon) throws SQLException;

    public County countyCentroid(double lat, double lon) throws SQLException;

    public String findCmz(double lat, double lon) throws SQLException;

    public List<FileQryResult> findManagements(double lat, double lon) throws SQLException;

    public List<FileQryResult> findManagementsFilter(double lat, double lon, String filter1, String filter2) throws SQLException;

    public Connection getConnection();
}