use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.
the class ReformatProcess method execute.
@Override
protected void execute() throws ProcessException {
ArgumentChecks.ensureNonNull("inputParameter", inputParameters);
final RenderedImage inputImage = inputParameters.getValue(IN_IMAGE);
final int inputType = inputParameters.getValue(IN_DATATYPE);
final SampleModel inputSampleModel = inputImage.getSampleModel();
// check type, if same return the original coverage
if (inputSampleModel.getDataType() == inputType) {
outputParameters.getOrCreate(OUT_IMAGE).setValue(inputImage);
return;
}
// create the output image
final int width = inputImage.getWidth();
final int height = inputImage.getHeight();
final int nbBand = inputSampleModel.getNumBands();
final Point upperLeft = new Point(inputImage.getMinX(), inputImage.getMinY());
final WritableRaster raster;
try {
raster = createRaster(inputType, width, height, nbBand, upperLeft);
} catch (IllegalArgumentException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
// TODO try to reuse java colormodel if possible
// create a temporary fallback colormodel which will always work
// extract grayscale min/max from sample dimension
final ColorModel graycm = ColorModelFactory.createGrayScale(inputType, nbBand, 0, 0, 10);
final BufferedImage resultImage = new BufferedImage(graycm, raster, false, new Hashtable<Object, Object>());
// copy datas
final PixelIterator readIte = new PixelIterator.Builder().create(inputImage);
final WritablePixelIterator writeIte = new PixelIterator.Builder().createWritable(raster);
while (readIte.next() && writeIte.next()) {
for (int b = 0; b < nbBand; b++) {
writeIte.setSample(b, readIte.getSampleDouble(b));
}
}
outputParameters.getOrCreate(OUT_IMAGE).setValue(resultImage);
}
use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.
the class BufferProcess method execute.
@Override
protected void execute() throws ProcessException {
try {
final Geometry geom = inputParameters.getValue(GEOM);
final double distance = inputParameters.getValue(DISTANCE);
int segments = 0;
if (inputParameters.getValue(SEGMENTS) != null) {
segments = inputParameters.getValue(SEGMENTS);
}
int endStyle = 2;
if (inputParameters.getValue(ENDSTYLE) != null) {
endStyle = inputParameters.getValue(ENDSTYLE);
}
final CoordinateReferenceSystem geomCRS = JTS.findCoordinateReferenceSystem(geom);
Geometry result = JTS.getFactory().buildGeometry(Collections.EMPTY_LIST);
if (segments > 0) {
if (endStyle != 0) {
result = geom.buffer(distance, segments, endStyle);
} else {
result = geom.buffer(distance, segments);
}
} else {
result = geom.buffer(distance);
}
JTS.setCRS(result, geomCRS);
outputParameters.getOrCreate(RESULT_GEOM).setValue(result);
} catch (NoSuchAuthorityCodeException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
} catch (FactoryException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
}
use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.
the class CentroidProcess method execute.
@Override
protected void execute() throws ProcessException {
try {
final Geometry geom = inputParameters.getValue(GEOM);
final CoordinateReferenceSystem geomCRS = JTS.findCoordinateReferenceSystem(geom);
final Point result = geom.getCentroid();
JTS.setCRS(result, geomCRS);
outputParameters.getOrCreate(RESULT_GEOM).setValue(result);
} catch (NoSuchAuthorityCodeException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
} catch (FactoryException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
}
use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.
the class ConvexHullProcess method execute.
@Override
protected void execute() throws ProcessException {
try {
final Geometry geom = inputParameters.getValue(ConvexHullDescriptor.GEOM);
final CoordinateReferenceSystem geomCRS = JTS.findCoordinateReferenceSystem(geom);
final Geometry result = geom.convexHull();
JTS.setCRS(result, geomCRS);
outputParameters.getOrCreate(ConvexHullDescriptor.RESULT_GEOM).setValue(result);
} catch (NoSuchAuthorityCodeException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
} catch (FactoryException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
}
use of org.geotoolkit.process.ProcessException in project geotoolkit by Geomatys.
the class CrossesProcess method execute.
@Override
protected void execute() throws ProcessException {
try {
final Geometry geom1 = inputParameters.getValue(CrossesDescriptor.GEOM1);
Geometry geom2 = inputParameters.getValue(CrossesDescriptor.GEOM2);
// ensure geometries are in the same CRS
final CoordinateReferenceSystem resultCRS = JTS.getCommonCRS(geom1, geom2);
if (JTS.isConversionNeeded(geom1, geom2)) {
geom2 = JTS.convertToCRS(geom2, resultCRS);
}
final Boolean result = (Boolean) geom1.crosses(geom2);
outputParameters.getOrCreate(CrossesDescriptor.RESULT).setValue(result);
} catch (FactoryException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
} catch (TransformException ex) {
throw new ProcessException(ex.getMessage(), this, ex);
}
}
Aggregations