RasterAsPointCollectionProcess implements RasterProcess { @DescribeResult(name = "result", description = "Point features") public SimpleFeatureCollection execute( @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D gc2d, @DescribeParameter(name = "targetCRS", description = "CRS in which the points will be displayed", min=0) CoordinateReferenceSystem targetCRS, @DescribeParameter(name = "scale", description = "scale",min=0, defaultValue="1.0f") Float scaleFactor, @DescribeParameter(name = "interpolation", description = "interpolation",min=0, defaultValue="InterpolationNearest") Interpolation interpolation, @DescribeParameter(name = "emisphere", description = "Add Emishpere",min=0, defaultValue="False" ) Boolean emisphere) throws ProcessException { if (gc2d ==null) { throw new ProcessException("Invalid input, source grid coverage should be not null"); } GridEnvelope2D gridEnv = gc2d.getGridGeometry().getGridRange2D(); double coverageWidth = gridEnv.getWidth(); double coverageHeight = gridEnv.getHeight(); if (scaleFactor != null && (Math.abs(coverageWidth*(scaleFactor - 1f)) >=1 || Math.abs(coverageHeight*(scaleFactor - 1f)) >= 1) ) { Interpolation interp = interpolation != null ? interpolation : new InterpolationNearest(); double scaleX = scaleFactor; double scaleY = scaleFactor; final RenderedImage imageToBescaled = gc2d.getRenderedImage(); if (imageToBescaled != null) { final SampleModel sampleModel = imageToBescaled.getSampleModel(); final int height = sampleModel.getHeight(); final int width = sampleModel.getWidth(); if (height * scaleFactor < 1) { scaleY = 1d/height; } if (width * scaleFactor < 1) { scaleX = 1d/width; } } gc2d = new AffineProcess().execute(gc2d, scaleX, scaleY, null, null, null, null, null, interp); } try { return new RasterAsPointFeatureCollection(gc2d, emisphere, targetCRS); } catch (IOException e) { throw new ProcessException("Unable to wrap provided grid coverage", e); } }  @DescribeResult(name = "result", description = "Point features") SimpleFeatureCollection execute(
            @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D gc2d,
            @DescribeParameter(name = "targetCRS", description = "CRS in which the points will be displayed", min=0) CoordinateReferenceSystem targetCRS,
            @DescribeParameter(name = "scale", description = "scale",min=0, defaultValue="1.0f") Float scaleFactor,
            @DescribeParameter(name = "interpolation", description = "interpolation",min=0, defaultValue="InterpolationNearest") Interpolation interpolation,
            @DescribeParameter(name = "emisphere", description = "Add Emishpere",min=0, defaultValue="False" ) Boolean emisphere);  }
