/** * Sets the internal data array. The actual type of the given data object should only be one of <ol> * <li><code>byte[]</code> - for signed/unsigned 8-bit integer fields</li> <li><code>short[]</code> - for * signed/unsigned 16-bit integer fields</li> <li><code>int[]</code> - for signed/unsigned 32-bit integer * fields</li> <li><code>float[]</code> - for signed 32-bit floating point fields</li> <li><code>double[]</code> - * for signed 64-bit floating point fields</li> </ol> * * @param data an array of one of the described types */ public void setValue(Object data) { getData().setElems(data); }
/** * Adds an attribute from src to dest * * @param tag the name of the attribute * @param value the string value * @param dest the destination element * @param desc the description */ private static void addAbstractedAttribute(String tag, String value, MetadataElement dest, String desc) { if (value == null || value.isEmpty()) value = " "; final MetadataAttribute attribute = new MetadataAttribute(tag, ProductData.TYPE_ASCII, 1); attribute.getData().setElems(value); attribute.setDescription(desc); dest.addAttribute(attribute); }
/** * Sets the attribute with the given name to the given string value. <p>A new attribute with * <code>ProductData.TYPE_ASCII</code> is added to this node if an attribute with the given name could not be found * in this node. * * @param name the attribute name * @param value the new value */ public void setAttributeString(String name, String value) { final MetadataAttribute attribute = getAndMaybeCreateAttribute(name, ProductData.TYPE_ASCII, 1); attribute.getData().setElems(value); attribute.fireProductNodeDataChanged(); setModified(true); }
private ProductData getFilledSourceData(int size) { ProductData data = getSourceData(size); byte[] bytes = new byte[data.getNumElems()]; for (int i = 0; i < bytes.length; i++) { bytes[i] = 85; } data.setElems(bytes); return data; }
private static ProductData createProductDataPartAsUINT32(final Band band, final Rectangle region) { int[] intData = null; intData = band.getPixels((int) region.getX(), (int) region.getY(), (int) region.getWidth(), (int) region.getHeight(), intData, ProgressMonitor.NULL); final ProductData data = ProductData.createInstance(ProductData.TYPE_UINT32, intData.length); data.setElems(intData); return data; }
/** * Sets the attribute with the given name to the given utc value. <p>A new attribute with * <code>ProductData.UTC</code> is added to this node if an attribute with the given name could not be found * in this node. * * @param name the attribute name * @param value the new value */ public void setAttributeUTC(String name, ProductData.UTC value) { final MetadataAttribute attribute = getAndMaybeCreateAttribute(name, ProductData.TYPE_UTC, 1); attribute.getData().setElems(value.getArray()); attribute.fireProductNodeDataChanged(); setModified(true); }
public void testSetElemsAsString_OutOfRange() { final ProductData pd1 = ProductData.createInstance(ProductData.TYPE_UINT16, 1); try { pd1.setElems(new String[]{String.valueOf(Short.MAX_VALUE * 2 + 2)}); } catch (Exception e) { assertEquals(NumberFormatException.class, e.getClass()); assertEquals("Value out of range. The value:'65536' is not an unsigned short value.", e.getMessage()); } final ProductData pd2 = ProductData.createInstance(ProductData.TYPE_UINT16, 1); try { pd2.setElems(new String[]{String.valueOf(-1)}); } catch (Exception e) { assertEquals(NumberFormatException.class, e.getClass()); assertEquals("Value out of range. The value:'-1' is not an unsigned short value.", e.getMessage()); } } }
public void testSetElemsAsString_OutOfRange() { final ProductData pd1 = ProductData.createInstance(ProductData.TYPE_INT16, 1); try { pd1.setElems(new String[]{String.valueOf(Short.MAX_VALUE + 1)}); } catch (Exception e) { assertEquals(NumberFormatException.class, e.getClass()); assertEquals("Value out of range. Value:\"32768\" Radix:10", e.getMessage()); } final ProductData pd2 = ProductData.createInstance(ProductData.TYPE_INT16, 1); try { pd2.setElems(new String[]{String.valueOf(Short.MIN_VALUE - 1)}); } catch (Exception e) { assertEquals(NumberFormatException.class, e.getClass()); assertEquals("Value out of range. Value:\"-32769\" Radix:10", e.getMessage()); } } }
public void testSetElemsAsString_OutOfRange() { final ProductData pd1 = ProductData.createInstance(ProductData.TYPE_INT8, 1); try { pd1.setElems(new String[]{String.valueOf(Byte.MAX_VALUE + 1)}); } catch (Exception e) { assertEquals(NumberFormatException.class, e.getClass()); assertEquals("Value out of range. Value:\"128\" Radix:10", e.getMessage()); } final ProductData pd2 = ProductData.createInstance(ProductData.TYPE_INT8, 1); try { pd2.setElems(new String[]{String.valueOf(Byte.MIN_VALUE - 1)}); } catch (Exception e) { assertEquals(NumberFormatException.class, e.getClass()); assertEquals("Value out of range. Value:\"-129\" Radix:10", e.getMessage()); } } }
/** * Adds an attribute from src to dest * * @param tag the name of the attribute * @param value the double value * @param unit the unit string * @param dest the destination element * @param desc the description */ private static void addAbstractedAttribute(String tag, double value, String unit, MetadataElement dest, String desc) { final MetadataAttribute attribute = new MetadataAttribute(tag, ProductData.TYPE_FLOAT64, 1); attribute.getData().setElems(new double[]{value}); attribute.setUnit(unit); attribute.setDescription(desc); dest.addAttribute(attribute); }
/** * Adds an attribute from src to dest * * @param tag the name of the attribute * @param value the UTC value * @param dest the destination element * @param desc the description */ private static void addAbstractedAttribute(String tag, ProductData.UTC value, MetadataElement dest, String desc) { final MetadataAttribute attribute = new MetadataAttribute(tag, ProductData.TYPE_UTC, 1); attribute.getData().setElems(value.getArray()); attribute.setUnit("utc"); attribute.setDescription(desc); dest.addAttribute(attribute); }
public void testSetElemsAsString() { final ProductData pd = ProductData.createInstance(ProductData.TYPE_INT16, 3); pd.setElems(new String[]{ String.valueOf(Short.MAX_VALUE), String.valueOf(0), String.valueOf(Short.MIN_VALUE), }); assertEquals(Short.MAX_VALUE, pd.getElemIntAt(0)); assertEquals(0, pd.getElemIntAt(1)); assertEquals(Short.MIN_VALUE, pd.getElemIntAt(2)); }
public void testSetElemsAsString() { final ProductData pd = ProductData.createInstance(ProductData.TYPE_INT32, 3); pd.setElems(new String[]{ String.valueOf(Integer.MAX_VALUE), String.valueOf(Integer.MIN_VALUE), String.valueOf(0), }); assertEquals(Integer.MAX_VALUE, pd.getElemIntAt(0)); assertEquals(Integer.MIN_VALUE, pd.getElemIntAt(1)); assertEquals(0, pd.getElemIntAt(2)); }
public void testSetElemsAsString() { final ProductData pd = ProductData.createInstance(ProductData.TYPE_INT8, 3); pd.setElems(new String[]{ String.valueOf(Byte.MAX_VALUE), String.valueOf(Byte.MIN_VALUE), String.valueOf(0), }); assertEquals(Byte.MAX_VALUE, pd.getElemIntAt(0)); assertEquals(Byte.MIN_VALUE, pd.getElemIntAt(1)); assertEquals(0, pd.getElemIntAt(2)); }
public void testSetElemsAsString() { final ProductData pd = ProductData.createInstance(ProductData.TYPE_UINT8, 3); pd.setElems(new String[]{ String.valueOf(Byte.MAX_VALUE * 2 + 1), String.valueOf(Byte.MAX_VALUE), String.valueOf(0), }); assertEquals(Byte.MAX_VALUE * 2 + 1, pd.getElemIntAt(0)); assertEquals(Byte.MAX_VALUE, pd.getElemIntAt(1)); assertEquals(0, pd.getElemIntAt(2)); }
public void testSetElemsAsString() { final ProductData pd = ProductData.createInstance(ProductData.TYPE_UINT16, 3); pd.setElems(new String[]{ String.valueOf(Short.MAX_VALUE * 2 + 1), String.valueOf(Short.MAX_VALUE), String.valueOf(0), }); assertEquals(Short.MAX_VALUE * 2 + 1, pd.getElemIntAt(0)); assertEquals(Short.MAX_VALUE, pd.getElemIntAt(1)); assertEquals(0, pd.getElemIntAt(2)); }
public void testSetElemsAsString() { final ProductData pd = ProductData.createInstance(ProductData.TYPE_UINT32, 3); pd.setElems(new String[]{ String.valueOf((long) Integer.MAX_VALUE * 2 + 1), String.valueOf(Integer.MAX_VALUE), String.valueOf(0), }); assertEquals((long) Integer.MAX_VALUE * 2 + 1, pd.getElemUIntAt(0)); assertEquals(-1, pd.getElemIntAt(0)); assertEquals(Integer.MAX_VALUE, pd.getElemUIntAt(1)); assertEquals(Integer.MAX_VALUE, pd.getElemIntAt(1)); assertEquals(0, pd.getElemIntAt(2)); }
@Override public void computeTile(Band band, Tile targetTile, ProgressMonitor pm) throws OperatorException { recordCall(getOpName(this), "Operator.computeBand"); Rectangle r = targetTile.getRectangle(); float offset = r.y * targetProduct.getSceneRasterWidth() + r.x; ProductData rawSampleData = targetTile.getRawSamples(); float[] targetElems = (float[]) rawSampleData.getElems(); for (int i = 0; i < targetElems.length; i++) { targetElems[i] = offset + i; } rawSampleData.setElems(targetElems); targetTile.setRawSamples(rawSampleData); }
@Override public synchronized void setRawSamples(ProductData rawSamples) { if (target) { if (rawSamples != this.dataBuffer) { Assert.notNull(rawSamples, "rawSamples"); Assert.argument(rawSamples.getType() == dataBuffer.getType(), "rawSamples.getType() == dataBuffer.getType()"); Assert.argument(rawSamples.getNumElems() == dataBuffer.getNumElems(), "rawSamples.getNumElems() == dataBuffer.getNumElems()"); dataBuffer.setElems(rawSamples.getElems()); } } }
@Override public void computeTile(Band band, Tile targetTile, ProgressMonitor pm) throws OperatorException { recordCall(getOpName(this), "Operator.computeBand"); Tile sourceTile = getSourceTile(sourceProduct.getBandAt(0), targetTile.getRectangle()); float[] sourceElems = (float[]) sourceTile.getRawSamples().getElems(); ProductData rawSampleData = targetTile.getRawSamples(); float[] targetElems = (float[]) rawSampleData.getElems(); for (int i = 0; i < targetElems.length; i++) { targetElems[i] = 0.1f * sourceElems[i]; } rawSampleData.setElems(targetElems); targetTile.setRawSamples(rawSampleData); } }