/** Converts a 3D variable to a {@link Metadata} representation */ private static void convert3DVariable(GridDatatype g, Date date, Map<String, Metadata> metaMap) throws IOException { Variable v = g.getVariable(); System.out.println("Reading: " + v.getFullName()); Array values = v.read(); int h = v.getShape(1); int w = v.getShape(2); for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { LatLonPoint pt = g.getCoordinateSystem().getLatLon(j, i); String hash = GeoHash.encode((float) pt.getLatitude(), (float) pt.getLongitude(), 10).toLowerCase(); Metadata meta = metaMap.get(hash); if (meta == null) { /* We need to create Metadata for this location */ meta = new Metadata(); UUID metaUUID = UUID.nameUUIDFromBytes(hash.getBytes()); meta.setName(metaUUID.toString()); SpatialProperties location = new SpatialProperties((float) pt.getLatitude(), (float) pt.getLongitude()); meta.setSpatialProperties(location); TemporalProperties time = new TemporalProperties(date.getTime()); meta.setTemporalProperties(time); metaMap.put(hash, meta); } String featureName = v.getFullName().toLowerCase(); float featureValue = values.getFloat(i * w + j); Feature feature = new Feature(featureName, featureValue); meta.putAttribute(feature); } } }
/** * Takes a Metadata instance being used as Block content, and extracts the given Feature for * indexing purposes. */ private static void addIndexField(String featureName, Metadata baseMeta, Metadata indexMeta) { Feature f = baseMeta.getAttribute(featureName); if (f != null) { indexMeta.putAttribute(f); } }