use of org.hortonmachine.gears.modules.r.scanline.OmsScanLineRasterizer in project hortonmachine by TheHortonMachine.
the class OmsRasterVectorIntersector method process.
@Execute
public void process() throws Exception {
checkNull(inRaster, inVector);
SimpleFeatureType schema = inVector.getSchema();
if (!EGeometryType.isPolygon(schema.getGeometryDescriptor())) {
throw new ModelsRuntimeException("The module works only with polygon vectors.", this);
}
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
OmsScanLineRasterizer raster = new OmsScanLineRasterizer();
raster.inVector = inVector;
raster.pCols = regionMap.getCols();
raster.pRows = regionMap.getRows();
raster.pNorth = regionMap.getNorth();
raster.pSouth = regionMap.getSouth();
raster.pEast = regionMap.getEast();
raster.pWest = regionMap.getWest();
raster.pValue = 1.0;
raster.process();
GridCoverage2D rasterizedVector = raster.outRaster;
OmsCutOut cutout = new OmsCutOut();
cutout.pm = pm;
cutout.inRaster = inRaster;
cutout.inMask = rasterizedVector;
cutout.doInverse = doInverse;
cutout.process();
outRaster = cutout.outRaster;
}
use of org.hortonmachine.gears.modules.r.scanline.OmsScanLineRasterizer in project hortonmachine by TheHortonMachine.
the class OmsBobTheBuilder method process.
@Execute
public void process() throws Exception {
checkNull(inRaster, inArea, inElevations, fElevation);
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
int cols = regionMap.getCols();
int rows = regionMap.getRows();
double west = regionMap.getWest();
double east = regionMap.getEast();
double south = regionMap.getSouth();
double north = regionMap.getNorth();
ReferencedEnvelope vectorBounds = inArea.getBounds();
if (!isBetween(vectorBounds.getMaxX(), west, east) || !isBetween(vectorBounds.getMinX(), west, east) || !isBetween(vectorBounds.getMaxY(), south, north) || !isBetween(vectorBounds.getMinY(), south, north)) {
throw new ModelsIllegalargumentException("The vector map has to be within the raster map boundaries.", this, pm);
}
List<FeatureMate> polygonMates = FeatureUtilities.featureCollectionToMatesList(inArea);
String polygonMessage = "This operation can be applied only to a single polygon.";
if (polygonMates.size() != 1) {
throw new ModelsIllegalargumentException(polygonMessage, this, pm);
}
FeatureMate polygonMate = polygonMates.get(0);
Geometry polygon = polygonMate.getGeometry();
if (polygon instanceof MultiPolygon) {
polygon = polygon.getGeometryN(0);
}
if (!(polygon instanceof Polygon)) {
throw new ModelsIllegalargumentException(polygonMessage, this, pm);
}
List<FeatureMate> pointsMates = FeatureUtilities.featureCollectionToMatesList(inElevations);
if (doUseOnlyInternal) {
PreparedGeometry preparedPolygon = PreparedGeometryFactory.prepare(polygon);
List<FeatureMate> tmpPointsMates = new ArrayList<FeatureMate>();
for (FeatureMate pointMate : pointsMates) {
Geometry geometry = pointMate.getGeometry();
if (preparedPolygon.covers(geometry)) {
tmpPointsMates.add(pointMate);
}
}
pointsMates = tmpPointsMates;
}
if (pointsMates.size() < 4) {
throw new ModelsIllegalargumentException("You need at least 4 elevation points (the more, the better) to gain a decent interpolation.", this, pm);
}
List<Coordinate> controlPointsList = new ArrayList<Coordinate>();
if (doPolygonborder) {
pm.beginTask("Extract polygon border...", IHMProgressMonitor.UNKNOWN);
Coordinate[] polygonCoordinates = polygon.getCoordinates();
List<ProfilePoint> profile = CoverageUtilities.doProfile(inRaster, polygonCoordinates);
for (ProfilePoint profilePoint : profile) {
Coordinate position = profilePoint.getPosition();
double elevation = profilePoint.getElevation();
Coordinate coord = new Coordinate(position.x, position.y, elevation);
controlPointsList.add(coord);
}
pm.done();
}
for (FeatureMate pointsMate : pointsMates) {
Coordinate coordinate = pointsMate.getGeometry().getCoordinate();
double elev = pointsMate.getAttribute(fElevation, Double.class);
Coordinate coord = new Coordinate(coordinate.x, coordinate.y, elev);
controlPointsList.add(coord);
}
Coordinate[] controlPoints = controlPointsList.toArray(new Coordinate[0]);
GridGeometry2D gridGeometry = inRaster.getGridGeometry();
RandomIter elevIter = CoverageUtilities.getRandomIterator(inRaster);
WritableRaster outputWR = CoverageUtilities.createWritableRaster(cols, rows, null, null, HMConstants.doubleNovalue);
WritableRandomIter outputIter = RandomIterFactory.createWritable(outputWR, null);
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
newCollection.add(polygonMate.getFeature());
OmsScanLineRasterizer slRasterizer = new OmsScanLineRasterizer();
slRasterizer.pm = pm;
slRasterizer.inVector = newCollection;
slRasterizer.pCols = cols;
slRasterizer.pRows = rows;
slRasterizer.pNorth = north;
slRasterizer.pSouth = south;
slRasterizer.pEast = east;
slRasterizer.pWest = west;
slRasterizer.pValue = 1.0;
slRasterizer.process();
GridCoverage2D outRasterized = slRasterizer.outRaster;
if (pMaxbuffer < 0)
pMaxbuffer = Math.max(vectorBounds.getWidth(), vectorBounds.getHeight());
IDWInterpolator interpolator = new IDWInterpolator(pMaxbuffer);
final GridCoordinates2D gridCoord = new GridCoordinates2D();
RandomIter rasterizedIter = CoverageUtilities.getRandomIterator(outRasterized);
pm.beginTask("Interpolating...", cols);
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
double probValue = rasterizedIter.getSampleDouble(c, r, 0);
if (isNovalue(probValue)) {
continue;
}
gridCoord.setLocation(c, r);
DirectPosition world = gridGeometry.gridToWorld(gridCoord);
double[] coordinate = world.getCoordinate();
double interpolated = interpolator.getValue(controlPoints, new Coordinate(coordinate[0], coordinate[1]));
outputIter.setSample(c, r, 0, interpolated);
}
pm.worked(1);
}
pm.done();
pm.beginTask("Merging with original raster...", cols);
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
double interpolatedValue = outputIter.getSampleDouble(c, r, 0);
double rasterValue = elevIter.getSampleDouble(c, r, 0);
if (isNovalue(interpolatedValue)) {
if (!isNovalue(rasterValue))
outputIter.setSample(c, r, 0, rasterValue);
} else {
if (doErode) {
// any value generated is ok
outputIter.setSample(c, r, 0, interpolatedValue);
} else {
// only values higher than the raster are ok
if (!isNovalue(rasterValue)) {
if (rasterValue < interpolatedValue) {
outputIter.setSample(c, r, 0, interpolatedValue);
} else {
outputIter.setSample(c, r, 0, rasterValue);
}
} else {
outputIter.setSample(c, r, 0, interpolatedValue);
}
}
}
}
pm.worked(1);
}
pm.done();
outRaster = CoverageUtilities.buildCoverage("raster", outputWR, regionMap, inRaster.getCoordinateReferenceSystem());
}
use of org.hortonmachine.gears.modules.r.scanline.OmsScanLineRasterizer in project hortonmachine by TheHortonMachine.
the class ScanLineRasterizer method process.
@Execute
public void process() throws Exception {
OmsScanLineRasterizer scanlinerasterizer = new OmsScanLineRasterizer();
scanlinerasterizer.inVector = getVector(inVector);
scanlinerasterizer.inRaster = getRaster(inRaster);
scanlinerasterizer.pValue = pValue;
scanlinerasterizer.fCat = fCat;
scanlinerasterizer.pNorth = pNorth;
scanlinerasterizer.pSouth = pSouth;
scanlinerasterizer.pWest = pWest;
scanlinerasterizer.pEast = pEast;
scanlinerasterizer.pRows = pRows;
scanlinerasterizer.pCols = pCols;
scanlinerasterizer.pUsePointInPolygon = pUsePointInPolygon;
scanlinerasterizer.pm = pm;
scanlinerasterizer.doProcess = doProcess;
scanlinerasterizer.doReset = doReset;
scanlinerasterizer.process();
dumpRaster(scanlinerasterizer.outRaster, outRaster);
}
use of org.hortonmachine.gears.modules.r.scanline.OmsScanLineRasterizer in project hortonmachine by TheHortonMachine.
the class RasterExtruder method process.
@Execute
public void process() throws Exception {
checkNull(inRaster, inVector, pAddingField);
GridCoverage2D dtm = getRaster(inRaster);
SimpleFeatureCollection vector = getVector(inVector);
OmsScanLineRasterizer r = new OmsScanLineRasterizer();
r.inRaster = dtm;
r.inVector = vector;
r.fCat = pAddingField;
r.process();
GridCoverage2D outGC = r.outRaster;
GridCoverage2D mergedGC = CoverageUtilities.mergeCoverages(outGC, dtm);
dumpRaster(mergedGC, outRaster);
}
use of org.hortonmachine.gears.modules.r.scanline.OmsScanLineRasterizer in project hortonmachine by TheHortonMachine.
the class OmsMeltonNumber method process.
@Execute
public void process() throws Exception {
checkNull(inElev, inFans);
RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inElev);
int cols = regionMap.getCols();
int rows = regionMap.getRows();
double west = regionMap.getWest();
double east = regionMap.getEast();
double south = regionMap.getSouth();
double north = regionMap.getNorth();
AttributeType type = inFans.getSchema().getType(fId);
if (type == null) {
throw new ModelsIllegalargumentException(MessageFormat.format("The attribute {0} does not exist in the vector map.", fId), this, pm);
}
List<SimpleFeature> fansList = FeatureUtilities.featureCollectionToList(inFans);
outMelton = new String[fansList.size()][2];
int index = 0;
pm.beginTask("Calculating Melton number for fans...", fansList.size());
for (SimpleFeature fan : fansList) {
Object attribute = fan.getAttribute(fId);
// rasterize the fan
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
newCollection.add(fan);
OmsScanLineRasterizer rasterizer = new OmsScanLineRasterizer();
rasterizer.inVector = newCollection;
rasterizer.pCols = cols;
rasterizer.pRows = rows;
rasterizer.pNorth = north;
rasterizer.pSouth = south;
rasterizer.pEast = east;
rasterizer.pWest = west;
rasterizer.pValue = 1.0;
rasterizer.pm = new DummyProgressMonitor();
rasterizer.process();
GridCoverage2D rasterizedFan = rasterizer.outRaster;
GridCoverage2D fanElev = CoverageUtilities.coverageValuesMapper(inElev, rasterizedFan);
// extract min and max
OmsRasterSummary summary = new OmsRasterSummary();
summary.pm = new DummyProgressMonitor();
summary.inRaster = fanElev;
summary.process();
double min = summary.outMin;
double max = summary.outMax;
// get the suface of the fan
Geometry geometry = (Geometry) fan.getDefaultGeometry();
double area = geometry.getArea();
// calculate Melton
double melton = (max - min) / sqrt(area);
outMelton[index][0] = attribute.toString();
outMelton[index][1] = String.valueOf(melton);
index++;
pm.message(MessageFormat.format("id: {0} gave Melton number: {1}", attribute.toString(), melton));
pm.message("Based on max: " + max + " min: " + min + " and area: " + area);
pm.worked(1);
}
pm.done();
}
Aggregations