@@ -129,6 +129,7 @@ |
|
featureIterator.close(); |
|
+ LOG.info("===> CMZs Switch : " + cmzs_switch); |
if (!cmzs_switch) { |
|
File CMZfile = new File(dataDir, CSIP_Const.CMZshp); |
@@ -258,6 +259,10 @@ |
} |
|
if (CMZs.size() < 2 && states.size() < 2 && County.size() < 2) { |
+ if (CMZs.size() < 1) { |
+ LOG.info("===> No CMZ "); |
+ CMZs.add("XX"); |
+ } |
for (int i = 0; i < AOI.size(); i++) { |
ERU new_hru = new ERU(); |
new_hru.ID = i; |
@@ -376,54 +381,54 @@ |
LOG.info(part + ".-" + ((int) progress) + "%..."); |
} |
//LOG.info("===> Going to real check CMZs"); |
- if(!list_cmzs.isEmpty()){ |
- for (SimpleFeature feature : list_cmzs) { |
+ if (list_cmzs.size() > 0) { |
+ for (SimpleFeature feature : list_cmzs) { |
|
- Geometry geometry = (Geometry) feature.getDefaultGeometry(); |
- geometry = Geospatial.roundCoordinates(geometry.convexHull()); |
+ Geometry geometry = (Geometry) feature.getDefaultGeometry(); |
+ geometry = Geospatial.roundCoordinates(geometry.convexHull()); |
|
- if (AOI.get(i).within(geometry)) { |
- String no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", ""); |
- if (feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").startsWith("0")) { |
- no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").replace("0", ""); |
- } |
- CMZs.add(no_start_zero); |
- break; |
- } else if (AOI.get(i).intersects(geometry) || AOI.get(i).crosses(geometry) || AOI.get(i).overlaps(geometry) || AOI.get(i).touches(geometry)) { |
- |
- Geometry intersection = AOI.get(i).intersection(geometry); |
- |
- if (intersection instanceof MultiPolygon) { |
- MultiPolygon mp = (MultiPolygon) intersection; |
- double sum_area_part = 0; |
- for (int uu = 0; uu < mp.getNumGeometries(); uu++) { |
- com.vividsolutions.jts.geom.Polygon g = (com.vividsolutions.jts.geom.Polygon) mp.getGeometryN(uu); |
- Geometry gIntersection = IntersectUtils.intersection(g, AOI.get(i)); |
- sum_area_part = sum_area_part + ((gIntersection.getArea() / AOI.get(i).getArea()) * 100); |
- } |
+ if (AOI.get(i).within(geometry)) { |
String no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", ""); |
if (feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").startsWith("0")) { |
no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").replace("0", ""); |
} |
- if (!CMZs.contains(no_start_zero) && sum_area_part > majority_size) { |
- CMZs.add(no_start_zero); |
+ CMZs.add(no_start_zero); |
+ break; |
+ } else if (AOI.get(i).intersects(geometry) || AOI.get(i).crosses(geometry) || AOI.get(i).overlaps(geometry) || AOI.get(i).touches(geometry)) { |
+ |
+ Geometry intersection = AOI.get(i).intersection(geometry); |
+ |
+ if (intersection instanceof MultiPolygon) { |
+ MultiPolygon mp = (MultiPolygon) intersection; |
+ double sum_area_part = 0; |
+ for (int uu = 0; uu < mp.getNumGeometries(); uu++) { |
+ com.vividsolutions.jts.geom.Polygon g = (com.vividsolutions.jts.geom.Polygon) mp.getGeometryN(uu); |
+ Geometry gIntersection = IntersectUtils.intersection(g, AOI.get(i)); |
+ sum_area_part = sum_area_part + ((gIntersection.getArea() / AOI.get(i).getArea()) * 100); |
+ } |
+ String no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", ""); |
+ if (feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").startsWith("0")) { |
+ no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").replace("0", ""); |
+ } |
+ if (!CMZs.contains(no_start_zero) && sum_area_part > majority_size) { |
+ CMZs.add(no_start_zero); |
+ } |
} |
- } |
- if (intersection instanceof Polygon) { |
- com.vividsolutions.jts.geom.Polygon g = (com.vividsolutions.jts.geom.Polygon) intersection; |
- Geometry gIntersection = IntersectUtils.intersection(g, AOI.get(i)); |
- double intersection_area_portion = (gIntersection.getArea() / AOI.get(i).getArea()) * 100; |
- String no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", ""); |
- if (feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").startsWith("0")) { |
- no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").replace("0", ""); |
- } |
- if (!CMZs.contains(no_start_zero) && intersection_area_portion > majority_size) { |
- CMZs.add(no_start_zero); |
+ if (intersection instanceof Polygon) { |
+ com.vividsolutions.jts.geom.Polygon g = (com.vividsolutions.jts.geom.Polygon) intersection; |
+ Geometry gIntersection = IntersectUtils.intersection(g, AOI.get(i)); |
+ double intersection_area_portion = (gIntersection.getArea() / AOI.get(i).getArea()) * 100; |
+ String no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", ""); |
+ if (feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").startsWith("0")) { |
+ no_start_zero = feature.getProperty("CMZ").getValue().toString().replace("CMZ ", "").replace("0", ""); |
+ } |
+ if (!CMZs.contains(no_start_zero) && intersection_area_portion > majority_size) { |
+ CMZs.add(no_start_zero); |
+ } |
} |
} |
} |
} |
- } |
//LOG.info("===> Done real check CMZs"); |
|
//LOG.info("===> Going to real check States"); |
@@ -491,6 +496,7 @@ |
} |
|
if (new_hru.cmz.isEmpty()) { |
+ LOG.info("===> in more overlay check CMZ is empty 1. !"); |
for (SimpleFeature feature : list_cmzs) { |
Geometry geometry = (Geometry) feature.getDefaultGeometry(); |
if (AOI.get(i).getCentroid().within(geometry.getEnvelope())) { |
@@ -504,6 +510,7 @@ |
} |
new_hru.cmz = CMZs; |
if (new_hru.cmz.isEmpty()) { |
+ LOG.info("===> in more overlay check CMZ is empty 2. !"); |
LOG.info("===> No CMZ " + new_hru.ID); |
CMZs.add("XX"); |
} |
@@ -54,8 +54,6 @@ |
public static void query_LAMPS_DB_Rotations_For_CMZ(File dataDir, List<String> unique_cmzs, |
List<ArrayList<String>> LMOD_CMZ_Data, HashMap<String, List<ArrayList<String>>> DB_LMOD_map, SessionLogger LOG) throws Exception { |
|
- unique_cmzs.add("XX"); |
- |
Class.forName("org.h2.Driver"); |
try (Connection conn = DriverManager.getConnection("jdbc:h2:file:" + dataDir.getPath() + CSIP_Const.LocalDB, "sa", ""); |
Statement state = conn.createStatement()) { |
@@ -65,6 +63,7 @@ |
if (no_start_zero.equals("XX")) { |
String queryString = "select max(KEY) as KEY, max(COVERCROPS) as COVERCROPS, max(TILOP_NR) as TILOP_NR, CROPSEQUENCE,cropseqacr,irrigated,years from LMOD_MGMTS_ACR_II group by CROPSEQUENCE,cropseqacr,irrigated,years order by years desc;"; |
ResultSet result = state.executeQuery(queryString); |
+ int count = 0; |
while (result.next()) { |
if (!result.getString("CROPSEQACR").contains("?") && !result.getString("CROPSEQUENCE").contains("silage") && !result.getString("CROPSEQUENCE").contains("sweet") && !result.getString("CROPSEQUENCE").equals("Corn;")) { // for now "silage" & "sweet" out |
ArrayList<String> LMOD_data_by_CMZ = new ArrayList<>(); |
@@ -85,8 +84,10 @@ |
LMOD_data_by_CMZ_list.add(LMOD_data_by_CMZ); |
DB_LMOD_map.put(result.getString("CROPSEQACR") + "_" + "" + no_start_zero + "" + "_" + result.getString("IRRIGATED"), LMOD_data_by_CMZ_list); |
} |
+ count++; |
} |
} |
+ LOG.info("Number of ALL Rotations " + no_start_zero + " size: " + count); |
|
} else { |
//original String queryString = "select * from \"PUBLIC\".LMOD_MGMTS_ACR where CMZ='" + Integer.parseInt(unique_cmzs.get(i)) + "' order by years desc"; |
@@ -371,15 +372,19 @@ |
boolean highest_opposite_irrigation_rotation = false; |
|
if (hrus.get(i).sorted_adjusted_conf.size() > 1 && hrus.get(i).acc_crops_year_count > 0 && (hrus.get(i).non_field_crops_years / hrus.get(i).acc_crops_year_count) < 0.51) { |
- //w_log.println(" Verhaeltnis vegetation & fieldcrops: " + (hrus.get(i).non_field_crops_years / hrus.get(i).acc_crops_year_count) + " non:" + hrus.get(i).non_field_crops_years + " field:" + hrus.get(i).acc_crops_year_count); |
+ //LOG.info(" Verhaeltnis vegetation & fieldcrops: " + (hrus.get(i).non_field_crops_years / hrus.get(i).acc_crops_year_count) + " non:" + hrus.get(i).non_field_crops_years + " field:" + hrus.get(i).acc_crops_year_count); |
//w_log.flush(); |
|
boolean rot_in_cmz = false; |
|
for (String key : hrus.get(i).sorted_adjusted_conf.keySet()) { |
|
+ LOG.info(" key : " + key); |
+ LOG.info(" hrus.get(i).sorted_adjusted_conf.get(key) : " + hrus.get(i).sorted_adjusted_conf.get(key)); |
+ LOG.info(" hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key) : " + hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key))); |
+ |
for (String cmz : hrus.get(i).cmz) { |
- //w_log.println(" " + hash_pos + ".in LIST Seq : " + hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + " Adjusted avg. Conf: " + hrus.get(i).sorted_adjusted_conf.get(key) + " for: " + key + " CMZ: " + cmz); |
+ //LOG.info(" " + hash_pos + ".in LIST Seq : " + hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + " Adjusted avg. Conf: " + hrus.get(i).sorted_adjusted_conf.get(key) + " for: " + key + " CMZ: " + cmz); |
//w_log.flush(); |
//int int_cmz = Integer.parseInt(cmz); |
String irriation_boolean = ""; |
@@ -389,15 +394,15 @@ |
irriation_boolean = "TRUE"; |
} |
|
- if (!match && DB_LMOD_map.get(hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + "_" + cmz + "_" + (hrus.get(i).irrigated).toString().toUpperCase()) != null) { |
+ if (!match && DB_LMOD_map.get(hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + "_" + cmz + "_" + (hrus.get(i).irrigated).toString().toUpperCase()) != null && !cmz.equals("XX")) { |
+ LOG.info(" with cor irri "); |
|
right_irrigation_rotation = true; |
|
List<ArrayList<String>> LMOD_data_by_CMZ = DB_LMOD_map.get(hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + "_" + cmz + "_" + (hrus.get(i).irrigated).toString().toUpperCase()); |
- // if (LMOD_data_by_CMZ.size() > 1) { |
- // w_log.println(" " + LMOD_data_by_CMZ.size() + ": Number of " + hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + "_" + cmz + "_" + (hrus.get(i).irrigated).toString().toUpperCase()); |
- // w_log.flush(); |
- // } |
+ //if (LMOD_data_by_CMZ.size() > 1) { |
+ // LOG.info(" " + LMOD_data_by_CMZ.size() + ": Number of " + hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + "_" + cmz + "_" + (hrus.get(i).irrigated).toString().toUpperCase()); |
+ //} |
pattern = hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)); |
//w_log.println(" " + hash_pos + ".in LIST Seq : " + hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + " Adjusted avg. Conf: " + hrus.get(i).sorted_adjusted_conf.get(key) + " for: " + key); |
//w_log.println(" LMOD : ==> " + pattern); |
@@ -541,7 +546,8 @@ |
break; |
//} |
} |
- } else if (!match && !highest_opposite_irrigation_rotation && DB_LMOD_map.get(hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + "_" + cmz + "_" + irriation_boolean) != null) { |
+ } else if (!match && !highest_opposite_irrigation_rotation && DB_LMOD_map.get(hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + "_" + cmz + "_" + irriation_boolean) != null && !cmz.equals("XX")) { |
+ LOG.info(" without cor irri "); |
|
highest_opposite_irrigation_rotation = true; |
List<ArrayList<String>> LMOD_data_by_CMZ = DB_LMOD_map.get(hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + "_" + cmz + "_" + irriation_boolean); |
@@ -704,11 +710,15 @@ |
|
*/ |
if (!match && !rot_in_cmz) { |
- //w_log.println(i + " HRU in new XXXXX match: "); |
- //w_log.println(" veg_seq : " + hrus.get(i).hru_veg_seq); |
- //w_log.println(" org_seq : " + hrus.get(i).hru_seq_org); |
+ LOG.info(i + " HRU in new XXXXX match: "); |
+ LOG.info(" veg_seq : " + hrus.get(i).hru_veg_seq); |
+ LOG.info(" org_seq : " + hrus.get(i).hru_seq_org); |
//w_log.flush(); |
for (String key : hrus.get(i).sorted_adjusted_conf.keySet()) { |
+ LOG.info(" key : " + key); |
+ LOG.info(" hrus.get(i).sorted_adjusted_conf.get(key) : " + hrus.get(i).sorted_adjusted_conf.get(key)); |
+ LOG.info(" hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key) : " + hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key))); |
+ |
if (!match && DB_LMOD_map.get(hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key)) + "_XX_" + (hrus.get(i).irrigated).toString().toUpperCase()) != null) { |
|
right_irrigation_rotation = true; |
@@ -858,9 +868,17 @@ |
//w_log.flush(); |
//if (jaro.proximity(org_seq, new_rebuilt) > 0.2) { |
match = true; |
+ LOG.info(" Match !!! : " + hrus.get(i).seq_map.get(hrus.get(i).sorted_adjusted_conf.get(key))); |
+ |
break; |
//} |
} |
+ if (match) { |
+ break; |
+ } |
+ } |
+ if (match) { |
+ break; |
} |
} |
} |
@@ -878,7 +896,7 @@ |
int count = majority_veg.get(each_veg[j]); |
majority_veg.put(each_veg[j], count + 1); |
} |
- } |
+ } |
} |
majority_veg = sortByValues(majority_veg); |
if (majority_veg.isEmpty()) { |
@@ -1073,12 +1091,11 @@ |
}//try state |
conn.close();//end db connection |
}//try conn |
- |
- |
+ |
long end_time = System.currentTimeMillis(); |
double difference = (end_time - start_time) / 1000; |
LOG.info(" Done first : " + first + " last : " + last + " time : " + difference + " s"); |
- |
+ |
return map; |
} |
|