From c285f88e8d554d984db494359b7df8c35eb861f2 Mon Sep 17 00:00:00 2001 From: Michael Dorfman Date: Wed, 31 May 2023 11:32:13 -0600 Subject: [PATCH 1/2] Updated call to updatePolygon so we're calling updatePolygons instead - the latter ensures counter-clockwise arrangement of points in the polygon. Updated updatePolygons so we can optionally bypass the polygon validity check for backwards compatibility with updatePolygon Removed no-longer-used updatePolygon method --- .../metadata/aggregator/UMMGranuleFile.java | 44 +++++-------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java b/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java index 940ca03..8056e9b 100644 --- a/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java +++ b/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java @@ -423,10 +423,13 @@ private JSONObject exportSpatial() throws ParseException{ spatialExtent.put("HorizontalSpatialDomain", horizontalSpatialDomain); if (granule instanceof IsoGranule) { - String polygon = ((IsoGranule) granule).getPolygon(); - if (polygon != "" && polygon != null) { + String polygonString = ((IsoGranule) granule).getPolygon(); + if (polygonString != "" && polygonString != null) { // Export Polygon - addPolygon(geometry, polygon); + ArrayList polygonCoordinates = UMMUtils.lineString2Coordinates(polygonString); + ArrayList> polygonCoordinatesArrayList = new ArrayList>(1); + polygonCoordinatesArrayList.add(polygonCoordinates); + addPolygons(geometry, polygonCoordinatesArrayList, true); } // Export Orbit // Commented out for now since UMM v1.5 only allows for either Geometry or Orbit not both @@ -663,7 +666,7 @@ public JSONObject line2Polygons(JSONObject geometry, String line) { // use the original coordinate array instead of splittedGeos.get(0) // for the original coordinate array is "un-damaged polygons.add(coordinates); - geometry = addPolygons(geometry, polygons); + geometry = addPolygons(geometry, polygons, false); } else if (dividedSize == 2) { // dont know how to process. Create global bounding box AdapterLogger.LogError(this.className + " split divided to more than 2 geos. Creating global bounding box"); @@ -677,7 +680,7 @@ public JSONObject line2Polygons(JSONObject geometry, String line) { ArrayList> polygons = new ArrayList<>(); polygons.add(polygon1); polygons.add(UMMUtils.closeUp((ArrayList) splittedGeos.get(1))); - geometry = addPolygons(geometry, polygons); + geometry = addPolygons(geometry, polygons, false); } else if (dividedSize > 3) { // donot know how to process, Perhaps throw exception AdapterLogger.LogError(this.className + " split divided to more than 3 geos, "); @@ -703,7 +706,7 @@ public JSONObject addGlobalBoundingBox2Geometry(JSONObject geometry) { return geometry; } - public JSONObject addPolygons(JSONObject geometry, ArrayList> inputPolygons) { + public JSONObject addPolygons(JSONObject geometry, ArrayList> inputPolygons, boolean invalidOK) { JSONArray polygons = new JSONArray(); geometry.put("GPolygons", polygons); GeometryFactory geometryFactory = new GeometryFactory(); @@ -721,7 +724,7 @@ public JSONObject addPolygons(JSONObject geometry, ArrayList Date: Fri, 2 Jun 2023 13:28:41 -0600 Subject: [PATCH 2/2] - Used StringUtils to determine whether a string is empty - Removed the validity check bypass for polygons --- .../cumulus/metadata/aggregator/UMMGranuleFile.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java b/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java index 8056e9b..cdf18ea 100644 --- a/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java +++ b/src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java @@ -424,12 +424,12 @@ private JSONObject exportSpatial() throws ParseException{ if (granule instanceof IsoGranule) { String polygonString = ((IsoGranule) granule).getPolygon(); - if (polygonString != "" && polygonString != null) { + if (!StringUtils.isEmpty(StringUtils.trim(polygonString))) { // Export Polygon ArrayList polygonCoordinates = UMMUtils.lineString2Coordinates(polygonString); ArrayList> polygonCoordinatesArrayList = new ArrayList>(1); polygonCoordinatesArrayList.add(polygonCoordinates); - addPolygons(geometry, polygonCoordinatesArrayList, true); + addPolygons(geometry, polygonCoordinatesArrayList); } // Export Orbit // Commented out for now since UMM v1.5 only allows for either Geometry or Orbit not both @@ -666,7 +666,7 @@ public JSONObject line2Polygons(JSONObject geometry, String line) { // use the original coordinate array instead of splittedGeos.get(0) // for the original coordinate array is "un-damaged polygons.add(coordinates); - geometry = addPolygons(geometry, polygons, false); + geometry = addPolygons(geometry, polygons); } else if (dividedSize == 2) { // dont know how to process. Create global bounding box AdapterLogger.LogError(this.className + " split divided to more than 2 geos. Creating global bounding box"); @@ -680,7 +680,7 @@ public JSONObject line2Polygons(JSONObject geometry, String line) { ArrayList> polygons = new ArrayList<>(); polygons.add(polygon1); polygons.add(UMMUtils.closeUp((ArrayList) splittedGeos.get(1))); - geometry = addPolygons(geometry, polygons, false); + geometry = addPolygons(geometry, polygons); } else if (dividedSize > 3) { // donot know how to process, Perhaps throw exception AdapterLogger.LogError(this.className + " split divided to more than 3 geos, "); @@ -706,7 +706,7 @@ public JSONObject addGlobalBoundingBox2Geometry(JSONObject geometry) { return geometry; } - public JSONObject addPolygons(JSONObject geometry, ArrayList> inputPolygons, boolean invalidOK) { + public JSONObject addPolygons(JSONObject geometry, ArrayList> inputPolygons) { JSONArray polygons = new JSONArray(); geometry.put("GPolygons", polygons); GeometryFactory geometryFactory = new GeometryFactory(); @@ -724,7 +724,7 @@ public JSONObject addPolygons(JSONObject geometry, ArrayList