use of oms3.annotations.Out in project hortonmachine by TheHortonMachine.
the class OmsRasterTransformer method process.
@Execute
public void process() throws Exception {
if (!concatOr(outRaster == null, doReset)) {
return;
}
Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
if (pInterpolation.equals(BILINEAR)) {
interpolation = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
} else if (pInterpolation.equals(BICUBIC)) {
interpolation = Interpolation.getInstance(Interpolation.INTERP_BICUBIC);
}
RenderedImage inRasterRI = inRaster.getRenderedImage();
RegionMap sourceRegion = CoverageUtilities.gridGeometry2RegionParamsMap(inRaster.getGridGeometry());
Envelope2D envelope2d = inRaster.getEnvelope2D();
Envelope targetEnvelope = new Envelope(envelope2d.getMinX(), envelope2d.getMaxX(), envelope2d.getMinY(), envelope2d.getMaxY());
Geometry targetGeometry = null;
GeometryFactory gf = GeometryUtilities.gf();
RenderedOp finalImg = null;
if (pAngle != null) {
pm.beginTask("Rotate raster by angle: " + pAngle, IHMProgressMonitor.UNKNOWN);
float centerX = 0f;
float centerY = 0f;
if (pEast == null) {
centerX = (float) envelope2d.getCenterX();
} else {
centerX = pEast.floatValue();
}
if (pNorth == null) {
centerY = (float) envelope2d.getCenterY();
} else {
centerY = pNorth.floatValue();
}
finalImg = RotateDescriptor.create(inRasterRI, centerX, centerY, (float) Math.toRadians(pAngle), interpolation, null, null);
// also keep track of the transforming envelope
AffineTransform rotationAT = new AffineTransform();
rotationAT.translate(centerX, centerY);
rotationAT.rotate(Math.toRadians(-pAngle));
rotationAT.translate(-centerX, -centerY);
MathTransform rotationTransform = new AffineTransform2D(rotationAT);
Envelope jtsEnv = new Envelope(targetEnvelope.getMinX(), targetEnvelope.getMaxX(), targetEnvelope.getMinY(), targetEnvelope.getMaxY());
targetEnvelope = JTS.transform(jtsEnv, rotationTransform);
Geometry rotGeometry = gf.toGeometry(jtsEnv);
targetGeometry = JTS.transform(rotGeometry, rotationTransform);
pm.done();
}
if (doFlipHorizontal) {
pm.beginTask("Flip horizontally...", IHMProgressMonitor.UNKNOWN);
if (finalImg != null) {
finalImg = TransposeDescriptor.create(finalImg, TransposeDescriptor.FLIP_HORIZONTAL, null);
} else {
finalImg = TransposeDescriptor.create(inRasterRI, TransposeDescriptor.FLIP_HORIZONTAL, null);
}
Envelope jtsEnv = new Envelope(targetEnvelope.getMinX(), targetEnvelope.getMaxX(), targetEnvelope.getMinY(), targetEnvelope.getMaxY());
targetGeometry = gf.toGeometry(jtsEnv);
pm.done();
}
if (doFlipVertical) {
pm.beginTask("Flip vertically...", IHMProgressMonitor.UNKNOWN);
if (finalImg != null) {
finalImg = TransposeDescriptor.create(finalImg, TransposeDescriptor.FLIP_VERTICAL, null);
} else {
finalImg = TransposeDescriptor.create(inRasterRI, TransposeDescriptor.FLIP_VERTICAL, null);
}
Envelope jtsEnv = new Envelope(targetEnvelope.getMinX(), targetEnvelope.getMaxX(), targetEnvelope.getMinY(), targetEnvelope.getMaxY());
targetGeometry = gf.toGeometry(jtsEnv);
pm.done();
}
if (pScaleX != null || pScaleY != null) {
float scaleX = 1f;
float scaleY = 1f;
if (pScaleX == null) {
scaleX = 1f;
} else {
scaleX = pScaleX.floatValue();
}
if (pScaleY == null) {
scaleY = 1f;
} else {
scaleY = pScaleY.floatValue();
}
pm.beginTask("Scale raster by: " + scaleX + " and " + scaleY, IHMProgressMonitor.UNKNOWN);
// float centerY = (float) envelope2d.getCenterY();
if (finalImg != null) {
finalImg = ScaleDescriptor.create(finalImg, new Float(scaleX), new Float(scaleY), new Float(0.0f), new Float(0.0f), interpolation, null);
} else {
finalImg = ScaleDescriptor.create(inRasterRI, new Float(scaleX), new Float(scaleY), new Float(0.0f), new Float(0.0f), interpolation, null);
}
// also keep track of the transforming envelope
AffineTransform scaleAT = new AffineTransform();
// scaleAT.translate(centerX, centerY);
scaleAT.scale(scaleX, scaleY);
// scaleAT.translate(-centerX, -centerY);
MathTransform scaleTransform = new AffineTransform2D(scaleAT);
Envelope jtsEnv = new Envelope(targetEnvelope.getMinX(), targetEnvelope.getMaxX(), targetEnvelope.getMinY(), targetEnvelope.getMaxY());
targetEnvelope = JTS.transform(jtsEnv, scaleTransform);
Geometry scaledGeometry = gf.toGeometry(jtsEnv);
targetGeometry = JTS.transform(scaledGeometry, scaleTransform);
pm.done();
}
if (pTransX != null || pTransY != null) {
float transX = 1f;
float transY = 1f;
if (pTransX == null) {
transX = 1f;
} else {
transX = pTransX.floatValue();
}
if (pTransY == null) {
transY = 1f;
} else {
transY = pTransY.floatValue();
}
pm.beginTask("Translate raster by: " + transX + " and " + transY, IHMProgressMonitor.UNKNOWN);
if (finalImg != null) {
finalImg = TranslateDescriptor.create(finalImg, transX, transY, interpolation, null);
} else {
finalImg = TranslateDescriptor.create(inRasterRI, transX, transY, interpolation, null);
}
// also keep track of the transforming envelope
AffineTransform translationAT = new AffineTransform();
translationAT.translate(transX, transY);
MathTransform translateTransform = new AffineTransform2D(translationAT);
if (targetGeometry == null) {
targetGeometry = gf.toGeometry(targetEnvelope);
}
targetEnvelope = JTS.transform(targetEnvelope, translateTransform);
targetGeometry = JTS.transform(targetGeometry, translateTransform);
pm.done();
}
if (finalImg != null) {
RegionMap targetRegion = new RegionMap();
targetRegion.put(NORTH, targetEnvelope.getMaxY());
targetRegion.put(SOUTH, targetEnvelope.getMinY());
targetRegion.put(WEST, targetEnvelope.getMinX());
targetRegion.put(EAST, targetEnvelope.getMaxX());
targetRegion.put(XRES, sourceRegion.getXres());
targetRegion.put(YRES, sourceRegion.getYres());
// targetRegion.put(ROWS, (double) height);
// targetRegion.put(COLS, (double) width);
CoordinateReferenceSystem crs = inRaster.getCoordinateReferenceSystem();
outRaster = CoverageUtilities.buildCoverage("out", finalImg, targetRegion, crs);
outBounds = FeatureUtilities.featureCollectionFromGeometry(crs, targetGeometry);
}
pm.done();
}
use of oms3.annotations.Out in project hortonmachine by TheHortonMachine.
the class OmsEnergyBalance method writeSafePoint.
@Finalize
public void writeSafePoint() {
if (pEndsafepoint != null && new File(pEndsafepoint).getParentFile() != null) {
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = new FileOutputStream(pEndsafepoint);
out = new ObjectOutputStream(fos);
out.writeObject(safePoint);
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
use of oms3.annotations.Out in project hortonmachine by TheHortonMachine.
the class FieldAccess method out.
/**
* a field is sending a new value (out)
*
* @return the object value in out
* @throws java.lang.Exception
*/
@Override
public void out() throws Exception {
Object val = getFieldValue();
if (ens.shouldFire()) {
DataflowEvent e = new DataflowEvent(ens.getController(), this, val);
// DataflowEvent e = new DataflowEvent(ens.getController(), this, access.toObject());
ens.fireOut(e);
// the value might be altered
val = e.getValue();
}
// if data==null this unconsumed @Out, its OK but we do not want to set it.
if (data != null) {
data.setValue(val);
}
}
use of oms3.annotations.Out in project hortonmachine by TheHortonMachine.
the class Components method figureOutConnect.
/**
* Figure out connectivity and generate Java statements.
* @param comps
*/
public static void figureOutConnect(PrintStream w, Object... comps) {
// add all the components via Proxy.
List<ComponentAccess> l = new ArrayList<ComponentAccess>();
for (Object c : comps) {
l.add(new ComponentAccess(c));
}
// find all out slots
for (ComponentAccess cp_out : l) {
w.println("// connect " + objName(cp_out));
// over all input slots.
for (Access fout : cp_out.outputs()) {
String s = " out2in(" + objName(cp_out) + ", \"" + fout.getField().getName() + "\"";
for (ComponentAccess cp_in : l) {
// skip if it is the same component.
if (cp_in == cp_out) {
continue;
}
// out points to in
for (Access fin : cp_in.inputs()) {
// name equivalence enought for now.
if (fout.getField().getName().equals(fin.getField().getName())) {
s = s + ", " + objName(cp_in);
}
}
}
w.println(s + ");");
}
w.println();
}
}
use of oms3.annotations.Out in project hortonmachine by TheHortonMachine.
the class Convert method param.
public static String param(String file) {
File param = new File(file);
if (!param.isAbsolute()) {
String work = System.getProperty("oms3.work");
if (work == null) {
return "Error no $work property found, use full qualifies name instead.)";
}
param = new File(work + "/data", file);
}
String name = param.getName().substring(0, param.getName().indexOf('.'));
File out = new File(param.getParentFile(), name + ".csv");
try {
MmsParamInfo info = MMSParameterAdapter.map(param);
info.store(new FileOutputStream(out));
return " Converted: '" + file + "' -> '" + out + "'\n";
} catch (IOException ex) {
return "Error: " + ex.getMessage();
}
}
Aggregations