Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NDCUM-1016 #2

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Coordinate> polygonCoordinates = UMMUtils.lineString2Coordinates(polygonString);
ArrayList<ArrayList<Coordinate>> polygonCoordinatesArrayList = new ArrayList<ArrayList<Coordinate>>(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
Expand Down Expand Up @@ -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");
Expand All @@ -677,7 +680,7 @@ public JSONObject line2Polygons(JSONObject geometry, String line) {
ArrayList<ArrayList<Coordinate>> polygons = new ArrayList<>();
polygons.add(polygon1);
polygons.add(UMMUtils.closeUp((ArrayList<Coordinate>) 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, ");
Expand All @@ -703,7 +706,7 @@ public JSONObject addGlobalBoundingBox2Geometry(JSONObject geometry) {
return geometry;
}

public JSONObject addPolygons(JSONObject geometry, ArrayList<ArrayList<Coordinate>> inputPolygons) {
public JSONObject addPolygons(JSONObject geometry, ArrayList<ArrayList<Coordinate>> inputPolygons, boolean invalidOK) {
JSONArray polygons = new JSONArray();
geometry.put("GPolygons", polygons);
GeometryFactory geometryFactory = new GeometryFactory();
Expand All @@ -721,7 +724,7 @@ public JSONObject addPolygons(JSONObject geometry, ArrayList<ArrayList<Coordinat
);

// valid polygon by vividsolution again
if(polygon.isValid()) {
if(polygon.isValid() || invalidOK) {
JSONObject gPolygon = new JSONObject();
JSONObject boundary = new JSONObject();
gPolygon.put("Boundary", boundary);
Expand Down Expand Up @@ -865,33 +868,6 @@ private JSONObject exportQAStats(IsoGranule granule) {
return parameter;
}

private void addPolygon(JSONObject geometry, String polygon) {
JSONArray polygons = new JSONArray();
geometry.put("GPolygons", polygons);

JSONObject gPolygon = new JSONObject();
JSONObject boundary = new JSONObject();
gPolygon.put("Boundary", boundary);
polygons.add(gPolygon);

JSONArray points = new JSONArray();
String[] polygonArray = polygon.split(" ");

for (int i = 0; i < polygonArray.length; i += 2) {
JSONObject point = new JSONObject();
String lon = polygonArray[i + 1];
String lat = polygonArray[i];
if (BoundingTools.allParsable(lon, lat)) {
point.put("Longitude", Double.parseDouble(lon));
point.put("Latitude", Double.parseDouble(lat));
points.add(point);
} else {
AdapterLogger.LogWarning("Unable to parse polygon, lon: " + lon + ", lat: " + lat);
}
}
boundary.put("Points", points);
}

/**
* Parses line string and adds it to lines array in geometry JSON object.
* Points are sorted by longitude. Duplicate points are removed.
Expand Down