Skip to content

Commit

Permalink
When subsetting a coverage axis, use original values instead of midpo…
Browse files Browse the repository at this point in the history
…ints; these coords are used to find a record
  • Loading branch information
tdrwenski authored and haileyajohnson committed Jun 16, 2022
1 parent 49d9528 commit e69c6e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,7 @@ CoverageCoordAxisBuilder subsetByIndex(Range range) throws InvalidRangeException

// subset(int ncoords, double start, double end, double[] values)
CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(axis);
builder.subset(ncoords, axis.getCoordMidpoint(range.first()), axis.getCoordMidpoint(range.last()), resolution,
subsetValues);
builder.subset(ncoords, axis.getCoord(range.first()), axis.getCoord(range.last()), resolution, subsetValues);
builder.setRange(range);
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ public boolean isAscending() {
throw new IllegalStateException("unknown spacing" + spacing);
}

public double getCoord(int index) {
if (index < 0 || index >= getNcoords()) {
throw new IllegalArgumentException("Index out of range=" + index);
}
loadValuesIfNeeded();

switch (spacing) {
case regularPoint:
case regularInterval:
return startValue + index * getResolution();

case irregularPoint:
case contiguousInterval:
case discontiguousInterval:
return values[index];
}
throw new IllegalStateException("Unknown spacing=" + spacing);
}

public double getCoordMidpoint(int index) {
if (index < 0 || index >= getNcoords())
throw new IllegalArgumentException("Index out of range=" + index);
Expand Down

0 comments on commit e69c6e2

Please sign in to comment.