Skip to content

Commit 3ee320a

Browse files
committed
Merge pull request geotools#439 from n-lagomarsini/GEOT-4677
[GEOT-4677]: added logging and workaround for invalid unit string in time axis
2 parents f27f62f + dca4e06 commit 3ee320a

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

modules/unsupported/coverage-experiment/unidata/src/main/java/org/geotools/imageio/unidata/UnidataImageReader.java

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,27 @@ private void initMapping(CoordinateSystem cs) {
384384
// check other dimensions
385385
for (CoordinateAxis axis : cs.getCoordinateAxes()) {
386386
// get from coordinate vars
387-
final CoordinateVariable<?> cv = coordinatesVariables.get(axis.getFullName());
388-
final String name = cv.getName();
389-
switch(cv.getAxisType()){
390-
case GeoX: case GeoY: case Lat: case Lon:
391-
continue;
392-
case Height: case Pressure: case RadialElevation: case RadialDistance: case GeoZ:
393-
if (UnidataCRSUtilities.VERTICAL_AXIS_NAMES.contains(name)) {
394-
dimensionsMapping.put(UnidataUtilities.ELEVATION_DIM, name);
395-
} else {
396-
dimensionsMapping.put(name.toUpperCase(), name);
387+
final CoordinateVariable<?> cv = coordinatesVariables.get(axis.getFullName());
388+
if (cv != null) {
389+
final String name = cv.getName();
390+
switch(cv.getAxisType()){
391+
case GeoX: case GeoY: case Lat: case Lon:
392+
continue;
393+
case Height: case Pressure: case RadialElevation: case RadialDistance: case GeoZ:
394+
if (UnidataCRSUtilities.VERTICAL_AXIS_NAMES.contains(name)) {
395+
dimensionsMapping.put(UnidataUtilities.ELEVATION_DIM, name);
396+
} else {
397+
dimensionsMapping.put(name.toUpperCase(), name);
398+
}
399+
break;
400+
case Time:
401+
dimensionsMapping.put(UnidataUtilities.TIME_DIM, name);
402+
break;
403+
}
404+
}else {
405+
if (LOGGER.isLoggable(Level.SEVERE)) {
406+
LOGGER.severe("Null coordinate variable: '" + axis.getFullName() + "' while processing input: " + this.getInput());
397407
}
398-
break;
399-
case Time:
400-
dimensionsMapping.put(UnidataUtilities.TIME_DIM, name);
401-
break;
402408
}
403409
}
404410
}
@@ -421,11 +427,20 @@ private void extractCoordinatesVariable( ) throws IOException {
421427
} else {
422428
// Workaround for Unsupported Axes
423429
Set<String> unsupported = UnidataUtilities.getUnsupportedDimensions();
424-
if(axis instanceof CoordinateAxis1D && unsupported.contains(axis.getFullName())){
430+
if (axis instanceof CoordinateAxis1D && unsupported.contains(axis.getFullName())) {
425431
axis.setAxisType(AxisType.GeoZ);
426-
coordinatesVariables.put(axis.getFullName(), CoordinateVariable.create((CoordinateAxis1D)axis));
427-
}else{
428-
LOGGER.warning("Unsupported axis: "+axis + " in input: "+this.getInput() + " has been found");
432+
coordinatesVariables.put(axis.getFullName(),
433+
CoordinateVariable.create((CoordinateAxis1D) axis));
434+
// Workaround for files that have a time dimension, but in a format that could not be parsed
435+
} else if ("time".equals(axis.getFullName())) {
436+
LOGGER.warning("Detected unparseable unit string in time axis: '"
437+
+ axis.getUnitsString() + "'.");
438+
axis.setAxisType(AxisType.Time);
439+
coordinatesVariables.put(axis.getFullName(),
440+
CoordinateVariable.create((CoordinateAxis1D) axis));
441+
} else {
442+
LOGGER.warning("Unsupported axis: " + axis + " in input: " + this.getInput()
443+
+ " has been found");
429444
}
430445
}
431446
}

0 commit comments

Comments
 (0)