@Test public void rasterizePolygons() throws Exception { System.out.println(" rasterize polygons"); SimpleFeatureCollection features = createPolys(); ReferencedEnvelope bounds = features.getBounds(); Dimension gridDim = new Dimension( (int)bounds.getWidth(), (int)bounds.getHeight()); String covName = "Test"; ProgressListener monitor = null; GridCoverage2D cov = VectorToRasterProcess.process( features, "value", gridDim, bounds, covName, monitor); Map<Integer, Envelope> rects = new HashMap<Integer, Envelope>(); SimpleFeatureIterator iter = features.features(); while (iter.hasNext()) { SimpleFeature sf = iter.next(); rects.put((Integer)sf.getAttribute("value"), ((Geometry) sf.getDefaultGeometry()).getEnvelopeInternal()); } try { MathTransform2D mt = cov.getGridGeometry().getGridToCRS2D(PixelOrientation.CENTER); Point gridP = new Point(); Point2D.Double geoP = new Point2D.Double(); int[] covValue = new int[1]; for (gridP.y = 0; gridP.y < gridDim.height; gridP.y++) { for (gridP.x = 0; gridP.x < gridDim.width; gridP.x++) { mt.transform(gridP, geoP); } cov.evaluate(geoP, covValue); if (covValue[0] != 0) { assertTrue(rects.get(covValue[0]).contains(geoP.x, geoP.y)); } } } catch (TransformException tex) { throw new RuntimeException(tex); } }
public static GridCoverage2D process( SimpleFeatureCollection features, Object attribute, Dimension gridDim, Envelope bounds, String covName, ProgressListener monitor) throws VectorToRasterException { VectorToRasterFactory factory = new VectorToRasterFactory(); VectorToRasterProcess process = factory.create(); return process.convert(features, attribute, gridDim, bounds, covName, monitor); }
VectorToRasterProcess extends AbstractFeatureCollectionProcess { public static GridCoverage2D process( SimpleFeatureCollection features, Object attribute, Dimension gridDim, Envelope bounds, String covName, ProgressListener monitor) throws VectorToRasterException { VectorToRasterFactory factory = new VectorToRasterFactory(); VectorToRasterProcess process = factory.create(); return process.convert(features, attribute, gridDim, bounds, covName, monitor); } }
VectorToRasterProcess extends AbstractFeatureCollectionProcess { public static GridCoverage2D process( SimpleFeatureCollection features, Object attribute, Dimension gridDim, Envelope bounds, String covName, ProgressListener monitor) throws VectorToRasterException { VectorToRasterFactory factory = new VectorToRasterFactory(); VectorToRasterProcess process = factory.create(); return process.convert(features, attribute, gridDim, bounds, covName, monitor); } VectorToRasterProcess(VectorToRasterFactory factory); }
VectorToRasterProcess extends AbstractFeatureCollectionProcess { public static GridCoverage2D process( SimpleFeatureCollection features, Object attribute, Dimension gridDim, Envelope bounds, String covName, ProgressListener monitor) throws VectorToRasterException { VectorToRasterFactory factory = new VectorToRasterFactory(); VectorToRasterProcess process = factory.create(); return process.convert(features, attribute, gridDim, bounds, covName, monitor); } VectorToRasterProcess(VectorToRasterFactory factory); static GridCoverage2D process(
            SimpleFeatureCollection features,
            Object attribute,
            Dimension gridDim,
            Envelope bounds,
            String covName,
            ProgressListener monitor); Map<String, Object> execute( Map<String, Object> input, ProgressListener monitor ); }
VectorToRasterProcess extends AbstractFeatureCollectionProcess { public static GridCoverage2D process( SimpleFeatureCollection features, Object attribute, Dimension gridDim, Envelope bounds, String covName, ProgressListener monitor) throws VectorToRasterException { VectorToRasterFactory factory = new VectorToRasterFactory(); VectorToRasterProcess process = factory.create(); return process.convert(features, attribute, gridDim, bounds, covName, monitor); } VectorToRasterProcess(VectorToRasterFactory factory); static GridCoverage2D process(
            SimpleFeatureCollection features,
            Object attribute,
            Dimension gridDim,
            Envelope bounds,
            String covName,
            ProgressListener monitor); Map<String, Object> execute( Map<String, Object> input, ProgressListener monitor );  }