/** * get all radar station within box. * * @param boundingBox the bounding box * @param cancel the cancel task * @return List Station objects * @throws IOException java io exception */ public List<Station> getStations(LatLonRect boundingBox, ucar.nc2.util.CancelTask cancel) throws IOException { Collection<Station> sl = stationHMap.values(); List<Station> dsl = new ArrayList<Station>(); if (!boundingBox.containedIn(radarRegion)) { return null; } // for (Iterator it = sl.iterator(); it.hasNext(); ) { // Station s = (Station) it.next(); for (Station s : sl) { // LatLonPointImpl latlonPt = new LatLonPointImpl(); // latlonPt.set(s.getLatitude(), s.getLongitude()); // if (boundingBox.contains(latlonPt)) { if (boundingBox.contains(s.getLatLon())) { dsl.add(s); } if ((cancel != null) && cancel.isCancel()) { return null; } } return dsl; }
public void init() throws ServletException { super.init(); // allow = ThreddsConfig.getBoolean("NetcdfSubsetService.allow", true); // String radarLevel2Dir = ThreddsConfig.get("NetcdfSubsetService.radarLevel2DataDir", // "/data/ldm/pub/native/radar/level2/"); // if (!allow) return; contentPath = ServletUtil.getContentPath(); rm = new RadarMethods(contentPath, logServerStartup); // read in radarCollections.xml catalog InvCatalogFactory factory = InvCatalogFactory.getDefaultFactory(false); // no validation cat = readCatalog(factory, getPath() + catName, contentPath + getPath() + catName); if (cat == null) { logServerStartup.info("cat initialization failed"); return; } // URI tmpURI = cat.getBaseURI(); cat.setBaseURI(catURI); // get path and location from cat List parents = cat.getDatasets(); for (int i = 0; i < parents.size(); i++) { InvDataset top = (InvDataset) parents.get(i); datasets = top.getDatasets(); // dataset scans for (int j = 0; j < datasets.size(); j++) { InvDatasetScan ds = (InvDatasetScan) datasets.get(j); if (ds.getPath() != null) { dataLocation.put(ds.getPath(), ds.getScanLocation()); logServerStartup.info("path =" + ds.getPath() + " location =" + ds.getScanLocation()); } ds.setXlinkHref(ds.getPath() + "/dataset.xml"); } } logServerStartup.info(getClass().getName() + " initialization complete "); } // end init
/** * retrieve all radar stations in this dataset collection * * @param stsXML_location _more_ * @return station hashmap * @throws IOException _more_ */ public HashMap<String, Station> readRadarStations(String stsXML_location) throws IOException { SAXBuilder builder; Document doc = null; XMLEntityResolver jaxp = new XMLEntityResolver(true); builder = jaxp.getSAXBuilder(); HashMap<String, Station> stations = new HashMap<String, Station>(); try { doc = builder.build(stsXML_location); } catch (JDOMException e) { e.printStackTrace(); } Element rootElem = doc.getRootElement(); List<Element> children = rootElem.getChildren(); for (Element child : children) { Station s; if (null != (s = readStation(child))) { stations.put(s.getName(), s); } } return stations; }
private void datasetInfoXml(RadarType radarType, String pathInfo, PrintWriter pw) throws IOException { try { pw.println( "<catalog xmlns=\"http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" name=\"Radar Data\" version=\"1.0.1\">\n"); // add service pw.println( " <service name=\"radarServer\" base=\"/thredds/radarServer/\" serviceType=\"DQC\" />\n"); pathInfo = pathInfo.replace("/dataset.xml", ""); pathInfo = pathInfo.replace("/catalog.xml", ""); if (pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1); for (int i = 0; i < datasets.size(); i++) { InvDatasetScan ds = (InvDatasetScan) datasets.get(i); if (!(pathInfo.equals(ds.getPath()))) { continue; } pw.println(" <dataset ID=\"" + ds.getID() + "\" serviceName=\"radarServer\">"); pw.println(" <urlpath>" + ds.getPath() + "</urlpath>"); pw.println(" <dataType>" + ds.getDataType() + "</dataType>"); pw.println(" <dataFormat>" + ds.getDataFormatType() + "</dataFormat>"); pw.println(" <serviceName>radarServer</serviceName>"); pw.println(" <metadata inherited=\"true\">"); pw.println(" <documentation type=\"summary\">" + ds.getSummary() + "</documentation>"); CalendarDateRange dr = ds.getCalendarDateCoverage(); pw.println(" <TimeSpan>"); pw.print(" <start>"); if (pathInfo.contains("IDD")) { pw.print(rm.getStartDateTime(ds.getPath())); } else { pw.print(dr.getStart().toString()); } pw.println("</start>"); pw.println(" <end>" + dr.getEnd().toString() + "</end>"); pw.println(" </TimeSpan>"); ThreddsMetadata.GeospatialCoverage gc = ds.getGeospatialCoverage(); LatLonRect bb = new LatLonRect(); gc.setBoundingBox(bb); pw.println(" <LatLonBox>"); pw.println(" <north>" + gc.getLatNorth() + "</north>"); pw.println(" <south>" + gc.getLatSouth() + "</south>"); pw.println(" <east>" + gc.getLonEast() + "</east>"); pw.println(" <west>" + gc.getLonWest() + "</west>"); pw.println(" </LatLonBox>"); ThreddsMetadata.Variables cvs = (ThreddsMetadata.Variables) ds.getVariables().get(0); List vl = cvs.getVariableList(); pw.println(" <Variables>"); for (int j = 0; j < vl.size(); j++) { ThreddsMetadata.Variable v = (ThreddsMetadata.Variable) vl.get(j); pw.println( " <variable name=\"" + v.getName() + "\" vocabulary_name=\"" + v.getVocabularyName() + "\" units=\"" + v.getUnits() + "\" />"); } pw.println(" </Variables>"); String[] stations = rm.stationsDS(radarType, dataLocation.get(ds.getPath())); rm.printStations(stations, pw, radarType); pw.println(" </metadata>"); pw.println(" </dataset>"); } pw.println("</catalog>"); pw.flush(); } catch (Throwable e) { log.error("RadarServer.datasetInfoXml", e); } return; }