/** Creates a {@link GridCoverage2D} for the provided {@link RenderedImage}. */ private GridCoverage2D createCoverage(String name, RenderedImage image) { Category noDataCategory = new Category( Vocabulary.formatInternational(VocabularyKeys.NODATA), new Color[] {new Color(0, 0, 0, 0)}, NumberRange.create(DEFAULT_NODATA, DEFAULT_NODATA)); Category[] categories = new Category[] {noDataCategory}; GridSampleDimension[] bands; bands = new GridSampleDimension[1]; bands[0] = new GridSampleDimension(null, categories, null); final Map<String, Object> properties = new HashMap<String, Object>(); CoverageUtilities.setNoDataProperty(properties, DEFAULT_NODATA); return this.coverageFactory.create( name, image, this.originalEnvelope, bands, null, properties); }
"original", new Category[] { new Category( Vocabulary.formatInternational(VocabularyKeys.NODATA), new Color[] {new Color(0, 0, 0, 0)},
/** * Returns a category for the same range of sample values but a different color palette. The * array given in argument may have any length; colors will be interpolated as needed. An array * of length 1 means that an uniform color should be used for all sample values. An array of * length 0 or a {@code null} array means that some default colors should be used (usually a * gradient from opaque black to opaque white). * * @param colors A set of colors for the new category. * @return A category with the new color palette, or {@code this} if the new colors are * identical to the current ones. * @see org.geotools.coverage.processing.ColorMap#recolor */ public Category recolor(final Color[] colors) { final int[] newARGB = toARGB(colors); if (Arrays.equals(ARGB, newARGB)) { return this; } assert range != null : this; final Category newCategory = new Category(name, newARGB, range, isQuantitative); return newCategory; }
/** Constructs a list of categories. Used by constructors only. */ private static CategoryList list(final CharSequence[] names, final Color[] colors) { if (names.length != colors.length) { throw new IllegalArgumentException(Errors.format(ErrorKeys.MISMATCHED_ARRAY_LENGTH)); } final int length = names.length; final Category[] categories = new Category[length]; for (int i = 0; i < length; i++) { categories[i] = new Category(names[i], colors[i], i); } return list(categories, null); }
public SimplifiedGridSampleDimension( CharSequence description, SampleDimensionType type, ColorInterpretation color, double nodata, double minimum, double maximum, double scale, double offset, Unit<?> unit) { super( description, !Double.isNaN(nodata) ? new Category[] { new Category( Vocabulary.formatInternational(VocabularyKeys.NODATA), new Color[] {new Color(0, 0, 0, 0)}, NumberRange.create(nodata, nodata)) } : null, unit); this.nodata = nodata; this.minimum = minimum; this.maximum = maximum; this.scale = scale; this.offset = offset; this.unit = unit; this.type = type; this.color = color; }
/** * Returns a sample dimension for the current {@linkplain GridCoverageBuilder#getSampleRange * range of sample values}. */ public GridSampleDimension getSampleDimension() { if (sampleDimension == null) { NumberRange<? extends Number> range = getSampleRange(); int lower = (int) Math.floor(range.getMinimum(true)); int upper = (int) Math.ceil(range.getMaximum(false)); final Category[] categories = new Category[nodata.size() + 1]; int i = 0; for (final Map.Entry<Integer, CharSequence> entry : nodata.entrySet()) { final int sample = entry.getKey(); if (sample >= lower && sample < upper) { if (sample - lower <= upper - sample) { lower = sample + 1; } else { upper = sample; } } categories[i++] = new Category(entry.getValue(), null, sample); } range = NumberRange.create(lower, true, upper, false); categories[i] = new Category(name, null, range, true); sampleDimension = new GridSampleDimension(name, categories, units); } return sampleDimension; }
/** * Returns the quantitative category for a single {@linkplain GridSampleDimension sample * dimension} in the target {@linkplain GridCoverage2D grid coverage}. This method is invoked * automatically by the {@link #deriveSampleDimension deriveSampleDimension} method for each * band in the target image. The default implementation creates a default category from the * target range of values returned by {@link #deriveRange deriveRange}. * * @param categories The quantitative categories from every sources. For unary operations like, * this array has a length of 1. For binary operations like {@code "add"} and {@code * "multiply"}, this array has a length of 2. * @param parameters Parameters, rendering hints and coordinate reference system to use. * @return The quantitative category to use in the destination image, or {@code null} if * unknown. */ protected Category deriveCategory(final Category[] categories, final Parameters parameters) { final NumberRange[] ranges = new NumberRange[categories.length]; for (int i = 0; i < ranges.length; i++) { if (categories[i] == null) { continue; } ranges[i] = categories[i].getRange(); } final NumberRange range = deriveRange(ranges, parameters); if (range != null) { final Category category = categories[PRIMARY_SOURCE_INDEX]; return new Category(category.getName(), category.getColors(), range, true); } return null; }
if (!Double.isNaN(noData)) { noDataCategory = new Category( Vocabulary.formatInternational(VocabularyKeys.NODATA), new Color[] {new Color(0, 0, 0, 0)},
protected GridCoverage2D execute() { return CoverageFactoryFinder.getGridCoverageFactory(null) .create( "name", PlanarImage.wrapRenderedImage( RasterSymbolizerTest.getSynthetic(Double.NaN)), new GeneralEnvelope( new double[] {-90, -180}, new double[] {90, 180}), new GridSampleDimension[] { new GridSampleDimension( "sd", new Category[] { new Category("", Color.BLACK, 0) }, null) }, null, null); } };
protected GridCoverage2D execute() { return CoverageFactoryFinder.getGridCoverageFactory(null) .create( "name", PlanarImage.wrapRenderedImage( RasterSymbolizerTest.getSynthetic(Double.NaN)), new GeneralEnvelope( new double[] {-90, -180}, new double[] {90, 180}), new GridSampleDimension[] { new GridSampleDimension( "sd", new Category[] { new Category("", Color.BLACK, 0) }, null) }, null, null); } };
@org.junit.Test public void colorMap() throws IOException, TransformerException { // get a coverage GridCoverage2D gc = CoverageFactoryFinder.getGridCoverageFactory(null) .create( "name", PlanarImage.wrapRenderedImage(getSynthetic(Double.NaN)), new GeneralEnvelope( new double[] {-90, -180}, new double[] {90, 180}), new GridSampleDimension[] { new GridSampleDimension( "sd", new Category[] {new Category("", Color.BLACK, 0)}, null) }, null, null); testColorMap(gc); }
new GridSampleDimension( "sd", new Category[] {new Category("", Color.BLACK, 0)}, null), new GridSampleDimension(
@Before public void setUp() throws Exception { // get a coverage final GridCoverage2D gc = CoverageFactoryFinder.getGridCoverageFactory(null) .create( "name", PlanarImage.wrapRenderedImage( RasterSymbolizerTest.getSynthetic(Double.NaN)), new GeneralEnvelope( new double[] {-90, -180}, new double[] {90, 180}), new GridSampleDimension[] { new GridSampleDimension( "sd", new Category[] {new Category("", Color.BLACK, 0)}, null) }, null, null); root1 = new RootNode(gc); root2 = new RootNode(gc); root3 = new RootNode(gc, null); }
new GridSampleDimension( "sd", new Category[] {new Category("", Color.BLACK, 0)}, null) },
new GridSampleDimension( "sd", new Category[] {new Category("", Color.BLACK, 0)}, null) },