Displaying differences for changeset
 
display as  

src/java/m/crp1/erosion/V3_0.java

@@ -133,7 +133,8 @@
   protected double legacyWindErosion;
   protected double legacyWaterErosion;
   protected String stateFips, countyFips;
-  protected String stateAbbr, countyName;  
+  protected String stateAbbr, countyName;
+  protected String lrr = "";
 
   /**
    *
@@ -200,6 +201,9 @@
       //Set the centroid values needed by WEPS.
       latitude = aoiShape.getLatitude();
       longitude = aoiShape.getLongitude();
+      if (0 != mupolygonkey) {
+        lrr = getLRR();
+      }
 
       try {
         getSoilData(soilsDb, aoiShape, mupolygonkey,
@@ -264,6 +268,27 @@
     }
   }
 
+  protected String getLRR() throws SQLException, ServiceException {
+
+    try (Connection connection = resources().getJDBC(EROSION_GIS_SQLSERVER);) {
+
+      String query = "SELECT mlra_id, mlra_name, mlrarsym, lrrsym, lrr_name "
+          + "FROM common.mlra_v42 "
+          + "WITH (index(idx_common_mlra42)) "
+          + "WHERE "
+          + "ogr_geometry.STContains(geometry::STGeomFromText('POINT(" + longitude + " " + latitude + "  )', 4326))=1;";
+
+      try (Statement statement = connection.createStatement();
+          ResultSet resultSet = statement.executeQuery(query)) {
+        if (resultSet.next()) {
+          return resultSet.getString("lrrsym");
+        }
+      }
+    }
+
+    throw new ServiceException("Could not locate the LRR of this centroid: (" + latitude + ", " + longitude + ").");
+  }
+
   protected String getMuPolygonData(SOILS_DATA soilsDb, int mupolygonkey) throws SQLException {
     try (Statement stmt = soilsDb.getConnection().createStatement();) {
       String query = "select cast('' as xml).value(\n"
@@ -554,19 +579,29 @@
       JSONArray topThreeDetails = new JSONArray();
       for (SignificantSoil tSoil : topThree) {
         JSONArray soilData = tSoil.toJSON();
+        try {
+          IFCFile ifc = new IFCFile(tSoil.mapUnit.toIfc(tSoil.component.cokey()));
+          SOLFile sol = new SOLFile(tSoil.component.toSol());
+          soilData.put(JSONUtils.data("sol_wepp_surface_sand", sol.sand[0]));
+          soilData.put(JSONUtils.data("sol_wepp_surface_clay", sol.clay[0]));
+          soilData.put(JSONUtils.data("sol_wepp_surface_cec", sol.cec[0]));
 
-        IFCFile ifc = new IFCFile(tSoil.mapUnit.toIfc(tSoil.component.cokey()));
-        SOLFile sol = new SOLFile(tSoil.component.toSol());
-        soilData.put(JSONUtils.data("sol_wepp_surface_sand",sol.sand[0]));
-        soilData.put(JSONUtils.data("sol_wepp_surface_clay",sol.clay[0]));     
-        soilData.put(JSONUtils.data("sol_wepp_surface_cec",sol.cec[0]));            
-        
-        soilData.put(JSONUtils.data("ifc_weps_surface_wilting_point",ifc.wiltingPointSWC[0]));
-        soilData.put(JSONUtils.data("ifc_weps_surface_sand",ifc.fractionSand[0]));
-        soilData.put(JSONUtils.data("ifc_weps_surface_silt",ifc.fractionSilt[0]));
-        soilData.put(JSONUtils.data("ifc_weps_surface_clay",ifc.fractionClay[0]));        
-                
-        topThreeDetails.put(soilData);        
+          soilData.put(JSONUtils.data("ifc_weps_surface_wilting_point", ifc.wiltingPointSWC[0]));
+          soilData.put(JSONUtils.data("ifc_weps_surface_sand", ifc.fractionSand[0]));
+          soilData.put(JSONUtils.data("ifc_weps_surface_silt", ifc.fractionSilt[0]));
+          soilData.put(JSONUtils.data("ifc_weps_surface_clay", ifc.fractionClay[0]));
+        } catch (Exception ex) {
+          soilData.put(JSONUtils.data("sol_wepp_surface_sand", "NaN"));
+          soilData.put(JSONUtils.data("sol_wepp_surface_clay", "NaN"));
+          soilData.put(JSONUtils.data("sol_wepp_surface_cec", "NaN"));
+
+          soilData.put(JSONUtils.data("ifc_weps_surface_wilting_point", "NaN"));
+          soilData.put(JSONUtils.data("ifc_weps_surface_sand", "NaN"));
+          soilData.put(JSONUtils.data("ifc_weps_surface_silt", "NaN"));
+          soilData.put(JSONUtils.data("ifc_weps_surface_clay", "NaN"));
+        }
+
+        topThreeDetails.put(soilData);
       }
       if (aoiShape.hasChanged()) {
         results().put("changed_or_corrected_input_shape", ((aoiShape.hasChanged()) ? aoiShape.toJSON() : "NONE"),