use of org.hortonmachine.gears.modules.r.interpolation2d.core.ISurfaceInterpolator in project hortonmachine by TheHortonMachine.
the class OmsHoleFiller method process.
@Execute
public void process() throws Exception {
checkNull(inRaster);
ISurfaceInterpolator interpolator;
if (pMode.equals(IDW)) {
interpolator = new IDWInterpolator(pBuffer);
} else {
interpolator = new TPSInterpolator(pBuffer);
}
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
int rows = regionMap.getRows();
int cols = regionMap.getCols();
WritableRaster outWR = CoverageUtilities.renderedImage2WritableRaster(inRaster.getRenderedImage(), false);
WritableRandomIter outIter = CoverageUtilities.getWritableRandomIterator(outWR);
GridGeometry2D gridGeometry = inRaster.getGridGeometry();
PreparedGeometry preparedRoi = null;
if (inROI != null) {
List<Geometry> roiList = FeatureUtilities.featureCollectionToGeometriesList(inROI, false, null);
GeometryCollection gc = new GeometryCollection(roiList.toArray(GeometryUtilities.TYPE_GEOMETRY), gf);
preparedRoi = PreparedGeometryFactory.prepare(gc);
}
pm.beginTask("Filling holes...", cols - 2);
for (int r = 1; r < rows - 1; r++) {
for (int c = 1; c < cols - 1; c++) {
if (pm.isCanceled()) {
return;
}
double value = outIter.getSampleDouble(c, r, 0);
if (isNovalue(value)) {
DirectPosition worldPosition = gridGeometry.gridToWorld(new GridCoordinates2D(c, r));
double[] coordinate = worldPosition.getCoordinate();
Coordinate pointCoordinate = new Coordinate(coordinate[0], coordinate[1]);
Point point = gf.createPoint(pointCoordinate);
if (preparedRoi == null || preparedRoi.intersects(point)) {
// TODO this could be done considering more points and more far away points.
// For now, this works.
List<Coordinate> surroundingValids = getValidSurroundingPoints(outIter, gridGeometry, c, r);
if (surroundingValids.size() > 3) {
double newValue = interpolator.getValue(surroundingValids.toArray(new Coordinate[0]), pointCoordinate);
outIter.setSample(c, r, 0, newValue);
}
}
}
}
pm.worked(1);
}
pm.done();
outIter.done();
outRaster = CoverageUtilities.buildCoverage("nulled", outWR, regionMap, inRaster.getCoordinateReferenceSystem());
}
Aggregations