/** * Implementation of the public {@link #getValueClass()} method. * * @param parameter the netCDF parameter from which to infer the value class. */ private static Class<?> getValueClass(final Parameter parameter) { if (parameter.isString()) return String.class; if (parameter.getLength() == 1) return Double.class; return double[].class; }
/** * String representation * * @return nice String */ public String toString() { StringBuilder buff = new StringBuilder(); buff.append(getName()); if (isString()) { buff.append(" = "); buff.append(valueS); } else { buff.append(" = "); for (int i = 0; i < getLength(); i++) { if (i != 0) { buff.append(", "); } buff.append(getNumericValue(i)); } } return buff.toString(); }
/** * String representation * * @return nice String */ public String toString() { StringBuilder buff = new StringBuilder(); buff.append(getName()); if (isString()) { buff.append(" = "); buff.append(valueS); } else { buff.append(" = "); for (int i = 0; i < getLength(); i++) { if (i != 0) { buff.append(", "); } buff.append(getNumericValue(i)); } } return buff.toString(); }
/** * String representation * * @return nice String */ public String toString() { StringBuilder buff = new StringBuilder(); buff.append(getName()); if (isString()) { buff.append(" = "); buff.append(valueS); } else { buff.append(" = "); for (int i = 0; i < getLength(); i++) { if (i != 0) { buff.append(", "); } buff.append(getNumericValue(i)); } } return buff.toString(); }
/** * String representation * * @return nice String */ public String toString() { StringBuilder buff = new StringBuilder(); buff.append(getName()); if (isString()) { buff.append(" = "); buff.append(valueS); } else { buff.append(" = "); for (int i = 0; i < getLength(); i++) { if (i != 0) { buff.append(", "); } buff.append(getNumericValue(i)); } } return buff.toString(); }
/** * Returns the {@linkplain Parameter#getStringValue() parameter string value}. * * @return the parameter string value. * @throws InvalidParameterTypeException if the parameter value is not convertible * to the {@link String} type. * * @see Parameter#getStringValue() */ @Override public String stringValue() throws InvalidParameterTypeException { final Parameter parameter = this.parameter; if (!parameter.isString()) { throw invalidType(parameter, String.class); } return parameter.getStringValue(); }
/** * Returns the {@linkplain Parameter#getNumericValues() parameter numeric values} * as an array of floating point values. * * @return the parameter numeric values. * @throws InvalidParameterTypeException if the parameter value is not convertible * to the {@code double[]} type. * * @see Parameter#getNumericValues() */ @Override public double[] doubleValueList() throws InvalidParameterTypeException { final Parameter parameter = this.parameter; if (parameter.isString()) { throw invalidType(parameter, double[].class); } return parameter.getNumericValues(); }
/** * Sets this parameter to the given {@link String}, {@code double[]} or {@link Number}. * If the given value is a number, then this method delegates to {@link #setValue(double)}. * * @throws InvalidParameterValueException if this parameter can not accept the given value. * * @see Parameter#Parameter(String, String) */ @Override public void setValue(final Object value) throws InvalidParameterValueException { if (value instanceof Number) { setValue(((Number) value).doubleValue()); } else if ((value instanceof double[]) && !parameter.isString()) { parameter = new Parameter(parameter.getName(), (double[]) value); } else if ((value instanceof CharSequence) && parameter.isString()) { parameter = new Parameter(parameter.getName(), value.toString()); } else { throw invalidValue(parameter, value); } }
/** * Returns the {@linkplain Parameter#getNumericValue() parameter numeric value} * as a floating point value. This method first ensures that the parameter value * {@linkplain Parameter#isString() is not a string} and that the * {@linkplain Parameter#getLength() number of numeric values} is equals to 1, * then delegates to the {@link Parameter#getNumericValue()} method. * * @return the parameter numeric value. * @throws InvalidParameterTypeException if the parameter value is not convertible * to the {@code double} type. * * @see Parameter#getNumericValue() */ @Override public double doubleValue() throws InvalidParameterTypeException { final Parameter parameter = this.parameter; if (parameter.isString() || parameter.getLength() != 1) { throw invalidType(parameter, Double.class); } return parameter.getNumericValue(); }
/** * Sets this parameter to the given value. This method creates a new {@link Parameter} * instance with the given value. * * @throws InvalidParameterValueException if this parameter can not accept the {@code double} type. * * @see Parameter#Parameter(String, double) */ @Override public void setValue(final double value) throws InvalidParameterValueException { final Parameter parameter = this.parameter; if (parameter.isString() || parameter.getLength() != 1) { throw invalidValue(parameter, value); } this.parameter = new Parameter(getCode(), value); }
private Element makeAttribute( ucar.unidata.util.Parameter att, String elementName) { Element attElem = new Element(elementName, thredds.client.catalog.Catalog.ncmlNS); attElem.setAttribute("name", att.getName()); if (att.isString()) { String value = att.getStringValue(); String err = org.jdom2.Verifier.checkCharacterData(value); if (err != null) { value = "NcMLWriter invalid attribute value, err= "+err; System.out.println(value); } attElem.setAttribute("value", value); } else { attElem.setAttribute("type", "double"); StringBuffer buff = new StringBuffer(); for (int i=0; i<att.getLength(); i++) { double val = att.getNumericValue(i); if (i > 0) buff.append( " "); buff.append( Double.toString( val)); } attElem.setAttribute("value", buff.toString()); } return attElem; }
private Element makeAttribute( ucar.unidata.util.Parameter att, String elementName) { Element attElem = new Element(elementName, ncNS); attElem.setAttribute("name", att.getName()); if (att.isString()) { String value = att.getStringValue(); String err = org.jdom2.Verifier.checkCharacterData(value); if (err != null) { value = "NcMLWriter invalid attribute value, err= "+err; System.out.println(value); } attElem.setAttribute("value", value); } else { attElem.setAttribute("type", "double"); StringBuffer buff = new StringBuffer(); for (int i=0; i<att.getLength(); i++) { double val = att.getNumericValue(i); if (i > 0) buff.append( " "); buff.append( Double.toString( val)); } attElem.setAttribute("value", buff.toString()); } return attElem; }
private Element makeAttribute( ucar.unidata.util.Parameter att, String elementName) { Element attElem = new Element(elementName, ncNS); attElem.setAttribute("name", att.getName()); if (att.isString()) { String value = att.getStringValue(); String err = org.jdom2.Verifier.checkCharacterData(value); if (err != null) { value = "NcMLWriter invalid attribute value, err= "+err; System.out.println(value); } attElem.setAttribute("value", value); } else { attElem.setAttribute("type", "double"); StringBuffer buff = new StringBuffer(); for (int i=0; i<att.getLength(); i++) { double val = att.getNumericValue(i); if (i > 0) buff.append( " "); buff.append( Double.toString( val)); } attElem.setAttribute("value", buff.toString()); } return attElem; }
public static String getWcs1_0CrsId(Projection proj) { String paramName = null; if (proj == null) paramName = "LatLon"; else { for (Parameter curParam : proj.getProjectionParameters()) if (curParam.getName().equalsIgnoreCase(CF.GRID_MAPPING_NAME) && curParam.isString()) paramName = curParam.getStringValue(); } if (paramName == null) { log.warn("getWcs1_0CrsId(): Unknown projection - " + projToString(proj)); return ProjectionStandardsInfo.Unknown.getOgcName(); } if (paramName.equalsIgnoreCase("LatLon")) { paramName = "latitude_longitude"; return "OGC:CRS84"; } ProjectionStandardsInfo psi = ProjectionStandardsInfo.getProjectionByCfName(paramName); String crsId = "EPSG:" + psi.getEpsgCode() + " [" + psi.name(); if (psi.equals(ProjectionStandardsInfo.Unknown)) { log.warn("getWcs1_0CrsId(): Unknown projection - " + projToString(proj)); crsId += " - " + paramName; } return crsId + "]"; }
public static String getWcs1_0CrsId(Projection proj) { String paramName = null; if (proj == null) paramName = "LatLon"; else { for (Parameter curParam : proj.getProjectionParameters()) if (curParam.getName().equalsIgnoreCase(CF.GRID_MAPPING_NAME) && curParam.isString()) paramName = curParam.getStringValue(); } if (paramName == null) { log.warn("getWcs1_0CrsId(): Unknown projection - " + projToString(proj)); return ProjectionStandardsInfo.Unknown.getOgcName(); } if (paramName.equalsIgnoreCase("LatLon")) { paramName = "latitude_longitude"; return "OGC:CRS84"; } ProjectionStandardsInfo psi = ProjectionStandardsInfo.getProjectionByCfName(paramName); String crsId = "EPSG:" + psi.getEpsgCode() + " [" + psi.name(); if (psi.equals(ProjectionStandardsInfo.Unknown)) { log.warn("getWcs1_0CrsId(): Unknown projection - " + projToString(proj)); crsId += " - " + paramName; } return crsId + "]"; }
/** * A copy constructor using a ucar.unidata.util.Parameter. * Need to do this so ucar.unidata.geoloc package doesnt depend on ucar.nc2 library * * @param param copy info from here. */ public Attribute(ucar.unidata.util.Parameter param) { super(param.getName()); if (param.isString()) { setStringValue(param.getStringValue()); } else { double[] values = param.getNumericValues(); int n = values.length; Array vala = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[]{n}, values); setValues(vala); } }
/** * A copy constructor using a ucar.unidata.util.Parameter. * Need to do this so ucar.unidata.geoloc package doesnt depend on ucar.nc2 library * * @param param copy info from here. */ public Attribute(ucar.unidata.util.Parameter param) { this(param.getName()); if (param.isString()) { setStringValue(param.getStringValue()); } else { double[] values = param.getNumericValues(); int n = values.length; Array vala = Array.factory(DataType.DOUBLE, new int[]{n}, values); setValues(vala); } setImmutable(); }
/** * A copy constructor using a ucar.unidata.util.Parameter. * Need to do this so ucar.unidata.geoloc package doesnt depend on ucar.nc2 library * * @param param copy info from here. */ public Attribute(ucar.unidata.util.Parameter param) { this(param.getName()); if (param.isString()) { setStringValue(param.getStringValue()); } else { double[] values = param.getNumericValues(); int n = values.length; Array vala = Array.factory(DataType.DOUBLE.getPrimitiveClassType(), new int[]{n}, values); setValues(vala); } setImmutable(true); }
/** * Create a "dummy" Coordinate Transform Variable based on the given CoordinateTransform. * This creates a scalar Variable with dummy data, and adds the Parameters of the CoordinateTransform * as attributes. * @param ds for this dataset * @param ct based on the CoordinateTransform * @return the Coordinate Transform Variable. You must add it to the dataset. */ static public VariableDS makeDummyTransformVariable(NetcdfDataset ds, CoordinateTransform ct) { VariableDS v = new VariableDS( ds, null, null, ct.getName(), DataType.CHAR, "", null, null); List<Parameter> params = ct.getParameters(); for (Parameter p : params) { if (p.isString()) v.addAttribute(new Attribute(p.getName(), p.getStringValue())); else { double[] data = p.getNumericValues(); Array dataA = Array.factory(DataType.DOUBLE, new int[]{data.length}, data); v.addAttribute(new Attribute(p.getName(), dataA)); } } v.addAttribute( new Attribute(_Coordinate.TransformType, ct.getTransformType().toString())); // fake data Array data = Array.factory(DataType.CHAR, new int[] {}, new char[] {' '}); v.setCachedData(data, true); return v; }
/** * Create a "dummy" Coordinate Transform Variable based on the given CoordinateTransform. * This creates a scalar Variable with dummy data, and adds the Parameters of the CoordinateTransform * as attributes. * @param ds for this dataset * @param ct based on the CoordinateTransform * @return the Coordinate Transform Variable. You must add it to the dataset. */ static public VariableDS makeDummyTransformVariable(NetcdfDataset ds, CoordinateTransform ct) { VariableDS v = new VariableDS( ds, null, null, ct.getName(), DataType.CHAR, "", null, null); List<Parameter> params = ct.getParameters(); for (Parameter p : params) { if (p.isString()) v.addAttribute(new Attribute(p.getName(), p.getStringValue())); else { double[] data = p.getNumericValues(); Array dataA = Array.factory(double.class, new int[]{data.length}, data); v.addAttribute(new Attribute(p.getName(), dataA)); } } v.addAttribute( new Attribute(_Coordinate.TransformType, ct.getTransformType().toString())); // fake data Array data = Array.factory(DataType.CHAR.getPrimitiveClassType(), new int[] {}, new char[] {' '}); v.setCachedData(data, true); return v; }