@Test(expected = ProcessException.class) public void testNullCoverage() { process.execute(null, null, null, null, false); }
@Test public void testCoverageWithoutParam() throws MismatchedDimensionException, TransformException { SimpleFeatureCollection collection = process.execute(coverage, null, null, null, false); Assert.assertEquals(pixelNumber, collection.size()); checkCollectionPoints(collection, false, null, null); }
@Test public void testCoverageWithHemisphere() throws MismatchedDimensionException, TransformException { boolean hemisphere = true; SimpleFeatureCollection collection = process .execute(coverage, null, null, null, hemisphere); Assert.assertEquals(pixelNumber, collection.size()); checkCollectionPoints(collection, hemisphere, null, null); }
@Test public void testCoverageWithScaleFactor() throws MismatchedDimensionException, TransformException { boolean hemisphere = true; float scaleFactor = 2.0f; SimpleFeatureCollection collection = process.execute(coverage, null, scaleFactor, null, hemisphere); Assert.assertEquals((int) (pixelNumber * scaleFactor * scaleFactor), collection.size()); checkCollectionPoints(collection, hemisphere, scaleFactor, null); }
@Test public void testCoverageWithSmallScaleFactor() throws MismatchedDimensionException, TransformException { boolean hemisphere = true; float scaleFactor = 1f/18; SimpleFeatureCollection collection = process.execute(coverage, null, scaleFactor, null, hemisphere); Assert.assertEquals(1, collection.size()); checkCollectionPoints(collection, hemisphere, scaleFactor, null); }
@Test public void testCoverageWithNearestInterp() throws MismatchedDimensionException, TransformException { boolean hemisphere = true; float scaleFactor = 2.0f; Interpolation interp = new InterpolationNearest(); SimpleFeatureCollection collection = process.execute(coverage, null, scaleFactor, interp, hemisphere); Assert.assertEquals((int) (pixelNumber * scaleFactor * scaleFactor), collection.size()); checkCollectionPoints(collection, hemisphere, scaleFactor, null); }
@Test public void testCoverageWithBilinearInterp() throws MismatchedDimensionException, TransformException { boolean hemisphere = true; float scaleFactor = 2.0f; Interpolation interp = new InterpolationBilinear(); SimpleFeatureCollection collection = process.execute(coverage, null, scaleFactor, interp, hemisphere); Assert.assertEquals((int) (pixelNumber * scaleFactor * scaleFactor), collection.size()); checkCollectionPoints(collection, hemisphere, scaleFactor, null); }
@Test public void testCoverageWithBicubicInterp() throws MismatchedDimensionException, TransformException { boolean hemisphere = true; float scaleFactor = 2.0f; Interpolation interp = new InterpolationBicubic(8); SimpleFeatureCollection collection = process.execute(coverage, null, scaleFactor, interp, hemisphere); Assert.assertEquals((int) (pixelNumber * scaleFactor * scaleFactor), collection.size()); checkCollectionPoints(collection, hemisphere, scaleFactor, null); }
@Test public void testCoverageWithTargetCRS() throws MismatchedDimensionException, TransformException, FactoryException { boolean hemisphere = true; float scaleFactor = 2.0f; Interpolation interp = new InterpolationNearest(); String wkt = "PROJCS[\"Lambert_Conformal_Conic\"," + "GEOGCS[\"GCS_unknown\",DATUM[\"D_unknown\"," + "SPHEROID[\"Sphere\",6367470,0]],PRIMEM[\"Greenwich\",0]," + "UNIT[\"Degree\",0.017453292519943295]]," + "PROJECTION[\"Lambert_Conformal_Conic_1SP\"]," + "PARAMETER[\"latitude_of_origin\",38.5]," + "PARAMETER[\"central_meridian\",-97.5]," + "PARAMETER[\"scale_factor\",1]," + "PARAMETER[\"false_easting\",0]," + "PARAMETER[\"false_northing\",0],UNIT[\"m\",1.0]]"; CoordinateReferenceSystem targetCRS = CRS.parseWKT(wkt); SimpleFeatureCollection collection = process.execute(coverage, targetCRS, scaleFactor, interp, hemisphere); Assert.assertEquals((int) (pixelNumber * scaleFactor * scaleFactor), collection.size()); checkCollectionPoints(collection, hemisphere, scaleFactor, targetCRS); }
@Test public void testCoverageDifferentCRS() throws MismatchedDimensionException, TransformException, FactoryException { boolean hemisphere = true; float scaleFactor = 2.0f; Interpolation interp = new InterpolationNearest(); String wkt = "PROJCS[\"Lambert_Conformal_Conic\"," + "GEOGCS[\"GCS_unknown\",DATUM[\"D_unknown\"," + "SPHEROID[\"Sphere\",6367470,0]],PRIMEM[\"Greenwich\",0]," + "UNIT[\"Degree\",0.017453292519943295]]," + "PROJECTION[\"Lambert_Conformal_Conic_1SP\"]," + "PARAMETER[\"latitude_of_origin\",38.5]," + "PARAMETER[\"central_meridian\",-97.5]," + "PARAMETER[\"scale_factor\",1]," + "PARAMETER[\"false_easting\",0]," + "PARAMETER[\"false_northing\",0],UNIT[\"m\",1.0]]"; CoordinateReferenceSystem targetCRS = CRS.parseWKT(wkt); SimpleFeatureCollection collection = process.execute(inputCoverage, targetCRS, scaleFactor, interp, hemisphere); Assert.assertEquals((int) (pixelNumber * scaleFactor * scaleFactor), collection.size()); checkCollectionPoints(collection, hemisphere, scaleFactor, targetCRS); }