@Test public void testConvert() throws Exception { System.out.println(" simple grid"); final float[][] DATA = { {1, 1, 0, 1}, {0, 1, 0, 0}, {0, 1, 1, 1}, {1, 0, 0, 1} }; final int PERIMETER = 24; final int AREA = 9; GridCoverage2D cov = covFactory.create( "coverage", DATA, new ReferencedEnvelope(0, DATA[0].length, 0, DATA.length, null)); int band = 0; Set<Double> outsideValues = Collections.singleton(0D); ProgressListener progress = null; SimpleFeatureCollection fc = RasterToVectorProcess.process(cov, band, null, outsideValues, true, progress); double perimeter = 0; double area = 0; FeatureIterator iter = fc.features(); try { while (iter.hasNext()) { SimpleFeature feature = (SimpleFeature) iter.next(); Polygon poly = (Polygon) feature.getDefaultGeometry(); perimeter += poly.getLength(); area += poly.getArea(); } } finally { iter.close(); } assertEquals(AREA, (int) Math.round(area)); assertEquals(PERIMETER, (int) Math.round(perimeter)); }
private SimpleFeatureCollection convert( GridCoverage2D cov, int band, Envelope bounds, Collection<Double> outsideValues, boolean insideEdges, ProgressListener monitor) throws ProcessException { if (monitor == null) { monitor = new NullProgressListener(); } else { monitor.started(); } ReferencedEnvelope workingBounds = null; if (bounds == null) { workingBounds = new ReferencedEnvelope(cov.getEnvelope()); } else { CoordinateReferenceSystem sourceCRS = bounds.getCoordinateReferenceSystem(); CoordinateReferenceSystem targetCRS = cov.getCoordinateReferenceSystem(); if (sourceCRS != null) { if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { throw new ProcessException("CRS of bounds must match that of the coverage"); } } ReferencedEnvelope inputBounds = new ReferencedEnvelope(bounds); ReferencedEnvelope covBounds = new ReferencedEnvelope(cov.getEnvelope()); workingBounds = new ReferencedEnvelope(covBounds.intersection(inputBounds), targetCRS); if (workingBounds == null || workingBounds.isEmpty()) { throw new ProcessException("Specified bounds lie wholly outside of coverage"); } } try { monitor.setTask(new SimpleInternationalString("Initializing")); initialize(cov, workingBounds, new SubProgressListener(monitor, 10)); monitor.setTask(new SimpleInternationalString("Vectorizing")); vectorizeAndCollectBoundaries(band, outsideValues, insideEdges, new SubProgressListener(monitor, 70)); SimpleFeatureType schema = RasterToVectorFactory.getSchema(cov .getCoordinateReferenceSystem()); monitor.setTask(new SimpleInternationalString("Creating polygon features")); SimpleFeatureCollection features = assembleFeatures(cov, band, insideEdges, schema, new SubProgressListener(monitor, 20)); return features; } catch (Exception ex) { throw new ProcessException(ex); } finally { monitor.complete(); } }
RasterToVectorProcess extends AbstractProcess { private SimpleFeatureCollection convert( GridCoverage2D cov, int band, Envelope bounds, Collection<Double> outsideValues, boolean insideEdges, ProgressListener monitor) throws ProcessException { if (monitor == null) { monitor = new NullProgressListener(); } else { monitor.started(); } ReferencedEnvelope workingBounds = null; if (bounds == null) { workingBounds = new ReferencedEnvelope(cov.getEnvelope()); } else { CoordinateReferenceSystem sourceCRS = bounds.getCoordinateReferenceSystem(); CoordinateReferenceSystem targetCRS = cov.getCoordinateReferenceSystem(); if (sourceCRS != null) { if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { throw new ProcessException("CRS of bounds must match that of the coverage"); } } ReferencedEnvelope inputBounds = new ReferencedEnvelope(bounds); ReferencedEnvelope covBounds = new ReferencedEnvelope(cov.getEnvelope()); workingBounds = new ReferencedEnvelope(covBounds.intersection(inputBounds), targetCRS); if (workingBounds == null || workingBounds.isEmpty()) { throw new ProcessException("Specified bounds lie wholly outside of coverage"); } } try { monitor.setTask(new SimpleInternationalString("Initializing")); initialize(cov, workingBounds, new SubProgressListener(monitor, 10)); monitor.setTask(new SimpleInternationalString("Vectorizing")); vectorizeAndCollectBoundaries(band, outsideValues, insideEdges, new SubProgressListener(monitor, 70)); SimpleFeatureType schema = RasterToVectorFactory.getSchema(cov .getCoordinateReferenceSystem()); monitor.setTask(new SimpleInternationalString("Creating polygon features")); SimpleFeatureCollection features = assembleFeatures(cov, band, insideEdges, schema, new SubProgressListener(monitor, 20)); return features; } catch (Exception ex) { throw new ProcessException(ex); } finally { monitor.complete(); } } }
RasterToVectorProcess extends AbstractProcess { private SimpleFeatureCollection convert( GridCoverage2D cov, int band, Envelope bounds, Collection<Double> outsideValues, boolean insideEdges, ProgressListener monitor) throws ProcessException { if (monitor == null) { monitor = new NullProgressListener(); } else { monitor.started(); } ReferencedEnvelope workingBounds = null; if (bounds == null) { workingBounds = new ReferencedEnvelope(cov.getEnvelope()); } else { CoordinateReferenceSystem sourceCRS = bounds.getCoordinateReferenceSystem(); CoordinateReferenceSystem targetCRS = cov.getCoordinateReferenceSystem(); if (sourceCRS != null) { if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { throw new ProcessException("CRS of bounds must match that of the coverage"); } } ReferencedEnvelope inputBounds = new ReferencedEnvelope(bounds); ReferencedEnvelope covBounds = new ReferencedEnvelope(cov.getEnvelope()); workingBounds = new ReferencedEnvelope(covBounds.intersection(inputBounds), targetCRS); if (workingBounds == null || workingBounds.isEmpty()) { throw new ProcessException("Specified bounds lie wholly outside of coverage"); } } try { monitor.setTask(new SimpleInternationalString("Initializing")); initialize(cov, workingBounds, new SubProgressListener(monitor, 10)); monitor.setTask(new SimpleInternationalString("Vectorizing")); vectorizeAndCollectBoundaries(band, outsideValues, insideEdges, new SubProgressListener(monitor, 70)); SimpleFeatureType schema = RasterToVectorFactory.getSchema(cov .getCoordinateReferenceSystem()); monitor.setTask(new SimpleInternationalString("Creating polygon features")); SimpleFeatureCollection features = assembleFeatures(cov, band, insideEdges, schema, new SubProgressListener(monitor, 20)); return features; } catch (Exception ex) { throw new ProcessException(ex); } finally { monitor.complete(); } } RasterToVectorProcess(ProcessFactory factory); }
RasterToVectorProcess extends AbstractProcess { private SimpleFeatureCollection convert( GridCoverage2D cov, int band, Envelope bounds, Collection<Double> outsideValues, boolean insideEdges, ProgressListener monitor) throws ProcessException { if (monitor == null) { monitor = new NullProgressListener(); } else { monitor.started(); } ReferencedEnvelope workingBounds = null; if (bounds == null) { workingBounds = new ReferencedEnvelope(cov.getEnvelope()); } else { CoordinateReferenceSystem sourceCRS = bounds.getCoordinateReferenceSystem(); CoordinateReferenceSystem targetCRS = cov.getCoordinateReferenceSystem(); if (sourceCRS != null) { if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { throw new ProcessException("CRS of bounds must match that of the coverage"); } } ReferencedEnvelope inputBounds = new ReferencedEnvelope(bounds); ReferencedEnvelope covBounds = new ReferencedEnvelope(cov.getEnvelope()); workingBounds = new ReferencedEnvelope(covBounds.intersection(inputBounds), targetCRS); if (workingBounds == null || workingBounds.isEmpty()) { throw new ProcessException("Specified bounds lie wholly outside of coverage"); } } try { monitor.setTask(new SimpleInternationalString("Initializing")); initialize(cov, workingBounds, new SubProgressListener(monitor, 10)); monitor.setTask(new SimpleInternationalString("Vectorizing")); vectorizeAndCollectBoundaries(band, outsideValues, insideEdges, new SubProgressListener(monitor, 70)); SimpleFeatureType schema = RasterToVectorFactory.getSchema(cov .getCoordinateReferenceSystem()); monitor.setTask(new SimpleInternationalString("Creating polygon features")); SimpleFeatureCollection features = assembleFeatures(cov, band, insideEdges, schema, new SubProgressListener(monitor, 20)); return features; } catch (Exception ex) { throw new ProcessException(ex); } finally { monitor.complete(); } } RasterToVectorProcess(ProcessFactory factory); Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor); static SimpleFeatureCollection process(
            GridCoverage2D cov,
            int band,
            Envelope bounds,
            Collection<Double> outsideValues,
            boolean insideEdges,
            ProgressListener monitor); }
