@Override public SpatialMetadata getCoverageMetadata(int i) throws CoverageStoreException { SpatialMetadata meta = new SpatialMetadata( SpatialMetadataFormat.getImageInstance(SpatialMetadataFormat.GEOTK_FORMAT_NAME)); GridDomainAccessor grid = new GridDomainAccessor(meta); grid.setGridGeometry(coverage.getGridGeometry(), pixPos, CellGeometry.POINT, -1); ReferencingBuilder ref = new ReferencingBuilder(meta); ref.setCoordinateReferenceSystem(coverage.getCoordinateReferenceSystem()); return meta; }
@Override public void glyph( final Graphics2D g, final Rectangle2D rect, final CachedDimRangeSymbolizer symbol, final MapLayer layer) { int[] ARGB = new int[] {Color.RED.getRGB(), Color.GREEN.getRGB(), Color.BLUE.getRGB()}; if (layer instanceof CoverageMapLayer) { final CoverageMapLayer cml = (CoverageMapLayer) layer; final CoverageReference ref = cml.getCoverageReference(); try { final GridCoverageReader reader = ref.acquireReader(); final GridCoverageReadParam param = new GridCoverageReadParam(); param.setResolution(1, 1); GridCoverage2D cov = (GridCoverage2D) reader.read(0, param); ref.recycle(reader); cov = cov.view(ViewType.NATIVE); RenderedImage img = cov.getRenderedImage(); ColorModel cm = img.getColorModel(); if (cm instanceof IndexColorModel) { final IndexColorModel icm = (IndexColorModel) cm; final GridSampleDimension sampleDim = cov.getSampleDimension(0); int size = icm.getMapSize(); ARGB = new int[size]; icm.getRGBs(ARGB); final double minVal = sampleDim.getMinimumValue(); final double maxVal = sampleDim.getMaximumValue(); final ColorMap colorMap = new ColorMap(); colorMap.setGeophysicsRange( ColorMap.ANY_QUANTITATIVE_CATEGORY, new MeasurementRange( NumberRange.create(minVal, true, maxVal, true), sampleDim.getUnits())); GridSampleDimension ret = colorMap.recolor(sampleDim, ARGB); } } catch (CoverageStoreException | CancellationException ex) { Logging.getLogger("org.geotoolkit.display2d.ext.dimrange").log(Level.WARNING, null, ex); } } final float[] space = new float[ARGB.length]; final Color[] colors = new Color[ARGB.length]; for (int i = 0; i < space.length; i++) { space[i] = (float) i / (space.length - 1); colors[i] = new Color(ARGB[i]); } final LinearGradientPaint paint = new LinearGradientPaint( (float) rect.getMinX(), (float) rect.getMinY(), (float) rect.getMaxX(), (float) rect.getMinY(), space, colors); g.setPaint(paint); g.fill(rect); }
@Override public List<GridSampleDimension> getSampleDimensions(final int i) throws CoverageStoreException, CancellationException { return Collections.singletonList(coverage.getSampleDimension(i)); }
@Override public GeneralGridGeometry getGridGeometry(final int i) throws CoverageStoreException, CancellationException { return (GeneralGridGeometry) coverage.getGridGeometry(); }