이것은 내가 예상했던 것보다 힘들 것으로 판명되었는데, 이는 분명히 뭔가를 놓쳤다는 것을 의미합니다. 범위의 히스토그램을 작성하고 값을 포함하는 저장소를 선택하여 문제를 해결할 수 있습니다. 총 셀 수를 셀 영역으로 곱하면됩니다.
그래서 당신이 읽거나 범위를 만든 가정 :
private double selectCells(GridCoverage2D cov, int value) {
GridGeometry2D geom = cov.getGridGeometry();
// cov.show();
final OperationJAI op = new OperationJAI("Histogram");
ParameterValueGroup params = op.getParameters();
GridCoverage2D coverage;
params.parameter("Source").setValue(cov);
coverage = (GridCoverage2D) op.doOperation(params, null);
javax.media.jai.Histogram hist = (Histogram) coverage
.getProperty("histogram");
int total = hist.getSubTotal(0, value, value);
double area = calcAreaOfCell(geom);
Unit<?> unit = cov.getCoordinateReferenceSystem().getCoordinateSystem()
.getAxis(0).getUnit();
System.out.println("which gives " + (area * total) + " " + unit
+ "^2 area with value " + value);
return area * total;
}
private double calcAreaOfCell(GridGeometry2D geom) {
GridEnvelope gridRange = geom.getGridRange();
int width = gridRange.getHigh(0) - gridRange.getLow(0) + 1; // allow for the
int height = gridRange.getHigh(1) - gridRange.getLow(1) + 1;// 0th row/col
Envelope envelope = geom.getEnvelope();
double dWidth = envelope.getMaximum(0) - envelope.getMinimum(0);
double dHeight = envelope.getMaximum(1) - envelope.getMinimum(1);
double cellWidth = dWidth/width;
double cellHeight = dHeight/height;
return cellWidth * cellHeight;
}
을 분명히 당신은 히스토그램과 cellsize을 캐시 할 수 있습니다 번 이상을 호출 계획합니다.
당신은 진정한 영웅입니다! – jeanke
솔직히 말해서 나는 그것에 만족하지 않습니다. 그러나 그것은 효과적이다. –