RasterToVectorProcess extends AbstractProcess { private SimpleFeatureCollection convert( GridCoverage2D cov, int band, Envelope bounds, Collection<Double> outsideValues, boolean insideEdges, ProgressListener monitor) throws ProcessException { if (monitor == null) { monitor = new NullProgressListener(); } else { monitor.started(); } ReferencedEnvelope workingBounds = null; if (bounds == null) { workingBounds = new ReferencedEnvelope(cov.getEnvelope()); } else { CoordinateReferenceSystem sourceCRS = bounds.getCoordinateReferenceSystem(); CoordinateReferenceSystem targetCRS = cov.getCoordinateReferenceSystem(); if (sourceCRS != null) { if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { throw new ProcessException("CRS of bounds must match that of the coverage"); } } ReferencedEnvelope inputBounds = new ReferencedEnvelope(bounds); ReferencedEnvelope covBounds = new ReferencedEnvelope(cov.getEnvelope()); workingBounds = new ReferencedEnvelope(covBounds.intersection(inputBounds), targetCRS); if (workingBounds == null || workingBounds.isEmpty()) { throw new ProcessException("Specified bounds lie wholly outside of coverage"); } } try { monitor.setTask(new SimpleInternationalString("Initializing")); initialize(cov, workingBounds, new SubProgressListener(monitor, 10)); monitor.setTask(new SimpleInternationalString("Vectorizing")); vectorizeAndCollectBoundaries(band, outsideValues, insideEdges, new SubProgressListener(monitor, 70)); SimpleFeatureType schema = RasterToVectorFactory.getSchema(cov .getCoordinateReferenceSystem()); monitor.setTask(new SimpleInternationalString("Creating polygon features")); SimpleFeatureCollection features = assembleFeatures(cov, band, insideEdges, schema, new SubProgressListener(monitor, 20)); return features; } catch (Exception ex) { throw new ProcessException(ex); } finally { monitor.complete(); } } RasterToVectorProcess(ProcessFactory factory); Map<String, Object> execute(Map<String, Object> input, ProgressListener monitor); static SimpleFeatureCollection process(
            GridCoverage2D cov,
            int band,
            Envelope bounds,
            Collection<Double> outsideValues,
            boolean insideEdges,
            ProgressListener monitor);  }