public void testSingleDataset() throws IOException { InvCatalogImpl cat = TestTDSAll.open(null); InvDataset ds = cat.findDatasetByID("testSingleDataset"); assert (ds != null) : "cant find dataset 'testSingleDataset'"; assert ds.getDataType() == FeatureType.GRID; ThreddsDataFactory fac = new ThreddsDataFactory(); ThreddsDataFactory.Result dataResult = fac.openFeatureDataset(ds, null); assert dataResult != null; assert !dataResult.fatalError; assert dataResult.featureDataset != null; GridDataset gds = (GridDataset) dataResult.featureDataset; GridDatatype grid = gds.findGridDatatype("Z_sfc"); assert grid != null; GridCoordSystem gcs = grid.getCoordinateSystem(); assert gcs != null; assert null == gcs.getVerticalAxis(); CoordinateAxis1D time = gcs.getTimeAxis1D(); assert time != null; assert time.getSize() == 1; assert 102840.0 == time.readScalarDouble(); dataResult.featureDataset.close(); }
void setField(GridDatatype field) { /*int idx = fieldChooser.setSelectedByName(field.toString()); if (idx < 0) fieldChooser.setSelectedByIndex(0); */ fieldChooser.setToolTipText(field.getName()); GridCoordSystem gcs = field.getCoordinateSystem(); // levels CoordinateAxis1D axis = gcs.getVerticalAxis(); setChooserWanted("level", axis != null); if (axis != null) { List<NamedObject> levels = axis.getNames(); levelChooser.setCollection(levels.iterator(), true); NamedObject no = levels.get(controller.getCurrentLevelIndex()); levelChooser.setSelectedByName(no.getName()); } // times if (gcs.hasTimeAxis()) { axis = gcs.hasTimeAxis1D() ? gcs.getTimeAxis1D() : gcs.getTimeAxisForRun(0); setChooserWanted("time", axis != null); if (axis != null) { List<NamedObject> names = axis.getNames(); timeChooser.setCollection(names.iterator(), true); NamedObject no = names.get(controller.getCurrentTimeIndex()); timeChooser.setSelectedByName(no.getName()); } } else { setChooserWanted("time", false); } axis = gcs.getEnsembleAxis(); setChooserWanted("ensemble", axis != null); if (axis != null) { List<NamedObject> names = axis.getNames(); ensembleChooser.setCollection(names.iterator(), true); NamedObject no = names.get(controller.getCurrentEnsembleIndex()); ensembleChooser.setSelectedByName(no.getName()); } axis = gcs.getRunTimeAxis(); setChooserWanted("runtime", axis != null); if (axis != null) { List<NamedObject> names = axis.getNames(); runtimeChooser.setCollection(names.iterator(), true); NamedObject no = names.get(controller.getCurrentRunTimeIndex()); runtimeChooser.setSelectedByName(no.getName()); } setChoosers(); colorScalePanel.setUnitString(field.getUnitsString()); }
public static ThreddsMetadata.GeospatialCoverage extractGeospatial(GridDataset gridDataset) { ThreddsMetadata.GeospatialCoverage gc = new ThreddsMetadata.GeospatialCoverage(); LatLonRect llbb = null; CoordinateAxis1D vaxis = null; for (GridDataset.Gridset gridset : gridDataset.getGridsets()) { GridCoordSystem gsys = gridset.getGeoCoordSystem(); if (llbb == null) llbb = gsys.getLatLonBoundingBox(); CoordinateAxis1D vaxis2 = gsys.getVerticalAxis(); if (vaxis == null) vaxis = vaxis2; else if ((vaxis2 != null) && (vaxis2.getSize() > vaxis.getSize())) vaxis = vaxis2; } if (llbb != null) gc.setBoundingBox(llbb); if (vaxis != null) gc.setVertical(vaxis); return gc; }
protected Element genLonLatEnvelope(GridCoordSystem gcs) { // <CoverageOfferingBrief>/lonLatEnvelope Element lonLatEnvelopeElem = new Element("lonLatEnvelope", wcsNS); lonLatEnvelopeElem.setAttribute("srsName", "urn:ogc:def:crs:OGC:1.3:CRS84"); LatLonRect llbb = gcs.getLatLonBoundingBox(); LatLonPoint llpt = llbb.getLowerLeftPoint(); LatLonPoint urpt = llbb.getUpperRightPoint(); // <CoverageOfferingBrief>/lonLatEnvelope/gml:pos String firstPosition = llpt.getLongitude() + " " + llpt.getLatitude(); double lon = llpt.getLongitude() + llbb.getWidth(); String secondPosition = lon + " " + urpt.getLatitude(); // ToDo WCS 1.0Plus - Deal with conversion to meters. (Yikes!!) CoordinateAxis1D vertAxis = gcs.getVerticalAxis(); if (vertAxis != null) { // See verAxis.getUnitsString() double zeroIndexValue = vertAxis.getCoordValue(0); double sizeIndexValue = vertAxis.getCoordValue(((int) vertAxis.getSize()) - 1); if (vertAxis.getPositive().equals(ucar.nc2.constants.CF.POSITIVE_UP)) { firstPosition += " " + zeroIndexValue; secondPosition += " " + sizeIndexValue; } else { firstPosition += " " + sizeIndexValue; secondPosition += " " + zeroIndexValue; } } lonLatEnvelopeElem.addContent(new Element("pos", gmlNS).addContent(firstPosition)); lonLatEnvelopeElem.addContent(new Element("pos", gmlNS).addContent(secondPosition)); // <CoverageOfferingBrief>/lonLatEnvelope/gml:timePostion [2] if (gcs.hasTimeAxis()) { lonLatEnvelopeElem.addContent( new Element("timePosition", gmlNS) .addContent(gcs.getCalendarDateRange().getStart().toString())); lonLatEnvelopeElem.addContent( new Element("timePosition", gmlNS) .addContent(gcs.getCalendarDateRange().getEnd().toString())); } return lonLatEnvelopeElem; }