Skip to content

Commit

Permalink
Check for other problematic coords in GeoCoverage
Browse files Browse the repository at this point in the history
- Add validation rule to prevent bounding boxes from: containing the poles or crossing the anti-meridian
- Add unit tests for the new validation rules

Issue #2159
  • Loading branch information
robyngit committed Nov 2, 2023
1 parent 1e5cf79 commit 02d3e4b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 20 deletions.
53 changes: 33 additions & 20 deletions src/js/models/metadata/eml211/EMLGeoCoverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,14 @@ define(["jquery", "underscore", "backbone", "models/DataONEObject"], function (
case "needPair":
return "Each location description must have at least one coordinate pair.";
break;
case "coordsReversed":
case "northSouthReversed":
return "The North latitude must be greater than the South latitude.";
break;
case "crossesAntiMeridian":
return "The bounding box cannot cross the anti-meridian.";
break;
case "containsPole":
return "The bounding box cannot contain the North or South pole.";
default:
return "";
break;
Expand Down Expand Up @@ -370,21 +375,6 @@ define(["jquery", "underscore", "backbone", "models/DataONEObject"], function (

var pointStatuses = this.getCoordinateStatus();

// if (!this.checkForPairs(pointStatuses)) {
// errorMsg = this.addSpace(errorMsg);
// errorMsg += this.getErrorMessage("needPair");
// }

// if (this.hasMissingPoint(pointStatuses)) {
// errorMsg = this.addSpace(errorMsg);
// errors += this.getErrorMessage("missing");
// }

// errorMsg += this.addSpace(
// this.generateStatusErrors(pointStatuses),
// true
// );

if (
!pointStatuses.north.isSet &&
!pointStatuses.south.isSet &&
Expand Down Expand Up @@ -414,22 +404,45 @@ define(["jquery", "underscore", "backbone", "models/DataONEObject"], function (
else if (!pointStatuses.south.isSet && pointStatuses.east.isSet)
errors.south = this.getErrorMessage("missing");

// Verify latitudes: north should be > south. For longitude, east and
// west can be in any order, depending on whether the location crosses
// the antimeridian
// Verify latitudes: north should be > south. Don't allow bounding boxes
// to contain the north or south poles (doesn't really work)
if (
pointStatuses.north.isSet &&
pointStatuses.south.isSet &&
pointStatuses.north.isValid &&
pointStatuses.south.isValid
) {
if (pointStatuses.north.value < pointStatuses.south.value) {
const msg = this.getErrorMessage("coordsReversed");
const msg = this.getErrorMessage("northSouthReversed");
errors.north = msg;
errors.south = msg;
}
if (
pointStatuses.north.value == 90 ||
pointStatuses.south.value == -90
) {
const msg = this.getErrorMessage("containsPole");
errors.north = msg;
errors.south = msg;
}
}

// For longitudes, don't allow bounding boxes that attempt to traverse
// the anti-meridian
if (
pointStatuses.east.isSet &&
pointStatuses.west.isSet &&
pointStatuses.east.isValid &&
pointStatuses.west.isValid
) {
if (pointStatuses.east.value < pointStatuses.west.value) {
const msg = this.getErrorMessage("crossesAntiMeridian");
errors.east = msg;
errors.west = msg;
}
}


if (Object.keys(errors).length) return errors;
else return false;
},
Expand Down
32 changes: 32 additions & 0 deletions test/js/specs/unit/models/metadata/eml211/EMLGeoCoverage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,38 @@ define([
errors.south.should.equal(msg);
});

it("should give an error if the bounds cross the anti-meridian", function () {
var emlGeoCoverage = new EMLGeoCoverage(
{ objectDOM: this.testEML },
{ parse: true }
);
emlGeoCoverage.set("west", "170");
emlGeoCoverage.set("east", "-170");
var errors = emlGeoCoverage.validate();
errors.west.should.equal("The bounding box cannot cross the anti-meridian.");
errors.east.should.equal("The bounding box cannot cross the anti-meridian.");
});

it("should give an error if the bounds contain the north pole", function () {
var emlGeoCoverage = new EMLGeoCoverage(
{ objectDOM: this.testEML },
{ parse: true }
);
emlGeoCoverage.set("north", "90");
var errors = emlGeoCoverage.validate();
errors.north.should.equal("The bounding box cannot contain the North or South pole.");
});

it("should give an error if the bounds contain the south pole", function () {
var emlGeoCoverage = new EMLGeoCoverage(
{ objectDOM: this.testEML },
{ parse: true }
);
emlGeoCoverage.set("south", "-90");
var errors = emlGeoCoverage.validate();
errors.south.should.equal("The bounding box cannot contain the North or South pole.");
});

});
});
});

0 comments on commit 02d3e4b

Please sign in to comment.