Skip to content

Commit 3ebbc00

Browse files
committed
Support multiple bounding boxes in ISO metadata
1 parent 5e3938a commit 3ebbc00

File tree

5 files changed

+143
-88
lines changed

5 files changed

+143
-88
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package gov.nasa.cumulus.metadata.aggregator;
2+
3+
public class BoundingBox {
4+
private Double bbxNorthernLatitude;
5+
private Double bbxSouthernLatitude;
6+
private Double bbxEasternLongitude;
7+
private Double bbxWesternLongitude;
8+
9+
public BoundingBox(Double northLat, Double southLat, Double eastLon, Double westLon) {
10+
this.bbxNorthernLatitude = northLat;
11+
this.bbxSouthernLatitude = southLat;
12+
this.bbxEasternLongitude = eastLon;
13+
this.bbxWesternLongitude = westLon;
14+
}
15+
16+
public Double getBbxNorthernLatitude() {
17+
return bbxNorthernLatitude;
18+
}
19+
20+
public void setBbxNorthernLatitude(Double bbxNorthernLatitude) {
21+
this.bbxNorthernLatitude = bbxNorthernLatitude;
22+
}
23+
24+
public Double getBbxSouthernLatitude() {
25+
return bbxSouthernLatitude;
26+
}
27+
28+
public void setBbxSouthernLatitude(Double bbxSouthernLatitude) {
29+
this.bbxSouthernLatitude = bbxSouthernLatitude;
30+
}
31+
32+
public Double getBbxEasternLongitude() {
33+
return bbxEasternLongitude;
34+
}
35+
36+
public void setBbxEasternLongitude(Double bbxEasternLongitude) {
37+
this.bbxEasternLongitude = bbxEasternLongitude;
38+
}
39+
40+
public Double getBbxWesternLongitude() {
41+
return bbxWesternLongitude;
42+
}
43+
44+
public void setBbxWesternLongitude(Double bbxWesternLongitude) {
45+
this.bbxWesternLongitude = bbxWesternLongitude;
46+
}
47+
}

src/main/java/gov/nasa/cumulus/metadata/aggregator/MetadataFilesToEcho.java

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void setDatasetValues(String shortName, String version, Boolean rangeIs36
124124
}
125125

