Skip to content

Commit

Permalink
validate all crs definitions can be read, attempt to validate the ide…
Browse files Browse the repository at this point in the history
…ntifier
  • Loading branch information
bosborn committed Mar 15, 2024
1 parent 0f44399 commit 3337d6f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Adheres to [Semantic Versioning](http://semver.org/).
* DAO column range support (including geometry envelopes & bounding boxes) to build where clauses & args for queries
* User Column integrated Data Columns Schema support
* RTree Index and Feature Table Index geodesic support
* DGIWG validation updates: 1 meter tile bounds tolerance, CRS definition parsing validation
* sf-wkb version 2.2.3
* sf-wkt version 1.2.3
* sf-proj version 4.3.2
Expand Down
46 changes: 44 additions & 2 deletions src/main/java/mil/nga/geopackage/dgiwg/DGIWGValidate.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package mil.nga.geopackage.dgiwg;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import mil.nga.crs.CRS;
import mil.nga.crs.CRSType;
import mil.nga.crs.common.Identifier;
import mil.nga.crs.operation.OperationMethods;
import mil.nga.crs.projected.ProjectedCoordinateReferenceSystem;
import mil.nga.crs.wkt.CRSReader;
Expand Down Expand Up @@ -589,7 +589,7 @@ public static DGIWGValidationErrors validateTileCoordinateReferenceSystem(
if (definition != null) {
try {
definitionCrs = CRSReader.read(definition);
} catch (IOException e) {
} catch (Exception e) {
errors.add(new DGIWGValidationError(
SpatialReferenceSystem.TABLE_NAME,
SpatialReferenceSystem.COLUMN_DEFINITION,
Expand Down Expand Up @@ -873,6 +873,48 @@ private static CoordinateReferenceSystem validateCoordinateReferenceSystem(
definition,
"Missing required coordinate reference system well-known text definition",
DGIWGRequirement.CRS_WKT, primaryKey(srs)));
} else {
CRS definitionCrs = null;
try {
definitionCrs = CRSReader.read(definition);
} catch (Exception e) {
errors.add(new DGIWGValidationError(
SpatialReferenceSystem.TABLE_NAME,
SpatialReferenceSystem.COLUMN_DEFINITION,
definition,
"Failed to read coordinate reference system definition: "
+ e.getMessage(),
DGIWGRequirement.CRS_WKT, primaryKey(srs)));
}
if (definitionCrs != null) {
if (definitionCrs.hasIdentifiers()) {
boolean found = false;
for (Identifier identifier : definitionCrs
.getIdentifiers()) {
if (crs.getAuthority()
.equalsIgnoreCase(identifier.getName())
&& String.valueOf(crs.getCode())
.equalsIgnoreCase(identifier
.getUniqueIdentifier())) {
found = true;
}
}
if (!found) {
for (Identifier identifier : definitionCrs
.getIdentifiers()) {
errors.add(new DGIWGValidationError(
SpatialReferenceSystem.TABLE_NAME,
SpatialReferenceSystem.COLUMN_DEFINITION,
identifier.toString(),
new Identifier(crs.getAuthority(),
String.valueOf(crs.getCode()))
.toString(),
DGIWGRequirement.CRS_WKT,
primaryKey(srs)));
}
}
}
}
}

if (!srs.getSrsName().equalsIgnoreCase(crs.getName())) {
Expand Down

0 comments on commit 3337d6f

Please sign in to comment.