/** * 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(); }
/** * 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); } }
/** * Add an attribute to this projection * * @param name name of the attribute * @param value attribute value as a double */ protected void addParameter(String name, double value) { atts.add(new Parameter(name, value)); }
/** * 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; }
protected String getParameterStringValue(List<Parameter> params, String name) { for (Parameter a : params) { if (name.equalsIgnoreCase(a.getName())) return a.getStringValue(); } return null; }
/** * 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(); }
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 + "]"; }
/** * Returns the parameter name. This method delegates to {@link Parameter#getName()}. * The name returned by this method is the netCDF name. For the OGC or EPSG names, * see {@link #getAlias()}. * * @return the netCDF parameter name. * * @see Parameter#getName() */ @Override public String getCode() { return parameter.getName(); }
/** * 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); } }
/** * 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); }
/** * 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(); }
for (Parameter p : proj.getProjectionParameters()) { logger.debug("{}", p); if (p.getName().equals(CF.EARTH_RADIUS)) { found = true; radius = p.getNumericValue(); if (p.getName().equals(CF.SEMI_MAJOR_AXIS)) { found = true; radius = p.getNumericValue();
String[] varStrings = param.getStringValue().split(" "); for(int i = 1; i<varStrings.length; i+=2 ){ Variable paramVar = ncd.findVariable(varStrings[i].trim());
/** * 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(); }
/** * Instances which have same content are equal. * * @param oo compare to this Parameter. * @return true if equal. */ public boolean equals(Object oo) { if (this == oo) { return true; } if (!(oo instanceof Parameter)) { return false; } return hashCode() == oo.hashCode(); }
/** * Returns the {@linkplain Parameter#getNumericValue() parameter numeric value} * as a floating point value. */ @Override public double doubleValue() throws InvalidParameterTypeException { return delegate().getNumericValue(index); }
private static String projToString(Projection proj) { if (proj == null) return "null"; StringBuilder sb = new StringBuilder(); sb.append(proj.getName()) .append(" [").append(proj.getClassName()) .append("] - parameters=["); for (Parameter curProjParam : proj.getProjectionParameters()) { sb.append("(").append(curProjParam.toString()).append(")"); } sb.append("]"); return sb.toString(); }
/** * Sets this parameter to the given value. This method modify the internal array of the * netCDF {@link Parameter} instance. This is usually not a recommended practice, since * those {@code Parameter} are usually considered immutable. However in our case we * really want to modify existing instance without creating new instance, because the * same instance need to be shared by many {@code IndexedParameter} wrappers: one for * each index. */ @Override public void setValue(final double value) throws InvalidParameterValueException { delegate().getNumericValues()[index] = value; }
protected String getParameterStringValue(List<Parameter> params, String name) { for (Parameter a : params) { if (name.equalsIgnoreCase(a.getName())) return a.getStringValue(); } return null; }
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 + "]"; }