@@ -5,6 +5,8 @@ |
*/ |
package d.bamert_01.edit_soils_properties; |
|
+import com.jayway.jsonpath.ReadContext; |
+import csip.Config; |
import csip.ModelDataService; |
import csip.ServiceException; |
import csip.SessionLogger; |
@@ -12,7 +14,10 @@ |
import csip.annotations.Name; |
import csip.annotations.Resource; |
import csip.annotations.VersionInfo; |
+import csip.utils.JSONUtils; |
import static db.DBResources.GIS_DB; |
+import edit.EditConnection; |
+import edit.EditQueries; |
import gisobjects.GISObject; |
import static gisobjects.GISObject.DEFAULT_ASSUMED_SRID; |
import gisobjects.GISObjectException; |
@@ -21,17 +26,30 @@ |
import gisobjects.db.GISEngineFactory; |
import java.io.IOException; |
import java.sql.SQLException; |
+import java.util.ArrayList; |
+import java.util.Arrays; |
import java.util.Collections; |
import java.util.SortedMap; |
import java.util.TreeMap; |
import javax.ws.rs.Path; |
+import org.codehaus.jettison.json.JSONArray; |
import org.codehaus.jettison.json.JSONException; |
import org.codehaus.jettison.json.JSONObject; |
+import soils.Coecoclass; |
import soils.Component; |
import soils.MapUnit; |
+import soils.SoilsData; |
import static soils.db.DBResources.PROVIDER_TYPE; |
import soils.db.SOILS_DATA; |
import soils.db.SOILS_DB_Factory; |
+import soils.db.tables.TableCoecoclass; |
+import soils.db.tables.TableCoecoclassCalculations; |
+import soils.db.tables.TableComponent; |
+import soils.db.tables.TableComponentCalculations; |
+import soils.db.tables.TableHorizon; |
+import soils.db.tables.TableHorizonCalculations; |
+import soils.db.tables.TableMapUnit; |
+import soils.db.tables.TableTextureGroup; |
|
/** |
* |
@@ -50,6 +68,7 @@ |
static final String AOA_GEOMETRY = "aoa_geometry"; |
|
JSONObject aoa_geometry; |
+ AoA aoa; |
|
@Override |
protected void preProcess() throws Exception { |
@@ -60,16 +79,17 @@ |
@Override |
protected void doProcess() throws Exception { |
try (GISEngine gisEngine = GISEngineFactory.createGISEngine(resources().getJDBC(GIS_DB)); |
- SOILS_DATA soilsDb = SOILS_DB_Factory.createEngine(V1_0.class, LOG, config().getString(PROVIDER_TYPE));) { |
+ SOILS_DATA soilsDb = SOILS_DB_Factory.createEngine(V1_0.class, LOG, Config.getString("soils.gis.database.source"));) { |
GISObject aoaGeometry = GISObjectFactory.createGISObject(aoa_geometry, gisEngine); |
- AoA aoa = new AoA(soilsDb, aoaGeometry, LOG); |
+ aoa = new AoA(soilsDb, aoaGeometry, LOG); |
aoa.findSoils(); |
} |
} |
|
@Override |
protected void postProcess() throws Exception { |
- |
+ results().put("aoa_acres", aoa.getArea()); |
+ results().put("mapunits", aoa.toJSON()); |
} |
|
public class AoA extends soils.AoA { |
@@ -123,7 +143,7 @@ |
* @throws ServiceException |
* @throws GISObjectException |
*/ |
- public void findSoils() throws SQLException, ServiceException, GISObjectException { |
+ public void findSoils() throws SQLException, ServiceException, GISObjectException, Exception { |
|
if (null != shape) { |
findIntersectedMapUnitsWithAreasAndShapes(); |
@@ -131,39 +151,35 @@ |
throw new ServiceException("No AoI location was speified. Please specify an AoI location as a geometry."); |
} |
|
- if (soilsDb.findAllBasicComponentHorizonFragTextureData(map_units)) { |
-// TODO: Does Bamert need filtering of SDM data (missing data corrections, etc.) ?? |
- for (MapUnit mapunit : map_units.values()) { |
- for (Component tComponent : mapunit.components().values()) { |
- tComponent.applyHorizonFilter("WIND"); |
- tComponent.applyHorizonFilter("WATER"); |
- tComponent.updateCalculations(); |
+ if (soilsDb.findAllBasicComponentHorizonFragTextureData(map_units, true)) { |
+ soilsDb.findEcoClassForMukeyList(map_units, |
+ " ((ecoclassid LIKE 'R%' AND ecoclasstypename='NRCS Rangeland Site') " |
+ + " OR (ecoclassid LIKE 'F%' AND ecoclasstypename='NRCS Forestland Site'))" |
+ ); |
+ getEDITEcoclassNames(); |
+ |
+ } |
+ } |
+ |
+ private void getEDITEcoclassNames() throws ServiceException, Exception { |
+ if (null != map_units) { |
+ for (MapUnit mapUnit : map_units.values()) { |
+ for (Component component : mapUnit.components().values()) { |
+ for (Coecoclass coEcoClass : component.ecoClasses().values()) { |
+ String ecId = coEcoClass.ecoclassid(); |
+ if (ecId.length() == 11 && ((ecId.charAt(0) == 'R' || ecId.charAt(0) == 'F'))) { |
+ EditConnection editConn = new EditConnection(LOG); |
+ String edit_es_name = EditQueries.getEcoClassNameFor(editConn.fetchEcoClassList(ecId), ecId); |
+ if ((null != edit_es_name) && (!edit_es_name.isEmpty())) { |
+ coEcoClass.ecoclassname(edit_es_name); |
+ coEcoClass.setEDITPath("https://edit.jornada.nmsu.edu/catalogs/esd/" + ecId.substring(1, 5) + "/" + ecId); |
+ } |
+ } |
+ } |
} |
} |
- |
- // Copy data and test for WEPP usability |
-// for (MapUnit mapunit : map_units.values()) { |
-// MapUnit newMapUnit = mapunit.deepCopy(); |
-// |
-// for (Component tComponent : newMapUnit.components().values()) { |
-// try { |
-// tComponent.adjustForWEPP_WEPS("all"); |
-// componentOrderList.put(tComponent.calculated_area(), tComponent); |
-// } catch (WEPPException ex) { |
-// tComponent.setExclude(true, "WEPP Exclusion: " + ex.getMessage()); |
-// map_units.get(newMapUnit.mukey()).components().get(tComponent.cokey()).setExclude(true, "WEPP Exclusion: " + ex.getMessage()); |
-// } catch (SDMException ex) { |
-// tComponent.setExclude(true, "SDM Exclusion: " + ex.getMessage()); |
-// map_units.get(newMapUnit.mukey()).components().get(tComponent.cokey()).setExclude(true, "SDM Exclusion: " + ex.getMessage()); |
-// } catch (WEPP_WEPSException ex) { |
-// tComponent.setExclude(true, "Generic WEPP/WEPS Exclusion: " + ex.getMessage()); |
-// map_units.get(newMapUnit.mukey()).components().get(tComponent.cokey()).setExclude(true, "Generic WEPP/WEPS Exclusion: " + ex.getMessage()); |
-// } catch (WEPSException ex) { |
-// tComponent.setExclude(true, "WEPS Exclusion: " + ex.getMessage()); |
-// map_units.get(newMapUnit.mukey()).components().get(tComponent.cokey()).setExclude(true, "WEPS Exclusion: " + ex.getMessage()); |
-// } |
-// } |
-// } |
+ } else { |
+ throw new ServiceException("Cannot find ecoclass names from EDIT with an empty mapunit list."); |
} |
} |
|
@@ -174,5 +190,69 @@ |
public final int getSRID() { |
return shape.getGeometry().getSRID(); |
} |
+ |
+ /** |
+ * |
+ * @return @throws JSONException |
+ */ |
+ public JSONArray toJSON() throws JSONException, ServiceException, IOException { |
+ JSONArray mapunitData = new JSONArray(); |
+ |
+ for (MapUnit mapUnit : map_units.values()) { |
+ if (!mapUnit.isExcluded()) { |
+ JSONArray mapUnitArray = new JSONArray(); |
+ |
+ ArrayList<GISObject> intersections = mapUnit.getIntersectionPolygons(); |
+ |
+ mapUnit.setOutputColumns(new ArrayList<>(Arrays.asList( |
+ TableMapUnit.AREA_NAME, TableMapUnit.MUKEY, TableMapUnit.MUNAME, |
+ TableMapUnit.MUSYM, TableMapUnit.MUACRES |
+ ))); |
+ mapUnit.mapUnitJSON(mapUnitArray); |
+ JSONArray intersectionArray = new JSONArray(); |
+ for (GISObject intersect : intersections) { |
+ intersectionArray.put(intersect.toJSON()); |
+ } |
+ mapUnitArray.put(JSONUtils.data("mapunit_intersections", intersectionArray)); |
+ |
+ JSONArray componentArray = new JSONArray(); |
+ for (Component component : mapUnit.components().values()) { |
+ if (!component.isExcluded()) { |
+ JSONArray componentObject; |
+ |
+ component.setOutputColumns(new ArrayList<>(Arrays.asList( |
+ TableComponent.COKEY, TableComponent.COMPNAME, TableComponent.COMPPCT_R_NAME, |
+ TableComponent.MAJ_COMP_FLAG |
+ ))); |
+ |
+ component.setHorizonOutputColumnOrdering(new ArrayList<>(Arrays.asList(TableHorizon.CHKEY_NAME, TableHorizonCalculations.DEPT_R_IN, |
+ TableHorizonCalculations.DEPB_R_IN))); |
+ component.setTextureGroupOutputColumnOrdering(new ArrayList<>(Arrays.asList(TableTextureGroup.DESCRIPTION))); |
+ |
+ componentObject = component.toJSON(false); |
+ |
+ JSONArray ecoClassArray = new JSONArray(); |
+ for (Coecoclass ecoClass : component.ecoClasses().values()) { |
+ ecoClass.setOutputColumns(new ArrayList<>(Arrays.asList(TableCoecoclass.ECOCLASSID, |
+ TableCoecoclass.ECOCLASSNAME, TableCoecoclassCalculations.ES_EDIT_URL))); |
+ ecoClassArray.put(ecoClass.toJSON()); |
+ } |
+ |
+ componentObject.put(JSONUtils.data("EcoClassList", ecoClassArray)); |
+ componentArray.put(componentObject); |
+ |
+ } |
+ } |
+ |
+ if (componentArray.length() > 0) { |
+ mapUnitArray.put(JSONUtils.data(SoilsData.MAPUNIT_COMPONENT_LIST_NAME, componentArray)); |
+ mapunitData.put(mapUnitArray); |
+ } |
+ |
+ } |
+ } |
+ |
+ return mapunitData; |
+ } |
} |
} |
@@ -2,156 +2,32 @@ |
"metainfo": {}, |
"parameter": [ |
{ |
- "name": "RequestID", |
- "value": 1098765, |
- "description": "Unique request identifier for tracking." |
- }, |
- { |
- "name": "fpp_rotations", |
- "value": [[ |
- { |
- "name": "nslp_threshold_score", |
- "value": "30", |
- "description": " Weighted area average Nitrogen Soil leaching potential threshold score of the area of analysis" |
- }, |
- { |
- "name": "nsrp_threshold_score", |
- "value": "65", |
- "description": " Weighted area average Nitrogen Soil runoff potential threshold score for the area of analysis" |
- }, |
- { |
- "name": "pslp_threshold_score", |
- "value": "30", |
- "description": " Weighted area average Phosphorus surface loss potential threshold score of the area of analysis" |
- }, |
- { |
- "name": "pssp_threshold_score", |
- "value": "65", |
- "description": " Weighted area average Phosphorus sub-surface potential threshold score for the area of analysis" |
- }, |
- { |
- "name": "report_crlmod_crop_id", |
- "value": "765", |
- "Description": "Crop in the rotation that mitigation scores are being calculated for." |
- }, |
- { |
- "name": "rotation_crops", |
- "value": [[ |
- { |
- "name": "crlmod_crop_id", |
- "value": "765", |
- "Description": "Crop in the rotation that mitigation scores are being calculated for." |
- }, |
- { |
- "name": "p_soil_test_result_id", |
- "value": 5, |
- "Description": "Database row id of the phosphorus soil test result value. [5 means 'No Test'] " |
- }, |
- { |
- "name": "yield", |
- "value": "200", |
- "unit": "bu/ac", |
- "Description": "Crop Yield" |
- }, |
- { |
- "name": "tillage_type", |
- "value": 1, |
- "Description": "Predominant Tillage Practice used." |
- }, |
- { |
- "name": "preplant_tillage_days", |
- "value": 17, |
- "Description": "days of nearest tillage kill crop operation prior to planting." |
- }, |
- |
- { |
- "name": "next_cover_type_id", |
- "value": 197, |
- "Description": "Next cover crop practice after harvest. Value is the id of the practice code from a STEP domain list." |
- }, |
- { |
- "name": "total_n_amount", |
- "value": 160, |
- "unit": "lbs/ac", |
- "Description": "Total Amount of N applied during crop year. This would include organic and inorganic applications." |
- }, |
- { |
- "name": "n_application_method", |
- "value": 4, |
- "Description": "Worst case method of N fertilizer applied during crop year" |
- }, |
- { |
- "name": "n_timing", |
- "value": 2, |
- "Description": "Database row id of the N fertilizer application timing around planting" |
- }, |
- { |
- "name": "n_total_applications", |
- "value": 1, |
- "Description": "Total N fertilizer applications for crop year" |
- }, |
- { |
- "name": "n_applied_1st_application", |
- "value": 160, |
- "Description": "The amount of N applied on the first application within the crop year whether organic or inorganic source." |
- }, |
- { |
- "name": "n_carry_over", |
- "value": 50, |
- "Description": "The amount of nitrogen carried over from previous year based on soil tests. A value of zero represents no soil test was performed to determine if N was carried over." |
- }, |
- { |
- "name": "total_p_amount", |
- "value": 20, |
- "unit": "lbs/ac", |
- "Description": "Total Amount of N applied during crop year." |
- }, |
- { |
- "name": "p_application_method", |
- "value": 2, |
- "Description": "Worst case method of P fertilizer applied during crop year" |
- }, |
- { |
- "name": "p_timing", |
- "value": 2, |
- "Description": "Database row id of the P fertilizer application timing around planting" |
- }, |
- { |
- "name": "p_total_applications", |
- "value": 2, |
- "Description": "For this crop year what was the number of fertilizer applications that applied phosphorus." |
- }, |
- { |
- "name": "p_carry_over", |
- "value": 2, |
- "optional": true, |
- "Description": "Currently not used: The amount of phosphorus carried over from previous year based on soil tests. A value of zero represents no soil test was performed to determine if P was carried over." |
- }, |
- { |
- "name": "p_applied_1st_application", |
- "value": 10, |
- "Description":"P amount in lbs/acre applied on the first application of the crop interval" |
- }, |
- { |
- "name": "p_multi_crop_application", |
- "value": 2, |
- "Description": "Was application intended to supply P to successive crops in multiple years? If so, how many years?" |
- }, |
- { |
- "name": "management_techniques", |
- "value": [36, 37], |
- "Description": "Array list of all management techniques used in the crop year", |
- "Optional":true |
- }, |
- { |
- "name": "conservation_practices", |
- "value": [205], |
- "Description": "Array list of all conservation practices used in the crop year", |
- "Optional":true |
- } |
- ]] |
- } |
- ]] |
+ "name": "aoa_geometry", |
+ "type": "Polygon", |
+ "coordinates": [ |
+ [ |
+ [ |
+ -96.92813, |
+ 41.256813 |
+ ], |
+ [ |
+ -96.91852, |
+ 41.256813 |
+ ], |
+ [ |
+ -96.91852, |
+ 41.263523 |
+ ], |
+ [ |
+ -96.92813, |
+ 41.263523 |
+ ], |
+ [ |
+ -96.92813, |
+ 41.256813 |
+ ] |
+ ] |
+ ] |
} |
] |
} |