/** * 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); }
public MetadataAttribute createDeepClone() { MetadataAttribute clone = new MetadataAttribute(getName(), getData().createDeepClone(), isReadOnly()); clone.setDescription(getDescription()); clone.setSynthetic(isSynthetic()); clone.setUnit(getUnit()); return clone; } }
xmlAttribs.add(new String[]{DimapProductConstants.ATTRIB_NAME, attribute.getName()}); final String description = attribute.getDescription(); if (description != null) { xmlAttribs.add(new String[]{DimapProductConstants.ATTRIB_DESCRIPTION, description}); final String unit = attribute.getUnit(); if (unit != null) { xmlAttribs.add(new String[]{DimapProductConstants.ATTRIB_UNIT, unit}); final String dataTypeString = attribute.getData().getTypeString(); xmlAttribs.add(new String[]{DimapProductConstants.ATTRIB_TYPE, dataTypeString}); if (!attribute.isReadOnly()) { xmlAttribs.add(new String[]{DimapProductConstants.ATTRIB_MODE, "rw"}); if (attribute.getNumDataElems() > 1 && !ProductData.TYPESTRING_ASCII.equals(dataTypeString) && !ProductData.TYPESTRING_UTC.equals(dataTypeString)) { xmlAttribs.add( new String[]{DimapProductConstants.ATTRIB_ELEMS, String.valueOf(attribute.getNumDataElems())}); final String text = attribute.getData().getElemString(); final String[][] attribs = xmlAttribs.toArray(new String[][]{}); printLine(indent, DimapProductConstants.TAG_METADATA_ATTRIBUTE, attribs, text);
private static void extendAttribute(MetadataAttribute attribute, String unit, String description) { if (unit != null) { attribute.setUnit(unit); } if (description != null) { attribute.setDescription(description); } } }
/** * Parses a float attribute from the stream */ private MetadataAttribute parseFloatAttribute(int size, String name, String description, String unit) throws IOException { float fData = 0.f; MetadataAttribute attribute = null; ProductData data = null; fData = parseFloat(size); data = ProductData.createInstance(new float[]{fData}); attribute = new MetadataAttribute(name, data, true); if (description != null) { attribute.setDescription(description); } if (unit != null) { attribute.setUnit(unit); } return attribute; }
/** * stores a UTC Date in a metadata attribute * * @param name * @param date * * @return metadata attribute */ protected static MetadataAttribute createAttribute(final String name, final ProductData.UTC date) { return new MetadataAttribute(name, date, true); }
private static FlagCoding createCloudFlagCoding(Product outputProduct) { MetadataAttribute cloudAttr; final FlagCoding flagCoding = new FlagCoding(CLOUD_FLAG_BAND); flagCoding.setDescription("Cloud Flag Coding"); cloudAttr = new MetadataAttribute("cloudy", ProductData.TYPE_UINT8); cloudAttr.getData().setElemInt(FLAG_CLOUDY); cloudAttr.setDescription("is with more than 80% cloudy"); flagCoding.addAttribute(cloudAttr); outputProduct.addMask(cloudAttr.getName(), flagCoding.getName() + "." + cloudAttr.getName(), cloudAttr.getDescription(), createBitmaskColor(1, 3), 0.5); cloudAttr = new MetadataAttribute("cloudfree", ProductData.TYPE_UINT8); cloudAttr.getData().setElemInt(FLAG_CLOUDFREE); cloudAttr.setDescription("is with less than 20% cloudy"); flagCoding.addAttribute(cloudAttr); outputProduct.addMask(cloudAttr.getName(), flagCoding.getName() + "." + cloudAttr.getName(), cloudAttr.getDescription(), createBitmaskColor(2, 3), 0.5); cloudAttr = new MetadataAttribute("cloud_uncertain", ProductData.TYPE_UINT8); cloudAttr.getData().setElemInt(FLAG_UNCERTAIN); cloudAttr.setDescription("is with between 20% and 80% cloudy"); flagCoding.addAttribute(cloudAttr); outputProduct.addMask(cloudAttr.getName(), flagCoding.getName() + "." + cloudAttr.getName(), cloudAttr.getDescription(), createBitmaskColor(3, 3), 0.5); return flagCoding; }
public Object getValueAt(int column) { if (column == NAME_COL_INDEX) { if (index == -1) { return attribute.getName(); } else { return attribute.getName() + "." + index; } } else if (column == VALUE_COL_INDEX) { if (index == -1) { return attribute.getData().getElemString(); } else { return attribute.getData().getElemStringAt(index); } } else if (column == TYPE_COL_INDEX) { return attribute.getData().getTypeString(); } else if (column == UNIT_COL_INDEX) { return attribute.getUnit() != null ? attribute.getUnit() : ""; } else if (column == DESCR_COL_INDEX) { return attribute.getDescription() != null ? attribute.getDescription() : ""; } return ""; } }
ExpectedSampleCoding(SampleCoding sampleCoding) { this(); this.name = sampleCoding.getName(); samples = new ExpectedSample[sampleCoding.getNumAttributes()]; for (int i = 0; i < samples.length; i++) { final MetadataAttribute sampleAttribute = sampleCoding.getAttributeAt(i); samples[i] = new ExpectedSample(sampleAttribute.getName(), sampleAttribute.getData().getElemUInt(), sampleAttribute.getDescription()); } }
/** * 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); }
private static void registerSingleFlagSymbols(WritableNamespace namespace, Product product, String namePrefix) { for (int i = 0; i < product.getNumBands(); i++) { final Band band = product.getBandAt(i); if (band.getFlagCoding() != null) { for (int j = 0; j < band.getFlagCoding().getNumAttributes(); j++) { final MetadataAttribute attribute = band.getFlagCoding().getAttributeAt(j); final int flagMask = attribute.getData().getElemInt(); final String symbolName = namePrefix + band.getName() + "." + attribute.getName(); final Symbol symbol = new SingleFlagSymbol(symbolName, band, flagMask); namespace.registerSymbol(symbol); } } } }
String s = "at index [" + i + "]"; assertNotNull(s, attribute); assertEquals(s, expectedNames[i], attribute.getName()); assertEquals(s, 1, attribute.getNumDataElems()); assertEquals(s, expectedValues[i], attribute.getData().getElemInt());
private void addFlag(FlagCoding flagCoding, int index) { MetadataAttribute attribute; attribute = new MetadataAttribute(String.format("%d_FLAG", index + 1), ProductData.TYPE_UINT8); final int maskValue = 1 << index; attribute.getData().setElemInt(maskValue); flagCoding.addAttribute(attribute); } }
/** * Adds a new coding value to this sample coding. * * @param name the coding name * @param value the value * @param description the description text * @throws IllegalArgumentException if <code>name</code> is null * @return A new attribute representing the coded sample. */ public MetadataAttribute addSample(String name, int value, String description) { Guardian.assertNotNull("name", name); MetadataAttribute attribute = new MetadataAttribute(name, ProductData.TYPE_INT32); attribute.setDataElems(new int[]{value}); if (description != null) { attribute.setDescription(description); } addAttribute(attribute); return 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); }
/** * @param attributeName the name of the attribute * @param attributeDescription the descrption of the atttribute * * @return the <code>int</code> value of the attribute * * @throws IOException */ private int parseAndAddAttributeToSPH(String attributeName, String attributeDescription) throws IOException { int nData = parseInt(RECORD_CONTENTS_SIZE); ProductData data = ProductData.createInstance(new int[]{nData}); MetadataAttribute attribute = new MetadataAttribute(attributeName, data, true); attribute.setDescription(attributeDescription); _sph.addAttribute(attribute); return nData; }
private void writeAttributes(PrintWriter out, MetadataElement element) { final MetadataAttribute[] attributes = element.getAttributes(); for (MetadataAttribute attribute : attributes) { out.print(createAttributeName(attribute) + "\t"); out.print(attribute.getData().getElemString() + "\t"); out.print(attribute.getUnit() + "\t"); out.print(attribute.getDescription() + "\t\n"); } final MetadataElement[] subElements = element.getElements(); for (MetadataElement subElement : subElements) { writeAttributes(out, subElement); } }
ExpectedMetadata(MetadataAttribute attribute) { final MetadataElement metadataRoot = attribute.getProduct().getMetadataRoot(); MetadataElement currentElement = attribute.getParentElement(); final MetadataAttribute[] attributes = currentElement.getAttributes(); int index = 0; for (MetadataAttribute attrib : attributes) { if(attrib.getName().equals(attribute.getName())) { index++; if(attrib == attribute) { sb.append(escapeSlashes(attribute.getName())); if(index > 1) { sb.append("[").append(index).append("]"); this.value = attribute.getData().getElemString();
public static void assertIntAttribute(MetadataElement elem, String attributeName, int expectedValue) { final MetadataAttribute attribute = elem.getAttribute(attributeName); assertNotNull(attribute); assertEquals(ProductData.TYPE_INT32, attribute.getDataType()); assertEquals(1, attribute.getNumDataElems()); assertEquals(expectedValue, attribute.getData().getElemInt()); }