private static MetadataElement findElementContaining(final MetadataElement parent, final String elemName, final String attribName, final String attValue) { final MetadataElement[] elems = parent.getElements(); for (MetadataElement elem : elems) { if (elem.getName().equalsIgnoreCase(elemName) && elem.containsAttribute(attribName)) { String value = elem.getAttributeString(attribName); if (value != null && value.equalsIgnoreCase(attValue)) return elem; } } return null; }
private static MetadataElement findElementContaining(final MetadataElement parent, final String elemName, final String attribName, final String attValue) { final MetadataElement[] elems = parent.getElements(); for (MetadataElement elem : elems) { if (elem.getName().equalsIgnoreCase(elemName) && elem.containsAttribute(attribName)) { String value = elem.getAttributeString(attribName); if (value != null && value.equalsIgnoreCase(attValue)) return elem; } } return null; }
public int getNoDataValue() { int noData = -1; if (rootElement != null) { MetadataElement currentElement; if ((currentElement = rootElement.getElement(SpotConstants.TAG_IMAGE_DISPLAY)) != null) { MetadataElement[] specialValues = currentElement.getElements(); for (MetadataElement specialValue : specialValues) { if (specialValue.containsAttribute(SpotConstants.TAG_SPECIAL_VALUE_TEXT) && SpotConstants.NODATA_VALUE.equals(specialValue.getAttributeString(SpotConstants.TAG_SPECIAL_VALUE_TEXT))) { noData = Integer.parseInt(specialValue.getAttributeString(SpotConstants.TAG_SPECIAL_VALUE_INDEX)); } } } else { logger.warning(String.format(MISSING_ELEMENT_WARNING, SpotConstants.NODATA_VALUE)); } } return noData; }
public int getSaturatedPixelValue() { int saturatedValue = -1; if (rootElement != null) { MetadataElement currentElement; if ((currentElement = rootElement.getElement(SpotConstants.TAG_IMAGE_DISPLAY)) != null) { MetadataElement[] specialValues = currentElement.getElements(); for (MetadataElement specialValue : specialValues) { if (specialValue.containsAttribute(SpotConstants.TAG_SPECIAL_VALUE_TEXT) && SpotConstants.SATURATED_VALUE.equals(specialValue.getAttributeString(SpotConstants.TAG_SPECIAL_VALUE_TEXT))) { saturatedValue = Integer.parseInt(specialValue.getAttributeString(SpotConstants.TAG_SPECIAL_VALUE_INDEX)); } } } else { logger.warning(String.format(MISSING_ELEMENT_WARNING, SpotConstants.SATURATED_VALUE)); } } return saturatedValue; }
private static void initParameter(MetadataElement parentElement, Field field, Map<String, Object> parameters) throws OperatorException { Parameter annotation = field.getAnnotation(Parameter.class); String name = annotation.alias(); if (name.isEmpty()) { name = field.getName(); } try { if (parentElement.containsAttribute(name)) { final Converter converter = getConverter(field.getType(), annotation); final String parameterText = parentElement.getAttributeString(name); final Object value = converter.parse(parameterText); parameters.put(name, value); } else { final MetadataElement element = parentElement.getElement(name); if (element != null) { final Object obj = field.getType().newInstance(); final HashMap<String, Object> objParams = new HashMap<>(); collectParameters(obj.getClass(), element, objParams); initObject(objParams, obj); parameters.put(name, obj); } } } catch (Exception e) { throw new OperatorException(String.format("Cannot initialise operator parameter '%s'", name), e); } }
public Color getNoDataColor() { Color color = null; if (rootElement != null) { MetadataElement currentElement; if ((currentElement = rootElement.getElement(SpotConstants.TAG_IMAGE_DISPLAY)) != null) { MetadataElement[] specialValues = currentElement.getElements(); for (MetadataElement specialValue : specialValues) { if (specialValue.containsAttribute(SpotConstants.TAG_SPECIAL_VALUE_TEXT) && SpotConstants.NODATA_VALUE.equals(specialValue.getAttributeString(SpotConstants.TAG_SPECIAL_VALUE_TEXT))) { if ((currentElement = specialValue.getElement(SpotConstants.TAG_SPECIAL_VALUE_COLOR)) != null) { int red = (int) (255.0 * Double.parseDouble(currentElement.getAttributeString(SpotConstants.TAG_RED_LEVEL))); int green = (int) (255.0 * Double.parseDouble(currentElement.getAttributeString(SpotConstants.TAG_GREEN_LEVEL))); int blue = (int) (255.0 * Double.parseDouble(currentElement.getAttributeString(SpotConstants.TAG_BLUE_LEVEL))); color = new Color(red, green, blue); } } } } else { logger.warning(String.format(MISSING_ELEMENT_WARNING, SpotConstants.NODATA_VALUE)); } } return color; }
public Color getSaturatedColor() { Color color = null; if (rootElement != null) { MetadataElement currentElement; if ((currentElement = rootElement.getElement(SpotConstants.TAG_IMAGE_DISPLAY)) != null) { MetadataElement[] specialValues = currentElement.getElements(); for (MetadataElement specialValue : specialValues) { if (specialValue.containsAttribute(SpotConstants.TAG_SPECIAL_VALUE_TEXT) && SpotConstants.SATURATED_VALUE.equals(specialValue.getAttributeString(SpotConstants.TAG_SPECIAL_VALUE_TEXT))) { if ((currentElement = specialValue.getElement(SpotConstants.TAG_SPECIAL_VALUE_COLOR)) != null) { int red = (int) (255.0 * Double.parseDouble(currentElement.getAttributeString(SpotConstants.TAG_RED_LEVEL))); int green = (int) (255.0 * Double.parseDouble(currentElement.getAttributeString(SpotConstants.TAG_GREEN_LEVEL))); int blue = (int) (255.0 * Double.parseDouble(currentElement.getAttributeString(SpotConstants.TAG_BLUE_LEVEL))); color = new Color(red, green, blue); } } } } else { logger.warning(String.format(MISSING_ELEMENT_WARNING, SpotConstants.SATURATED_VALUE)); } } return color; }
final String swath = noiseVectorElem.containsAttribute("swath") ? noiseVectorElem.getAttributeString("swath") : null; final int firstAzimuthLine = noiseVectorElem.containsAttribute("firstAzimuthLine") ? Integer.parseInt(noiseVectorElem.getAttributeString("firstAzimuthLine")) : -1; final int firstRangeSample = noiseVectorElem.containsAttribute("firstRangeSample") ? Integer.parseInt(noiseVectorElem.getAttributeString("firstRangeSample")) : -1; final int lastAzimuthLine = noiseVectorElem.containsAttribute("lastAzimuthLine") ? Integer.parseInt(noiseVectorElem.getAttributeString("lastAzimuthLine")) : -1; final int lastRangeSample = noiseVectorElem.containsAttribute("lastRangeSample") ? Integer.parseInt(noiseVectorElem.getAttributeString("lastRangeSample")) : -1;
/** * Helper method that copies the child nodes of a metadata element as child nodes * of another metadata element. * * @param source The metadata element holding the nodes to be copied * @param target The destination metadata element */ public static void CopyChildElements(MetadataElement source, MetadataElement target) { Assert.notNull(source); Assert.notNull(target); MetadataAttribute[] attributes = source.getAttributes(); if (attributes != null) { for (MetadataAttribute attribute : attributes) { if (!target.containsAttribute(attribute.getName()) && !attribute.getName().contains(":")) { target.addAttribute(attribute); } } } while (source.getNumElements() > 0) { MetadataElement currentElement = source.getElementAt(0); target.addElement(currentElement); source.removeElement(currentElement); } }