Java Code Examples for ucar.nc2.dataset.NetcdfDataset#setId()
The following examples show how to use
ucar.nc2.dataset.NetcdfDataset#setId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreddsDataFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Add information from the InvDataset to the NetcdfDataset. * * @param ds get info from here * @param ncDataset add to here */ public static void annotate(InvDataset ds, NetcdfDataset ncDataset) { ncDataset.setTitle(ds.getName()); ncDataset.setId(ds.getID()); // add properties as global attributes for (InvProperty p : ds.getProperties()) { String name = p.getName(); if (null == ncDataset.findGlobalAttribute(name)) { ncDataset.addAttribute(null, new Attribute(name, p.getValue())); } } /* * ThreddsMetadata.GeospatialCoverage geoCoverage = ds.getGeospatialCoverage(); * if (geoCoverage != null) { * if ( null != geoCoverage.getNorthSouthRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_lat_min", new Double(geoCoverage.getLatSouth()))); * ncDataset.addAttribute(null, new Attribute("geospatial_lat_max", new Double(geoCoverage.getLatNorth()))); * } * if ( null != geoCoverage.getEastWestRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_lon_min", new Double(geoCoverage.getLonWest()))); * ncDataset.addAttribute(null, new Attribute("geospatial_lon_max", new Double(geoCoverage.getLonEast()))); * } * if ( null != geoCoverage.getUpDownRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_vertical_min", new Double(geoCoverage.getHeightStart()))); * ncDataset.addAttribute(null, new Attribute("geospatial_vertical_max", new Double(geoCoverage.getHeightStart() + * geoCoverage.getHeightExtent()))); * } * } * * DateRange timeCoverage = ds.getTimeCoverage(); * if (timeCoverage != null) { * ncDataset.addAttribute(null, new Attribute("time_coverage_start", * timeCoverage.getStart().toDateTimeStringISO())); * ncDataset.addAttribute(null, new Attribute("time_coverage_end", timeCoverage.getEnd().toDateTimeStringISO())); * } */ ncDataset.finish(); }
Example 2
Source File: DataFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private NetcdfDataset openDataset(Access access, boolean acquire, ucar.nc2.util.CancelTask task, Result result) throws IOException { Dataset ds = access.getDataset(); String datasetId = ds.getId(); String title = ds.getName(); String datasetLocation = access.getStandardUrlName(); ServiceType serviceType = access.getService().getType(); if (debugOpen) System.out.println("ThreddsDataset.openDataset= " + datasetLocation); // deal with RESOLVER type if (serviceType == ServiceType.Resolver) { Dataset rds = openResolver(datasetLocation, task, result); if (rds == null) return null; return openDataset(rds, acquire, task, result); } // ready to open it through netcdf API DatasetUrl durl = DatasetUrl.create(serviceType, datasetLocation); NetcdfDataset ncd = acquire ? NetcdfDatasets.acquireDataset(durl, true, task) : NetcdfDatasets.openDataset(durl, null, -1, task, null); /* * String prefix = null; * if ((serviceType == ServiceType.OPENDAP)|| (serviceType == ServiceType.DODS)) * prefix = "dods:"; * else if(serviceType == ServiceType.DAP4) * prefix = "dap4:"; * * boolean enhanceMode = true; * if (prefix != null) { * String curl = datasetLocation; * if (curl.startsWith("http:")) { * curl = prefix + datasetLocation.substring(5); * } else if (curl.startsWith("https:")) { * curl = prefix + curl.substring(6); * } * ncd = acquire ? NetcdfDataset.acquireDataset(curl, enhanceMode, task) : NetcdfDataset.openDataset(curl, * enhanceMode, task); * } * * // open CdmRemote * else if (serviceType == ServiceType.CdmRemote) { * String curl = CdmRemote.canonicalURL(datasetLocation); * ncd = acquire ? NetcdfDataset.acquireDataset(curl, enhanceMode, task) : NetcdfDataset.openDataset(curl, * enhanceMode, task); * } * * // open HTTPServer * else if (serviceType == ServiceType.HTTPServer) { * String curl = (datasetLocation.startsWith("http:")) ? "httpserver:" + datasetLocation.substring(5) : * datasetLocation; * ncd = acquire ? NetcdfDataset.acquireDataset(curl, enhanceMode, task) : NetcdfDataset.openDataset(curl, * enhanceMode, task); * } * * else { * // open through NetcdfDataset API * ncd = acquire ? NetcdfDataset.acquireDataset(datasetLocation, enhanceMode, task) : * NetcdfDataset.openDataset(datasetLocation, enhanceMode, task); * } */ result.accessUsed = access; ncd.setId(datasetId); ncd.setTitle(title); annotate(ds, ncd); /* * see if there's NcML metadata LOOK whats this * List<Metadata> list = ds.getMetadata(Metadata.Type.NcML); * if (list != null && list.size() > 0) { * Metadata ncmlMetadata = list.get(0); * NcMLReader.wrapNcML(ds, ncmlMetadata.getXlinkHref(), null); * } */ return ncd; }
Example 3
Source File: DataFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Add information from the Dataset to the NetcdfDataset. * * @param ds get info from here * @param ncDataset add to here */ public static void annotate(Dataset ds, NetcdfDataset ncDataset) { ncDataset.setTitle(ds.getName()); ncDataset.setId(ds.getId()); // add properties as global attributes for (Property p : ds.getProperties()) { String name = p.getName(); if (null == ncDataset.findGlobalAttribute(name)) { ncDataset.addAttribute(null, new Attribute(name, p.getValue())); } } /* * ThreddsMetadata.GeospatialCoverage geoCoverage = ds.getGeospatialCoverage(); * if (geoCoverage != null) { * if ( null != geoCoverage.getNorthSouthRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_lat_min", new Double(geoCoverage.getLatSouth()))); * ncDataset.addAttribute(null, new Attribute("geospatial_lat_max", new Double(geoCoverage.getLatNorth()))); * } * if ( null != geoCoverage.getEastWestRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_lon_min", new Double(geoCoverage.getLonWest()))); * ncDataset.addAttribute(null, new Attribute("geospatial_lon_max", new Double(geoCoverage.getLonEast()))); * } * if ( null != geoCoverage.getUpDownRange()) { * ncDataset.addAttribute(null, new Attribute("geospatial_vertical_min", new Double(geoCoverage.getHeightStart()))); * ncDataset.addAttribute(null, new Attribute("geospatial_vertical_max", new Double(geoCoverage.getHeightStart() + * geoCoverage.getHeightExtent()))); * } * } * * DateRange timeCoverage = ds.getTimeCoverage(); * if (timeCoverage != null) { * ncDataset.addAttribute(null, new Attribute("time_coverage_start", * timeCoverage.getStart().toDateTimeStringISO())); * ncDataset.addAttribute(null, new Attribute("time_coverage_end", timeCoverage.getEnd().toDateTimeStringISO())); * } */ ncDataset.finish(); }