126126
if (boundingBox != null) {
127-
setGranuleBoundingBox(
127+
addGranuleBoundingBox(
128128
(Double) boundingBox.get("latMax"),
129129
(Double) boundingBox.get("latMin"),
130130
(Double) boundingBox.get("lonMax"),
@@ -204,7 +204,7 @@ public void readCommonMetadataFile(String file, String s3Location) throws IOExce
204204
// setGranuleFileSizeAndChecksum function
205205

206206
//lat/lon
207-
setGranuleBoundingBox(
207+
addGranuleBoundingBox(
208208
(Double)((JSONObject)metadata.get("boundingBox")).get("NorthernLatitude"),
209209
(Double)((JSONObject)metadata.get("boundingBox")).get("SouthernLatitude"),
210210
(Double)((JSONObject)metadata.get("boundingBox")).get("EasternLongitude"),
@@ -420,7 +420,7 @@ private void parseRequiredFields(Document doc, XPath xpath, IsoType iso) throws
420420

421421
public IsoGranule readIsoMendsMetadataFile(String s3Location, Document doc, XPath xpath) throws XPathExpressionException {
422422
if (MENDsISOXmlUtiils.extractXPathValueSwallowException(doc, xpath, IsoMendsXPath.NORTH_BOUNDING_COORDINATE, "IsoMendsXPath.NORTH_BOUNDING_COORDINATE")!= "") {
423-
setGranuleBoundingBox(
423+
addGranuleBoundingBox(
424424
Double.parseDouble(MENDsISOXmlUtiils.extractXPathValueSwallowException(doc, xpath, IsoMendsXPath.NORTH_BOUNDING_COORDINATE, "IsoMendsXPath.NORTH_BOUNDING_COORDINATE")),
425425
Double.parseDouble(MENDsISOXmlUtiils.extractXPathValueSwallowException(doc, xpath, IsoMendsXPath.SOUTH_BOUNDING_COORDINATE, "IsoMendsXPath.SOUTH_BOUNDING_COORDINATE")),
426426
Double.parseDouble(MENDsISOXmlUtiils.extractXPathValueSwallowException(doc, xpath, IsoMendsXPath.EAST_BOUNDING_COORDINATE, "IsoMendsXPath.EAST_BOUNDING_COORDINATE")),
@@ -810,19 +810,34 @@ private void readIsoSmapMetadataFile(String s3Location, Document doc, XPath xpat
810810

811811
String boundingBoxInformation = xpath.evaluate(IsoSmapXPath.BOUNDING_BOX, doc);
812812
if (!boundingBoxInformation.trim().isEmpty()) {
813-
String north = xpath.evaluate(IsoSmapXPath.NORTH_BOUNDING_COORDINATE, doc);
814-
String south = xpath.evaluate(IsoSmapXPath.SOUTH_BOUNDING_COORDINATE, doc);
815-
String east = xpath.evaluate(IsoSmapXPath.EAST_BOUNDING_COORDINATE, doc);
816-
String west = xpath.evaluate(IsoSmapXPath.WEST_BOUNDING_COORDINATE, doc);
813+
NodeList boundingBoxes = (NodeList)xpath.evaluate(IsoSmapXPath.BOUNDING_BOX, doc, XPathConstants.NODESET);
814+
AdapterLogger.LogInfo("Found " + boundingBoxes.getLength() + " bounding box nodes.");
815+
for (int i = 0; i < boundingBoxes.getLength(); i++) {
816+
Node boundingBoxNode = boundingBoxes.item(i);
817817

818-
try {
819-
setGranuleBoundingBox(Double.parseDouble(north),
820-
Double.parseDouble(south),
821-
Double.parseDouble(east),
822-
Double.parseDouble(west));
823-
} catch (NullPointerException | NumberFormatException exception) {
824-
throw new IllegalArgumentException(String.format("Failed to parse bbox N=%s S=%s E=%s W=%s",
825-
north, south, east, west), exception);
818+
Element boundingBox = (Element)boundingBoxNode;
819+
820+
Element northBound = (Element)(boundingBox.getElementsByTagName("gmd:northBoundLatitude").item(0));
821+
String north = northBound.getElementsByTagName("gco:Decimal").item(0).getTextContent();
822+
823+
Element southBound = (Element)(boundingBox.getElementsByTagName("gmd:southBoundLatitude").item(0));
824+
String south = southBound.getElementsByTagName("gco:Decimal").item(0).getTextContent();
825+
826+
Element eastBound = (Element)(boundingBox.getElementsByTagName("gmd:eastBoundLongitude").item(0));
827+
String east = eastBound.getElementsByTagName("gco:Decimal").item(0).getTextContent();
828+
829+
Element westBound = (Element)(boundingBox.getElementsByTagName("gmd:westBoundLongitude").item(0));
830+
String west = westBound.getElementsByTagName("gco:Decimal").item(0).getTextContent();
831+
832+
try {
833+
addGranuleBoundingBox(Double.parseDouble(north),
834+
Double.parseDouble(south),
835+
Double.parseDouble(east),
836+
Double.parseDouble(west));
837+
} catch (NullPointerException | NumberFormatException exception) {
838+
throw new IllegalArgumentException(String.format("Failed to parse bbox N=%s S=%s E=%s W=%s",
839+
north, south, east, west), exception);
840+
}
826841
}
827842
}
828843

@@ -881,7 +896,7 @@ public void readSwotArchiveXmlFile(String file) throws ParserConfigurationExcept
881896

882897
granule = createSwotArchiveGranule(doc, xpath);
883898
// No spatial extent exists for SWOT L0 data so set as global
884-
setGranuleBoundingBox(90.0, -90.0, 180.0, -180.0);
899+
addGranuleBoundingBox(90.0, -90.0, 180.0, -180.0);
885900
}
886901

887902
/**
@@ -917,7 +932,7 @@ public void readSwotCalValXmlFile(String file) throws ParserConfigurationExcepti
917932
}
918933

919934
try {
920-
setGranuleBoundingBox(Double.parseDouble(north),
935+
addGranuleBoundingBox(Double.parseDouble(north),
921936
Double.parseDouble(south),
922937
Double.parseDouble(east),
923938
Double.parseDouble(west));
@@ -1086,12 +1101,10 @@ private TrackType createTrackType(Integer iCycle, Integer iPass) {
10861101
return trackType;
10871102
}
10881103

1089-
private void setGranuleBoundingBox(double north, double south, double east, double west) {
1104+
private void addGranuleBoundingBox(double north, double south, double east, double west) {
10901105
AdapterLogger.LogInfo("set bounding box 4 coordinates for UMMGranule object");
1091-
granule.setBbxNorthernLatitude(north);
1092-
granule.setBbxSouthernLatitude(south);
1093-
granule.setBbxEasternLongitude(east);
1094-
granule.setBbxWesternLongitude(west);
1106+
BoundingBox boundingBox = new BoundingBox(north, south, east, west);
1107+
granule.addBoundingBox(boundingBox);
10951108
}
10961109

10971110
public JSONObject createJson()

src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranule.java

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.json.simple.JSONObject;
88

99
import java.math.BigDecimal;
10+
import java.util.ArrayList;
11+
import java.util.Collections;
1012
import java.util.List;
1113

1214
public class UMMGranule extends Granule {
@@ -23,11 +25,8 @@ public class UMMGranule extends Granule {
2325
private Integer startOrbit;
2426
private Integer endOrbit;
2527
private String tile;
26-
/* Bounding Box 4 points */
27-
private Double bbxNorthernLatitude;
28-
private Double bbxSouthernLatitude;
29-
private Double bbxEasternLongitude;
30-
private Double bbxWesternLongitude;
28+
final private List<BoundingBox> boundingBoxes = new ArrayList<>();
29+
3130
private BigDecimal equatorCrossingLongitude;
3231
private String equatorCrossingDateTime;
3332
private JSONObject dynamicAttributeNameMapping;
@@ -87,38 +86,6 @@ public void setAdditionalAttributeTypes(List<AdditionalAttributeType> additional
8786
this.additionalAttributeTypes = additionalAttributeTypes;
8887
}
8988

90-
public Double getBbxNorthernLatitude() {
91-
return bbxNorthernLatitude;
92-
}
93-
94-
public void setBbxNorthernLatitude(Double bbxNorthernLatitude) {
95-
this.bbxNorthernLatitude = bbxNorthernLatitude;
96-
}
97-
98-
public Double getBbxSouthernLatitude() {
99-
return bbxSouthernLatitude;
100-
}
101-
102-
public void setBbxSouthernLatitude(Double bbxSouthernLatitude) {
103-
this.bbxSouthernLatitude = bbxSouthernLatitude;
104-
}
105-
106-
public Double getBbxEasternLongitude() {
107-
return bbxEasternLongitude;
108-
}
109-
110-
public void setBbxEasternLongitude(Double bbxEasternLongitude) {
111-
this.bbxEasternLongitude = bbxEasternLongitude;
112-
}
113-
114-
public Double getBbxWesternLongitude() {
115-
return bbxWesternLongitude;
116-
}
117-
118-
public void setBbxWesternLongitude(Double bbxWesternLongitude) {
119-
this.bbxWesternLongitude = bbxWesternLongitude;
120-
}
121-
12289
public String getEquatorCrossingDateTime() {
12390
return equatorCrossingDateTime;
12491
}
@@ -142,4 +109,13 @@ public JSONObject getDynamicAttributeNameMapping() {
142109
public void setDynamicAttributeNameMapping(JSONObject dynamicAttributeNameMapping) {
143110
this.dynamicAttributeNameMapping = dynamicAttributeNameMapping;
144111
}
112+
113+
public void addBoundingBox(BoundingBox bbox) {
114+
System.out.println("Adding bounding box to UMMG granule");
115+
boundingBoxes.add(bbox);
116+
}
117+
118+
public List<BoundingBox> getBoundingBoxes() {
119+
return Collections.unmodifiableList(boundingBoxes);
120+
}
145121
}

src/main/java/gov/nasa/cumulus/metadata/aggregator/UMMGranuleFile.java

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,20 @@ private JSONObject exportSpatial() throws ParseException{
534534

535535
double north = 0, south = 0, east = 0, west = 0;
536536
if(granule !=null && granule.getIsoType() == null) {
537-
east = ((UMMGranule) granule).getBbxEasternLongitude() != null ?
538-
((UMMGranule) granule).getBbxEasternLongitude() : 0;
539-
west = ((UMMGranule) granule).getBbxWesternLongitude() != null?
540-
((UMMGranule) granule).getBbxWesternLongitude() : 0;
541-
north = ((UMMGranule) granule).getBbxNorthernLatitude() != null?
542-
((UMMGranule) granule).getBbxNorthernLatitude() : 0;
543-
south = ((UMMGranule) granule).getBbxSouthernLatitude() != null?
544-
((UMMGranule) granule).getBbxSouthernLatitude() : 0;
537+
List<BoundingBox> boundingBoxes = ((UMMGranule)granule).getBoundingBoxes();
538+
539+
if (!boundingBoxes.isEmpty()) {
540+
BoundingBox boundingBox = boundingBoxes.get(0);
541+
542+
east = boundingBox.getBbxEasternLongitude() != null ?
543+
boundingBox.getBbxEasternLongitude() : 0;
544+
west = boundingBox.getBbxWesternLongitude() != null?
545+
boundingBox.getBbxWesternLongitude() : 0;
546+
north = boundingBox.getBbxNorthernLatitude() != null?
547+
boundingBox.getBbxNorthernLatitude() : 0;
548+
south = boundingBox.getBbxSouthernLatitude() != null?
549+
boundingBox.getBbxSouthernLatitude() : 0;
550+
}
545551
} else {
546552
Set<GranuleReal> grs = granule.getGranuleRealSet();
547553

@@ -656,26 +662,36 @@ private JSONObject exportSpatial() throws ParseException{
656662
}
657663

658664
public JSONObject appendBoundingRectangles (JSONObject geometry, JSONObject horizontalSpatialDomain) {
659-
double north = 0, south = 0, east = 0, west = 0;
660-
east = ((IsoGranule) granule).getBbxEasternLongitude() != null ?
661-
((IsoGranule) granule).getBbxEasternLongitude() : 0;
662-
west = ((IsoGranule) granule).getBbxWesternLongitude() != null?
663-
((IsoGranule) granule).getBbxWesternLongitude() : 0;
664-
north = ((IsoGranule) granule).getBbxNorthernLatitude() != null?
665-
((IsoGranule) granule).getBbxNorthernLatitude() : 0;
666-
south = ((IsoGranule) granule).getBbxSouthernLatitude() != null?
667-
((IsoGranule) granule).getBbxSouthernLatitude() : 0;
668-
if(BoundingTools.coordsInvalid(north, south, east, west)) {
669-
west = -180.0;
670-
east = -179.0;
671-
north = -89.0;
672-
south = -90.0;
673-
}
674665
horizontalSpatialDomain.put("Geometry", geometry);
675666
JSONArray boundingRectangles = new JSONArray();
676667
geometry.put("BoundingRectangles", boundingRectangles);
677-
boundingRectangles.add(createBoundingBoxJson(new BigDecimal(north), new BigDecimal(south),
678-
new BigDecimal(east), new BigDecimal(west)));
668+
669+
for (BoundingBox boundingBox : ((IsoGranule)granule).getBoundingBoxes()) {
670+
double north = 0, south = 0, east = 0, west = 0;
671+
672+
north = boundingBox.getBbxNorthernLatitude() != null ?
673+
boundingBox.getBbxNorthernLatitude() : 0;
674+
south = boundingBox.getBbxSouthernLatitude() != null ?
675+
boundingBox.getBbxSouthernLatitude() : 0;
676+
east = boundingBox.getBbxEasternLongitude() != null ?
677+
boundingBox.getBbxEasternLongitude() : 0;
678+
west = boundingBox.getBbxWesternLongitude() != null ?
679+
boundingBox.getBbxWesternLongitude() : 0;
680+
681+
if (BoundingTools.coordsInvalid(north, south, east, west)) {
682+
west = -180.0;
683+
east = -179.0;
684+
north = -89.0;
685+
south = -90.0;
686+
}
687+
688+
boundingRectangles.add(
689+
createBoundingBoxJson(
690+
new BigDecimal(north), new BigDecimal(south),
691+
new BigDecimal(east), new BigDecimal(west)
692+
)
693+
);
694+
}
679695
return horizontalSpatialDomain;
680696
}
681697

src/test/java/gov/nasa/cumulus/metadata/test/MetadataFilesToEchoTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ public void testSetDatasetValues() throws ParseException {
8484
assertEquals("2019.0", UMMUtils.getDatasetVersion(mfte.getDataset()));
8585

8686
assertEquals(UMMGranule.class, mfte.getGranule().getClass());
87+
8788
UMMGranule granule = (UMMGranule) mfte.getGranule();
88-
assertEquals(-180, granule.getBbxWesternLongitude().intValue());
89-
assertEquals(90, granule.getBbxNorthernLatitude().intValue());
90-
assertEquals(180, granule.getBbxEasternLongitude().intValue());
91-
assertEquals(-90, granule.getBbxSouthernLatitude().intValue());
89+
BoundingBox granuleBoundingBox = granule.getBoundingBoxes().get(0);
90+
91+
assertEquals(-180, granuleBoundingBox.getBbxWesternLongitude().intValue());
92+
assertEquals(90, granuleBoundingBox.getBbxNorthernLatitude().intValue());
93+
assertEquals(180, granuleBoundingBox.getBbxEasternLongitude().intValue());
94+
assertEquals(-90, granuleBoundingBox.getBbxSouthernLatitude().intValue());
9295
}
9396

9497
@Test

0 commit comments

Comments
 (0)