/** * Extract the {@link CoordinateReferenceSystem} from a NetCDF attribute (if present) * containing a WKT String * * @param wktAttribute the NetCDF {@link Attribute} if any, containing WKT definition. * @return */ private static CoordinateReferenceSystem parseWKT(Attribute wktAttribute) { CoordinateReferenceSystem crs = null; if (wktAttribute != null) { String wkt = wktAttribute.getStringValue(); try { crs = CRS.parseWKT(wkt); } catch (FactoryException e) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("Unable to setup a CRS from the specified WKT: " + wkt); } } } return crs; }
if (coordinatesAttribute != null) { coordinates = coordinatesAttribute.getStringValue(); } else if (!(var instanceof CoordinateAxis)) {
private static Variable getAuxiliaryCoordinate( NetcdfDataset dataset, Group group, Variable var, String dimName) { Variable coordinateVariable = null; Attribute attribute = var.findAttribute(NetCDFUtilities.COORDINATES); if (attribute != null) { String coordinates = attribute.getStringValue(); String[] coords = coordinates.split(" "); for (String coord : coords) { Variable coordVar = dataset.findVariable(group, coord); List<Dimension> varDimensions = coordVar.getDimensions(); if (varDimensions != null && varDimensions.size() == 1 && varDimensions.get(0).getFullName().equalsIgnoreCase(dimName)) { coordinateVariable = coordVar; break; } } } return coordinateVariable; }
private String getCoordinatesForVariable(String shortName) { Variable var = dataset.findVariable(null, shortName); if (var != null) { // Getting the coordinates attribute Attribute attribute = var.findAttribute(NetCDFUtilities.COORDINATES); if (attribute != null) { return attribute.getStringValue(); } else { return var.getDimensionsString(); } } return null; }
/** Look for a Coordinate Reference System */ private CoordinateReferenceSystem lookForCrs( CoordinateReferenceSystem crs, Attribute gridMappingAttribute, Variable var) throws FactoryException { if (gridMappingAttribute != null) { String gridMappingName = gridMappingAttribute.getStringValue(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("The variable refers to gridMapping: " + gridMappingName); } Variable mapping = dataset.findVariable(null, gridMappingName); if (mapping != null) { CoordinateReferenceSystem localCrs = NetCDFProjection.parseProjection(mapping); if (localCrs != null) { // lookup for a custom EPSG if any crs = NetCDFProjection.lookupForCustomEpsg(localCrs); } } else if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "The specified variable " + var.getFullName() + " declares a gridMapping = " + gridMappingName + " but that mapping doesn't exist."); } } return crs; } }
@Override public CoordinateReferenceSystem parseCoordinateReferenceSystem(Variable var) throws FactoryException { String mappingName = attribute.getStringValue(); String projectionName = getProjectionName(mappingName, var); // Getting the proper projection and set the projection parameters NetCDFProjection projection = supportedProjections.get(projectionName); if (projection == null) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Unsupported grid_mapping_name: " + projectionName); } return null; } String ogcName = projection.getOGCName(); // The OGC projection parameters ParameterValueGroup netcdfParameters = ProjectionBuilder.getDefaultparameters(ogcName); // Get the OGC to NetCDF projection parameters Map<String, String> paramsMapping = projection.getParameters(); Set<String> keys = paramsMapping.keySet(); for (String ogcParameterKey : keys) { handleParam(paramsMapping, netcdfParameters, ogcParameterKey, var); } return ProjectionBuilder.buildCRS( Collections.singletonMap(NetCDFUtilities.NAME, projectionName), projection.getOgcParameters(netcdfParameters), buildEllipsoid(var, SI.METRE)); } }
final Attribute attribute = coordinateAxis.findAttribute("time_origin"); if (attribute != null) { origin = attribute.getStringValue();
final Attribute attribute = timeAxis.findAttribute("time_origin"); if (attribute != null) { origin = attribute.getStringValue();
protected void unravelStringMet(NetcdfFile ncFile, Group group, Metadata met) { if (group == null) { group = ncFile.getRootGroup(); } // get file type met.set("File-Type-Description", ncFile.getFileTypeDescription()); // unravel its string attrs for (Attribute attribute : group.getAttributes()) { if (attribute.isString()) { met.add(attribute.getFullName(), attribute.getStringValue()); } else { // try and cast its value to a string met.add(attribute.getFullName(), String.valueOf(attribute .getNumericValue())); } } for (Group g : group.getGroups()) { unravelStringMet(ncFile, g, met); } }
public boolean match(CoordinateAxis axis) { Attribute stdName = axis.findAttribute(CF.STANDARD_NAME); return ((stdName == null) || !CF.STATION_ALTITUDE.equals(stdName.getStringValue())); } });
public String getRadarID() { Attribute ga = ds.findGlobalAttribute("Station"); if(ga != null) return ga.getStringValue(); else return "XXXX"; }
/** * Is this Variable unsigned?. Only meaningful for byte, short, int, long types. * Looks for attribute "_Unsigned", case insensitive * * @return true if Variable is unsigned */ public boolean isUnsigned() { Attribute att = findAttributeIgnoreCase(CDM.UNSIGNED); return (att != null) && att.getStringValue().equalsIgnoreCase("true"); }
public String getRadarName() { Attribute ga = ds.findGlobalAttribute("StationName"); if(ga != null) return ga.getStringValue(); else return "Unknown Station"; }
Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) { metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue();
private void writeStringValues(Attribute att) throws IOException { int n = att.getLength(); if (n == 1) writeString(att.getStringValue()); else { StringBuilder values = new StringBuilder(); for (int i = 0; i < n; i++) values.append(att.getStringValue(i)); writeString(values.toString()); } }
public String getDescription() { Attribute att = ncvar.findAttributeIgnoreCase(CDM.LONG_NAME); return (att == null) ? getName() : att.getStringValue(); } public DataType getValueType() { return valueType; }
Property property = resolveMetadataKey(attr.getFullName()); if (attr.getDataType().isString()) { metadata.add(property, attr.getStringValue()); } else if (attr.getDataType().isNumeric()) { int value = attr.getNumericValue().intValue();
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException { Attribute levelAtt = ds.findAttribute("/HDFEOS/ADDITIONAL/FILE_ATTRIBUTES/@ProcessLevel"); if (levelAtt == null) return; int level = levelAtt.getStringValue().startsWith("2") ? 2 : 3; Attribute time = ds.findAttribute("/HDFEOS/ADDITIONAL/FILE_ATTRIBUTES/@TAI93At0zOfGranule"); if (level == 3) augmentDataset3(ds); }
private void addAttributeInfo(NetcdfDataset result, String attName, String info) { Attribute att = result.findGlobalAttribute(attName); if (att == null) result.addAttribute(null, new Attribute(attName, info)); else { String oldValue = att.getStringValue(); result.addAttribute(null, new Attribute(attName, oldValue +" ;\n"+ info)); } }
public void rewrite() throws IOException, InvalidRangeException { Attribute attr = ncIn.getRootGroup().findAttribute("featureType"); if(attr.getStringValue().contains("RADIAL")) isRadial = true; createGroup(null, ncIn.getRootGroup()); ncOut.create(); transferData(ncIn.getRootGroup()); ncOut.close(); }