@@ -8,6 +8,8 @@ |
import java.sql.SQLException; |
import java.util.HashMap; |
import java.util.ArrayList; |
+import java.util.logging.Level; |
+import java.util.logging.Logger; |
import javax.ws.rs.Path; |
import m.rse.cfactor.utils.Const; |
import m.rse.cfactor.utils.PGTools; |
@@ -100,11 +102,11 @@ |
LOG.info("getting centroid for polygon now"); |
PGTools.Centroid centroid = PGTools.getCentroid(cfactor_polygon); |
LOG.info("About to get C Factor Raster value for lat=" + centroid.lat + " long=" + centroid.lon + " "); |
- this.aoa_cfactor = PGTools.getCFactorRaster(centroid.lat, centroid.lon, getWorkspaceDir()) / 100.0; |
+ this.aoa_cfactor = 5.68; //PGTools.getCFactorRaster(centroid.lat, centroid.lon, getWorkspaceDir()) / 100.0; |
|
//Call SSURGO gemoetry intersect code here ( ssurgo.soilmu_a table ) |
//Call SSURGO component lookups here ( ssurgo.component table ) |
- if (this.componentLookup(this.ssurgoIntersect(this.polygonData.toWKT()))) { |
+ if (this.componentLookup(this.ssurgoIntersect(this.polygonData.toWKT()), this.isPalouseArea(this.polygonData.toWKT()))) { |
//Calc wind and water ep here... |
this.aoa_wind_ep = this.aoa_cfactor * this.aoa_ifactor / this.aoa_tfactor; |
this.aoa_water_ep = this.aoa_kfactor * this.aoa_lsfactor / this.aoa_tfactor; |
@@ -117,9 +119,10 @@ |
this.error_msg += "SQL exception getting cfactor: " + se.getMessage(); |
} catch (ServiceException sx) { |
this.error_msg += "Service exception getting cfactor: " + sx.getMessage(); |
- } catch (IOException ioe) { |
+ } |
+ /*catch (IOException ioe) { |
this.error_msg += "IO Exception getting cFactor value from raster geotiff layer: " + ioe.getMessage(); |
- } |
+ }*/ |
|
return (this.error_msg.isEmpty() ? EXEC_OK : this.error_msg); |
} |
@@ -215,6 +218,46 @@ |
return tPolygon; |
} |
|
+ // If the WKTPolygon of interest intersects any polygons in the Palouse, MLRA-9, region, this funciton will return true. |
+ private boolean isPalouseArea(String WKTPolygon) { |
+ boolean ret_val = false; |
+ |
+ if (null != WKTPolygon) { |
+ String query; |
+ |
+ query = "SELECT id" |
+ + " FROM ssurgo.mlra_9 " |
+ + " WHERE geometry::STGeomFromText(component_boundary.STAsText(),4326).STIntersects(geometry::STGeomFromText(" + WKTPolygon + ",4326))=1" |
+ + " AND geometry::STGeomFromText(" + WKTPolygon + ",4326).STIsValid()=1;"; |
+ |
+ LOG.log(Level.INFO, "ssurgo Palouse query={0}", query); |
+ |
+ try ( |
+ java.sql.Connection conn = PGTools.getConnection("cfactor", LOG); |
+ java.sql.Statement statement = conn.createStatement();) { |
+ ResultSet results = statement.executeQuery(query); |
+ |
+ LOG.info(" past the query execute"); |
+ |
+ if (null != results) { |
+ if (results.next()) { |
+ ret_val = true; |
+ } |
+ } |
+ |
+ } catch (SQLException | ServiceException ex) { |
+ this.error_msg += "Cannot continue processing this request in the find Palouse region procedure: " + ex.getMessage(); |
+ StackTraceElement ste[] = ex.getStackTrace(); |
+ LOG.severe(ex.toString()); |
+ for (StackTraceElement e : ste) { |
+ LOG.severe(e.toString()); |
+ } |
+ } |
+ } |
+ |
+ return ret_val; |
+ } |
+ |
// Returns the intersected mukey with the largest area. |
private String ssurgoIntersect(String WKTPolygon) { |
HashMap<String, V1_1.ssurgoAttributes> mukeyAttributes; |
@@ -311,7 +354,7 @@ |
return ret_val; |
} |
|
- private Boolean componentLookup(String mukey) { |
+ private Boolean componentLookup(String mukey, boolean isPalouseRegion) { |
String query; |
ResultSet results; |
Boolean ret_val = false; |
@@ -321,7 +364,7 @@ |
double length_m = 0.0; |
double[] slopeDistance = {200.0, 300.0, 200.0, 180.0, 160.0, 150.0, 140.0, 130.0, 125.0, 120.0, 110.0, 100.0, 90.0, 80.0, 70.0}; |
double[] palouseSlopeDistance = {350.0, 275.0, 225.0, 175.0, 150.0, 125.0, 100.0}; |
- boolean palouseRegion = false; |
+ boolean palouseRegion = isPalouseRegion; |
|
if ((null != mukey) && !mukey.isEmpty()) { |
try ( |
@@ -329,10 +372,10 @@ |
java.sql.Statement statement = conn.createStatement();) { |
|
query = "SELECT component.cokey, component.compname, component.wei as ifact, component.slope_r, component.slopelenusle_r as lsfact, component.tfact, component.comppct_r " |
- + "FROM ssurgo.component " |
- + "WHERE component.mukey='" + mukey + "' " |
+ + " FROM ssurgo.component " |
+ + " WHERE component.mukey='" + mukey + "' " |
+ " AND component.slope_r is not null" |
- + "ORDER BY component.comppct_r DESC;"; |
+ + " ORDER BY component.comppct_r DESC;"; |
LOG.info(" ssurgo query=" + query); |
|
results = statement.executeQuery(query); |
@@ -345,19 +388,33 @@ |
this.aoa_dom_compname = results.getString("compname"); |
this.aoa_ifactor = results.getDouble("ifact"); |
slope_r = results.getDouble("slope_r"); |
- |
- if ( !palouseRegion ){ |
+ |
+ if (!palouseRegion) { |
if (slope_r >= 18) { |
lambda = 50; |
} else if (slope_r >= 16) { |
lambda = 60; |
- } else if (slope_r >= 0 && slope_r < 1.0) { |
+ } else if (slope_r >= 0 && slope_r < 1.0) { //maybe should just be <1.0 |
lambda = 100; |
} else { |
- lambda = slopeDistance[((int) slope_r) - 1]; |
+ lambda = slopeDistance[((int) slope_r) - 1]; // Maybe should be ((int) round(slope_r)) - 1 |
} |
+ } else if (slope_r < 6) { |
+ lambda = palouseSlopeDistance[0]; |
+ } else if (slope_r < 11) { |
+ lambda = palouseSlopeDistance[1]; |
+ } else if (slope_r < 16) { |
+ lambda = palouseSlopeDistance[2]; |
+ } else if (slope_r < 21) { |
+ lambda = palouseSlopeDistance[3]; |
+ } else if (slope_r < 26) { |
+ lambda = palouseSlopeDistance[4]; |
+ } else if (slope_r < 36) { |
+ lambda = palouseSlopeDistance[5]; |
+ } else if (slope_r < 46) { |
+ lambda = palouseSlopeDistance[6]; |
} |
- |
+ |
length_m = ((slope_r >= 5.0) ? 0.5 : (slope_r >= 3.5) ? 0.4 : (slope_r >= 1.0) ? 0.3 : 0.2); |
theta = Math.atan(slope_r / 100.0); |
|
@@ -401,8 +458,8 @@ |
|
return ret_val; |
} |
+ //Inner Classes/Structures go here... |
|
- //Inner Classes/Structures go here... |
/** |
* |
*/ |