VectorToRasterProcess implements VectorProcess { @DescribeResult(name = "result", description = "Rasterized grid") public GridCoverage2D execute( @DescribeParameter(name = "features", description = "Features to process", min = 1, max = 1) SimpleFeatureCollection features, @DescribeParameter(name = "rasterWidth", description = "Width of the output grid in pixels", min = 1, max = 1, minValue = 1) Integer rasterWidth, @DescribeParameter(name = "rasterHeight", description = "Height of the output grid in pixels", min = 1, max = 1, minValue = 1) Integer rasterHeight, @DescribeParameter(name = "title", description = "Title to use for the output grid", min = 0, max = 1, defaultValue = "raster" ) String title, @DescribeParameter(name = "attribute", description = "Attribute name to use for the raster cell values", min = 1, max = 1) String attribute, @DescribeParameter(name = "bounds", description = "Bounding box of the area to rasterize", min = 0, max = 1) Envelope bounds, ProgressListener progressListener) { Expression attributeExpr = null; try { attributeExpr = ECQL.toExpression(attribute); } catch(CQLException e) { throw new VectorToRasterException(e); } return convert(features, attributeExpr, new Dimension(rasterWidth, rasterHeight), bounds, title, progressListener); }  static GridCoverage2D process(
            SimpleFeatureCollection features,
            Object attribute,
            Dimension gridDim,
            Envelope bounds,
            String covName,
            ProgressListener monitor); @DescribeResult(name = "result", description = "Rasterized grid") GridCoverage2D execute(
        @DescribeParameter(name = "features", description = "Features to process", min = 1, max = 1) SimpleFeatureCollection features,
        @DescribeParameter(name = "rasterWidth", description = "Width of the output grid in pixels", min = 1, max = 1, minValue = 1) Integer rasterWidth,
        @DescribeParameter(name = "rasterHeight", description = "Height of the output grid in pixels", min = 1, max = 1, minValue = 1) Integer rasterHeight,
        @DescribeParameter(name = "title", description = "Title to use for the output grid", min = 0, max = 1, defaultValue = "raster" ) String title,
        @DescribeParameter(name = "attribute", description = "Attribute name to use for the raster cell values", min = 1, max = 1) String attribute,
        @DescribeParameter(name = "bounds", description = "Bounding box of the area to rasterize", min = 0, max = 1) Envelope bounds,
        ProgressListener progressListener);  }
@Test public void executeProcessWithFloat() throws Exception { System.out.println(" execute process using float values"); Process p = Processors.createProcess(new NameImpl("vec", "VectorToRaster")); assertNotNull(p); SimpleFeatureCollection features = createFloatLines(); ReferencedEnvelope bounds = features.getBounds(); Dimension gridDim = new Dimension( (int)bounds.getWidth(), (int)bounds.getHeight()); ProgressListener monitor = null; Map<String, Object> map = new HashMap<String, Object>(); map.put(AbstractFeatureCollectionProcessFactory.FEATURES.key, features); map.put("attribute", "value"); map.put("rasterWidth", gridDim.width); map.put("rasterHeight", gridDim.height); map.put("bounds", bounds); Map<String, Object> result = p.execute(map, monitor); GridCoverage2D cov = (GridCoverage2D) result.get("result"); SimpleFeatureIterator iter = features.features(); float[] covValue = new float[1]; GridCoordinates2D gridP = new GridCoordinates2D(); while (iter.hasNext()) { SimpleFeature feature = iter.next(); Coordinate[] coords = ((Geometry)feature.getDefaultGeometry()).getCoordinates(); for (Coordinate coord : coords) { gridP.x = coord.x == gridDim.width ? (int)coord.x-1 : (int)coord.x; gridP.y = coord.y == gridDim.height ? (int)coord.y-1 : (int)coord.y; cov.evaluate(gridP, covValue); Float value = (Float)feature.getAttribute("value"); assertEquals(value.floatValue(), covValue[0], .01); } } }
@Test public void executeProcessWithString() throws Exception { Process p = Processors.createProcess(new NameImpl("vec", "VectorToRaster")); assertNotNull(p); SimpleFeatureCollection features = createStringLines(); ReferencedEnvelope bounds = features.getBounds(); Dimension gridDim = new Dimension( (int)bounds.getWidth(), (int)bounds.getHeight()); ProgressListener monitor = null; Map<String, Object> map = new HashMap<String, Object>(); map.put(AbstractFeatureCollectionProcessFactory.FEATURES.key, features); map.put("attribute", "value"); map.put("rasterWidth", gridDim.width); map.put("rasterHeight", gridDim.height); map.put("bounds", bounds); Map<String, Object> result = p.execute(map, monitor); GridCoverage2D cov = (GridCoverage2D) result.get("result"); SimpleFeatureIterator iter = features.features(); int[] covValue = new int[1]; GridCoordinates2D gridP = new GridCoordinates2D(); while (iter.hasNext()) { SimpleFeature feature = iter.next(); Coordinate[] coords = ((Geometry)feature.getDefaultGeometry()).getCoordinates(); for (Coordinate coord : coords) { gridP.x = coord.x == gridDim.width ? (int)coord.x-1 : (int)coord.x; gridP.y = coord.y == gridDim.height ? (int)coord.y-1 : (int)coord.y; cov.evaluate(gridP, covValue); int value = Integer.valueOf((String)feature.getAttribute("value")); assertEquals(covValue[0], value); } } }