ucar.unidata.geoloc.LatLonRect Java Examples

The following examples show how to use ucar.unidata.geoloc.LatLonRect. 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: FeatureDatasetCapabilitiesWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Element writeBoundingBox(LatLonRect bb) {
  int decToKeep = 6;
  double bbExpand = Math.pow(10, -decToKeep);

  // extend the bbox to make sure the implicit rounding does not result in a bbox that does not contain
  // any points (can happen when you have a single station with very precise lat/lon values)
  // See https://github.com/Unidata/thredds/issues/470
  // This accounts for the implicit rounding errors that result from the use of
  // ucar.unidata.util.Format.dfrac when writing out the lat/lon box on the NCSS for Points dataset.html
  // page
  LatLonPoint extendNorthEast = LatLonPoint.create(bb.getLatMax() + bbExpand, bb.getLonMax() + bbExpand);
  LatLonPoint extendSouthWest = LatLonPoint.create(bb.getLatMin() - bbExpand, bb.getLonMin() - bbExpand);
  bb.extend(extendNorthEast);
  bb.extend(extendSouthWest);

  Element bbElem = new Element("LatLonBox"); // from KML

  bbElem.addContent(new Element("west").addContent(ucar.unidata.util.Format.dfrac(bb.getLonMin(), decToKeep)));
  bbElem.addContent(new Element("east").addContent(ucar.unidata.util.Format.dfrac(bb.getLonMax(), decToKeep)));
  bbElem.addContent(new Element("south").addContent(ucar.unidata.util.Format.dfrac(bb.getLatMin(), decToKeep)));
  bbElem.addContent(new Element("north").addContent(ucar.unidata.util.Format.dfrac(bb.getLatMax(), decToKeep)));
  return bbElem;
}
 
Example #2
Source File: CompositeDatasetFactory.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public CompositePointDataset(String location, FeatureType featureType, DsgFeatureCollection pfc,
    TimedCollection datasets, LatLonRect bb) {
  super(featureType);
  setLocationURI(location);
  setPointFeatureCollection(pfc);

  this.pfc = pfc;
  this.dateRange = datasets.getDateRange();

  if (datasets.getDateRange() != null)
    setDateRange(datasets.getDateRange());

  if (bb != null)
    setBoundingBox(bb);

}
 
Example #3
Source File: TestCoverageCrossSeamWriteFile.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
@Category(NeedsCdmUnitTest.class)
public void testCrossLongitudeSeamDt() throws Exception {
  String filename = TestDir.cdmUnitTestDir + "ft/grid/GFS_Global_onedeg_20081229_1800.grib2.nc";
  System.out.printf("open %s%n", filename);

  try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) {
    Assert.assertNotNull(filename, cc);
    CoverageCollection gcs = cc.findCoverageDataset(FeatureType.GRID);
    Assert.assertNotNull("gcs", gcs);
    String covName = "Pressure_surface";
    Coverage coverage = gcs.findCoverage(covName);
    Assert.assertNotNull(covName, coverage);

    CoverageCoordSys cs = coverage.getCoordSys();
    Assert.assertNotNull("coordSys", cs);
    System.out.printf(" org coverage shape=%s%n", Arrays.toString(cs.getShape()));

    HorizCoordSys hcs = cs.getHorizCoordSys();
    Assert.assertNotNull("HorizCoordSys", hcs);

    LatLonRect bbox = new LatLonRect(LatLonPoint.create(40.0, -100.0), 10.0, 120.0);
    writeTestFile(gcs, coverage, bbox, new int[] {1, 11, 121});
  }
}
 
Example #4
Source File: FeatureDatasetCapabilitiesWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static LatLonRect getSpatialExtent(Document doc) {
  Element root = doc.getRootElement();
  Element latlonBox = root.getChild("LatLonBox");
  if (latlonBox == null)
    return null;

  String westS = latlonBox.getChildText("west");
  String eastS = latlonBox.getChildText("east");
  String northS = latlonBox.getChildText("north");
  String southS = latlonBox.getChildText("south");
  if ((westS == null) || (eastS == null) || (northS == null) || (southS == null))
    return null;

  try {
    double west = Double.parseDouble(westS);
    double east = Double.parseDouble(eastS);
    double south = Double.parseDouble(southS);
    double north = Double.parseDouble(northS);
    return new LatLonRect(LatLonPoint.create(south, east), LatLonPoint.create(north, west));

  } catch (Exception e) {
    return null;
  }
}
 
Example #5
Source File: StationCollectionStream.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
Subset(StationCollectionStream from, LatLonRect filter_bb, CalendarDateRange filter_date) {
  super(from.uri, from.getTimeUnit(), from.getAltUnits());
  this.from = from;

  if (filter_bb == null)
    this.boundingBoxSubset = from.getBoundingBox();
  else
    this.boundingBoxSubset =
        (from.getBoundingBox() == null) ? filter_bb : from.getBoundingBox().intersect(filter_bb);

  if (filter_date == null) {
    this.dateRangeSubset = from.dateRangeSubset;
  } else {
    this.dateRangeSubset =
        (from.dateRangeSubset == null) ? filter_date : from.dateRangeSubset.intersect(filter_date);
  }
}
 
Example #6
Source File: RecordDatasetHelper.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public List getData(ArrayList records, LatLonRect boundingBox, CancelTask cancel) throws IOException {
  if (debugBB)
    System.out.println("Want bb= " + boundingBox);
  ArrayList result = new ArrayList();
  for (int i = 0; i < records.size(); i++) {
    RecordDatasetHelper.RecordPointObs r = (RecordDatasetHelper.RecordPointObs) records.get(i);
    if (boundingBox.contains(r.getLatLon())) {
      if (debugBB)
        System.out.println(" ok latlon= " + r.getLatLon());
      result.add(r);
    }
    if ((cancel != null) && cancel.isCancel())
      return null;
  }
  return result;
}
 
Example #7
Source File: GridDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void makeRanges() {

    for (ucar.nc2.dt.GridDataset.Gridset gset : getGridsets()) {
      GridCoordSystem gcs = gset.getGeoCoordSystem();

      ProjectionRect bb = gcs.getBoundingBox();
      if (projBB == null)
        projBB = bb;
      else
        projBB.add(bb);

      LatLonRect llbb = gcs.getLatLonBoundingBox();
      if (llbbMax == null)
        llbbMax = llbb;
      else
        llbbMax.extend(llbb);

      CalendarDateRange dateRange = gcs.getCalendarDateRange();
      if (dateRange != null) {
        if (dateRangeMax == null)
          dateRangeMax = dateRange;
        else
          dateRangeMax = dateRangeMax.extend(dateRange);
      }
    }
  }
 
Example #8
Source File: CFPointWriterUtils.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static LatLonRect getBoundingBox(List<? extends Station> stnList) {
  Station s = stnList.get(0);
  LatLonPoint llpt = LatLonPoint.create(s.getLatitude(), s.getLongitude());
  LatLonRect rect = new LatLonRect(llpt, 0, 0);

  for (int i = 1; i < stnList.size(); i++) {
    s = stnList.get(i);
    rect.extend(LatLonPoint.create(s.getLatitude(), s.getLongitude()));
  }

  // To give a little "wiggle room", we're going to slightly expand the bounding box.
  double newLowerLeftLat = rect.getLowerLeftPoint().getLatitude() - .0005;
  double newLowerLeftLon = rect.getLowerLeftPoint().getLongitude() - .0005;
  LatLonPoint newLowerLeftPoint = LatLonPoint.create(newLowerLeftLat, newLowerLeftLon);

  double newUpperRightLat = rect.getUpperRightPoint().getLatitude() + .0005;
  double newUpperRightLon = rect.getUpperRightPoint().getLongitude() + .0005;
  LatLonPoint newUpperRightPoint = LatLonPoint.create(newUpperRightLat, newUpperRightLon);

  rect.extend(newLowerLeftPoint);
  rect.extend(newUpperRightPoint);

  return rect;
}
 
Example #9
Source File: MetadataExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example #10
Source File: FeatureDatasetCapabilitiesWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Element writeBoundingBox(LatLonRect bb) {
  int decToKeep = 6;
  double bbExpand = Math.pow(10, -decToKeep);

  // extend the bbox to make sure the implicit rounding does not result in a bbox that does not contain
  // any points (can happen when you have a single station with very precise lat/lon values)
  // See https://github.com/Unidata/thredds/issues/470
  // This accounts for the implicit rounding errors that result from the use of
  // ucar.unidata.util.Format.dfrac when writing out the lat/lon box on the NCSS for Points dataset.html
  // page
  LatLonPoint extendNorthEast = LatLonPoint.create(bb.getLatMax() + bbExpand, bb.getLonMax() + bbExpand);
  LatLonPoint extendSouthWest = LatLonPoint.create(bb.getLatMin() - bbExpand, bb.getLonMin() - bbExpand);
  bb.extend(extendNorthEast);
  bb.extend(extendSouthWest);

  Element bbElem = new Element("LatLonBox"); // from KML

  bbElem.addContent(new Element("west").addContent(ucar.unidata.util.Format.dfrac(bb.getLonMin(), decToKeep)));
  bbElem.addContent(new Element("east").addContent(ucar.unidata.util.Format.dfrac(bb.getLonMax(), decToKeep)));
  bbElem.addContent(new Element("south").addContent(ucar.unidata.util.Format.dfrac(bb.getLatMin(), decToKeep)));
  bbElem.addContent(new Element("north").addContent(ucar.unidata.util.Format.dfrac(bb.getLatMax(), decToKeep)));
  return bbElem;
}
 
Example #11
Source File: PointDatasetRemote.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public PointDatasetRemote(FeatureType wantFeatureType, String uri, CalendarDateUnit timeUnit, String altUnits,
    List<VariableSimpleIF> vars, LatLonRect bb, CalendarDateRange dr) {

  super(wantFeatureType);
  setBoundingBox(bb);
  setDateRange(dr);
  setLocationURI(CdmrFeatureDataset.SCHEME + uri);

  dataVariables = new ArrayList<>(vars);

  collectionList = new ArrayList<>(1);
  switch (wantFeatureType) {
    case POINT:
      collectionList.add(new PointCollectionStreamRemote(uri, timeUnit, altUnits, null));
      break;
    case STATION:
      collectionList.add(new StationCollectionStream(uri, timeUnit, altUnits));
      break;
    default:
      throw new UnsupportedOperationException("No implementation for " + wantFeatureType);
  }
}
 
Example #12
Source File: NcssParamsBean.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public LatLonRect getLatLonBoundingBox() {
  if (!hasLatLonBB()) {
    return null;
  } else {
    double width = getEast() - getWest();
    double height = getNorth() - getSouth();
    return new LatLonRect(LatLonPoint.create(getSouth(), getWest()), height, width);
  }
}
 
Example #13
Source File: SpatialSubsettingTest.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void shouldGetVariablesSubset() throws Exception {

  // gridDataController.getGridSubset(params, validationResult, response);

  this.mockMvc.perform(requestBuilder).andExpect(MockMvcResultMatchers.status().isOk())
      .andExpect(new ResultMatcher() {
        public void match(MvcResult result) throws Exception {
          NetcdfFile nf = NetcdfFile.openInMemory("test_data.ncs", result.getResponse().getContentAsByteArray());
          ucar.nc2.dt.grid.GridDataset gdsDataset = new ucar.nc2.dt.grid.GridDataset(new NetcdfDataset(nf));
          // Open the binary response in memory
          if (TestDir.cdmUseBuilders) {
            nf = NetcdfFiles.openInMemory("test_data.ncs", result.getResponse().getContentAsByteArray());
            gdsDataset = new ucar.nc2.dt.grid.GridDataset(
                NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null));
          } else {
            nf = NetcdfFile.openInMemory("test_data.ncs", result.getResponse().getContentAsByteArray());
            gdsDataset = new ucar.nc2.dt.grid.GridDataset(new NetcdfDataset(nf));
          }
          LatLonRect responseBBox = gdsDataset.getBoundingBox();

          assertTrue(
              responseBBox.intersect((datasetBBOX)) != null && responseBBox.intersect((requestedBBOX)) != null);
          assertTrue(!responseBBox.equals(datasetBBOX));
        }
      });
}
 
Example #14
Source File: FeatureDatasetCapabilitiesWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create an XML document for the stations in this dataset, possible subsetted by bb.
 * Must be a station dataset.
 *
 * @param bb restrict stations to this bounding box, may be null
 * @param names restrict stations to these names, may be null
 * @return XML document for the stations
 */
public Document makeStationCollectionDocument(LatLonRect bb, String[] names) {
  List<DsgFeatureCollection> list = fdp.getPointFeatureCollectionList();
  DsgFeatureCollection fc = list.get(0); // LOOK maybe should pass in the dsg?

  if (!(fc instanceof StationTimeSeriesFeatureCollection)) {
    throw new UnsupportedOperationException(fc.getClass().getName() + " not a StationTimeSeriesFeatureCollection");
  }
  StationTimeSeriesFeatureCollection sobs = (StationTimeSeriesFeatureCollection) fc;

  Element rootElem = new Element("stationCollection");
  Document doc = new Document(rootElem);

  List<StationFeature> stations;
  if (bb != null)
    stations = sobs.getStationFeatures(bb);
  else if (names != null)
    stations = sobs.getStationFeatures(Arrays.asList(names));
  else
    stations = sobs.getStationFeatures();

  for (Station s : stations) {
    Element sElem = new Element("station");
    sElem.setAttribute("name", s.getName());
    if (s.getWmoId() != null)
      sElem.setAttribute("wmo_id", s.getWmoId());
    if ((s.getDescription() != null) && (!s.getDescription().isEmpty()))
      sElem.addContent(new Element("description").addContent(s.getDescription()));

    sElem.addContent(new Element("longitude").addContent(Double.toString(s.getLongitude())));
    sElem.addContent(new Element("latitide").addContent(Double.toString(s.getLatitude())));
    if (!Double.isNaN(s.getAltitude()))
      sElem.addContent(new Element("altitude").addContent(Double.toString(s.getAltitude())));
    rootElem.addContent(sElem);
  }

  return doc;
}
 
Example #15
Source File: TestCoverageCurvilinear.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testNetcdf2D() throws Exception {
  String filename = TestDir.cdmUnitTestDir + "conventions/cf/mississippi.nc";
  logger.debug("open {}", filename);

  try (FeatureDatasetCoverage cc = CoverageDatasetFactory.open(filename)) {
    Assert.assertNotNull(filename, cc);
    CoverageCollection gcs = cc.findCoverageDataset(FeatureType.CURVILINEAR);
    Assert.assertNotNull("gcs", gcs);
    String gribId = "salt";
    Coverage coverage = gcs.findCoverage(gribId);
    Assert.assertNotNull(gribId, coverage);

    CoverageCoordSys cs = coverage.getCoordSys();
    Assert.assertNotNull("coordSys", cs);
    HorizCoordSys hcs = cs.getHorizCoordSys();
    Assert.assertNotNull("HorizCoordSys", hcs);

    int[] expectedOrgShape = new int[] {1, 20, 64, 128};
    Assert.assertArrayEquals(expectedOrgShape, cs.getShape());
    logger.debug("org shape={}", Arrays.toString(cs.getShape()));

    // just try to bisect ot along the width
    LatLonRect bbox = new LatLonRect(LatLonPoint.create(90, -180), LatLonPoint.create(-90, -90));

    SubsetParams params = new SubsetParams().set(SubsetParams.timePresent, true).set(SubsetParams.latlonBB, bbox);
    GeoReferencedArray geo = coverage.readData(params);
    logger.debug("geoCs shape={}", Arrays.toString(geo.getCoordSysForData().getShape()));

    Array data = geo.getData();
    logger.debug("data shape={}", Arrays.toString(data.getShape()));
    Assert.assertArrayEquals(geo.getCoordSysForData().getShape(), data.getShape());

    int[] expectedShape = new int[] {1, 20, 64, 75};
    Assert.assertArrayEquals(expectedShape, data.getShape());
  }
}
 
Example #16
Source File: AbstractStationSubsetWriter.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static List<StationFeature> getStationsInSubset(StationTimeSeriesFeatureCollection stationFeatCol,
    SubsetParams ncssParams) throws IOException {

  List<StationFeature> wantedStations;

  // verify SpatialSelection has some stations
  if (ncssParams.getStations() != null) {
    List<String> stnNames = ncssParams.getStations();

    if (stnNames.get(0).equals("all")) {
      wantedStations = stationFeatCol.getStationFeatures();
    } else {
      wantedStations = stationFeatCol.getStationFeatures(stnNames);
    }
  } else if (ncssParams.getLatLonBoundingBox() != null) {
    LatLonRect llrect = ncssParams.getLatLonBoundingBox();
    wantedStations = stationFeatCol.getStationFeatures(llrect);

  } else if (ncssParams.getLatLonPoint() != null) {
    Station closestStation = findClosestStation(stationFeatCol, ncssParams.getLatLonPoint());
    List<String> stnList = new ArrayList<>();
    stnList.add(closestStation.getName());
    wantedStations = stationFeatCol.getStationFeatures(stnList);

  } else { // Want all.
    wantedStations = stationFeatCol.getStationFeatures();
  }

  return wantedStations;
}
 
Example #17
Source File: AbstractRadialAdapter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void setBoundingBox() {
  LatLonRect largestBB = null;
  // look through all the coord systems
  for (Object o : csHash.values()) {
    RadialCoordSys sys = (RadialCoordSys) o;
    sys.setOrigin(origin);
    LatLonRect bb = sys.getBoundingBox();
    if (largestBB == null)
      largestBB = bb;
    else if (bb != null)
      largestBB.extend(bb);
  }
  boundingBox = largestBB;
}
 
Example #18
Source File: TestMiscPointFeature.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testFlatten() throws IOException { // kunicki
  Formatter formatter = new Formatter(System.err);
  try (FeatureDataset fd = FeatureDatasetFactoryManager.open(FeatureType.STATION,
      TestDir.cdmLocalFromTestDataDir + "pointPre1.6/StandardPointFeatureIteratorIssue.ncml", null, formatter)) {
    if (fd != null && fd instanceof FeatureDatasetPoint) {
      FeatureDatasetPoint fdp = (FeatureDatasetPoint) fd;
      DsgFeatureCollection fc = fdp.getPointFeatureCollectionList().get(0);
      if (fc != null && fc instanceof StationTimeSeriesFeatureCollection) {
        StationTimeSeriesFeatureCollection stsfc = (StationTimeSeriesFeatureCollection) fc;
        // subset criteria not important, just want to get data
        // into flattened representation
        PointFeatureCollection pfc =
            stsfc.flatten(new LatLonRect(LatLonPoint.create(-90, -180), LatLonPoint.create(90, 180)),
                CalendarDateRange.of(CalendarDate.parseISOformat(null, "1900-01-01"),
                    CalendarDate.parseISOformat(null, "2100-01-01")));

        for (PointFeature pf : pfc) {
          // the call to cursor.getParentStructure() in
          // in StandardPointFeatureIterator.makeStation()
          // is returning the observation structure, not the
          // station structure since Cursor.currentIndex = 0
          // Station s = stsfc.getStation(pf);
          StructureData sdata = pf.getFeatureData();
          Assert.assertNotNull(sdata);

          StationFeature stnFeat = stsfc.getStationFeature(pf);
          Assert.assertNotNull(stnFeat);
          StructureData stnData = stnFeat.getFeatureData();
          Assert.assertNotEquals(sdata, stnData);
        }
      }
    }
  }
}
 
Example #19
Source File: TestGeoTiffWriter2.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> getTestParameters() {
  List<Object[]> result = new ArrayList<>();

  result.add(new Object[] {topdir + "formats/dmsp/F14200307192230.n.OIS", "infraredImagery",
      new LatLonRect(LatLonPoint.create(-5, -52.0), LatLonPoint.create(25, -20.0))});

  // this fails
  // result.add(new Object[]{topdir + "formats/netcdf4/ncom_relo_fukushima_1km_tmp_2011040800_t000.nc4",
  // "surf_salt_flux", new LatLonRect(LatLonPoint.create(43, 141), 5, 5)});

  return result;
}
 
Example #20
Source File: StationCollectionStream.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@Nullable
public PointFeatureCollection subset(LatLonRect boundingBox, CalendarDateRange dateRange) {
  if (boundingBox != null) {
    if (!boundingBox.contains(s.getLatLon()))
      return null;
    if (dateRange == null)
      return this;
  }
  return subset(dateRange);
}
 
Example #21
Source File: PointFeatureDatasetViewer.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setDataset(FeatureDatasetPoint dataset) {
  this.pfDataset = dataset;

  clear();

  // set the feature collection table - all use this
  List<FeatureCollectionBean> fcBeans = new ArrayList<>();
  for (DsgFeatureCollection fc : dataset.getPointFeatureCollectionList()) {
    fcBeans.add(new FeatureCollectionBean(fc));
  }
  if (fcBeans.isEmpty()) {
    JOptionPane.showMessageDialog(null, "No PointFeatureCollections found that could be displayed");
  }

  fcTable.setBeans(fcBeans);
  infoTA.clear();

  // set the date range if possible
  CalendarDateRange dr = dataset.getCalendarDateRange();
  if (dr != null) {
    stationMap.setDateRange(dr.toDateRange());
  }

  // set the bounding box if possible
  LatLonRect bb = dataset.getBoundingBox();
  if (bb != null) {
    stationMap.setGeoBounds(bb);
  }
}
 
Example #22
Source File: CFGridWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public long makeFile(String location, ucar.nc2.dt.GridDataset gds, List<String> gridList, LatLonRect llbb,
    int horizStride, Range zRange, CalendarDateRange dateRange, int stride_time, boolean addLatLon,
    NetcdfFileWriter.Version version) throws IOException, InvalidRangeException {

  return makeOrTestSize(location, gds, gridList, llbb, horizStride, zRange, dateRange, stride_time, addLatLon, false,
      version);
}
 
Example #23
Source File: DsgSubsetWriterTest.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void setupClass() throws URISyntaxException {
  // The WaterML marshaller usually initializes wml2:generationDate and om:resultTime to "now". This is a problem,
  // because those values will always differ from the fixed values we have in our expectedResultResource files.
  // So, to facilitate testing, we're going to fix the values that the marshaller emits.
  MarshallingUtil.fixedGenerationDate = CalendarDate.of(Calendar.gregorian, 1970, 1, 1, 0, 0, 0);
  MarshallingUtil.fixedResultTime = CalendarDate.of(Calendar.gregorian, 1970, 1, 1, 0, 0, 0);

  ncssDiskCache = new NcssDiskCache(DiskCache2.getDefault().getRootDirectory());

  subsetParamsAll = new SubsetParams();
  subsetParamsAll.setVariables(Arrays.asList("pr", "tas"));

  subsetParamsPoint = new SubsetParams();
  subsetParamsPoint.setVariables(Arrays.asList("pr"));
  subsetParamsPoint.setTime(CalendarDate.parseISOformat(null, "1970-01-01 02:00:00Z"));
  // Full extension is (40.0, -100.0) to (68.0, -58.0).
  LatLonRect bbox = new LatLonRect(LatLonPoint.create(40.0, -100.0), LatLonPoint.create(53.0, -58.0));
  subsetParamsPoint.setLatLonBoundingBox(bbox);

  subsetParamsStation1 = new SubsetParams();
  subsetParamsStation1.setVariables(Arrays.asList("tas"));
  CalendarDate start = CalendarDate.parseISOformat(null, "1970-01-05T00:00:00Z");
  CalendarDate end = CalendarDate.parseISOformat(null, "1970-02-05T00:00:00Z");
  subsetParamsStation1.setTimeRange(CalendarDateRange.of(start, end));
  subsetParamsStation1.setStations(Arrays.asList("AAA", "CCC"));

  subsetParamsStation2 = new SubsetParams();
  subsetParamsStation2.setVariables(Arrays.asList("pr", "tas"));
  // The nearest will be "1970-01-21 00:00:00Z"
  subsetParamsStation2.setTime(CalendarDate.parseISOformat(null, "1970-01-21 01:00:00Z"));
}
 
Example #24
Source File: CompositePointCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@Nonnull
public PointFeatureCollection subset(LatLonRect boundingBox, CalendarDateRange dateRange) {
  if ((dateRange == null) && (boundingBox == null))
    return this;
  else if (dateRange == null)
    return new PointCollectionSubset(this, boundingBox, null);
  else {
    CompositePointCollection dateSubset =
        new CompositePointCollection(name, getTimeUnit(), getAltUnits(), pointCollections.subset(dateRange));
    return new PointCollectionSubset(dateSubset, boundingBox, dateRange);
  }
}
 
Example #25
Source File: WcsRequest.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Element genLonLatEnvelope(CoverageCollection gcd, CoverageCoordSys gcs) {
  // <CoverageOfferingBrief>/lonLatEnvelope
  Element lonLatEnvelopeElem = new Element("lonLatEnvelope", wcsNS);
  lonLatEnvelopeElem.setAttribute("srsName", "urn:ogc:def:crs:OGC:1.3:CRS84");

  LatLonRect llbb = gcd.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 - Add vertical (Deal with conversion to meters. Yikes!!)
  // CoordinateAxis1D vertAxis = gcs.getVerticalAxis();
  // if ( vertAxis != null )
  // {
  // // See verAxis.getUnitsString()
  // firstPosition += " " + vertAxis.getCoordValue( 0);
  // secondPostion += " " + vertAxis.getCoordValue( ((int)vertAxis.getSize()) - 1);
  // }

  lonLatEnvelopeElem.addContent(new Element("pos", gmlNS).addContent(firstPosition));
  lonLatEnvelopeElem.addContent(new Element("pos", gmlNS).addContent(secondPosition));

  // <CoverageOfferingBrief>/lonLatEnvelope/gml:timePostion [2]

  CoverageCoordAxis timeCoord = gcs.getTimeAxis();
  if (timeCoord != null) {
    CalendarDateRange dr = timeCoord.getDateRange();
    if (dr != null) {
      lonLatEnvelopeElem.addContent(new Element("timePosition", gmlNS).addContent(dr.getStart().toString()));
      lonLatEnvelopeElem.addContent(new Element("timePosition", gmlNS).addContent(dr.getEnd().toString()));
    }
  }

  return lonLatEnvelopeElem;
}
 
Example #26
Source File: BufrFeatureDatasetFactory.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
BufrPointFeatureCollection(LatLonRect boundingBox, CalendarDateRange dateRange) throws IOException {
  super("BufrPointFeatureCollection", bufrDateUnits, bufrAltUnits);
  setBoundingBox(boundingBox);
  if (dateRange != null) {
    getInfo();
    info.setCalendarDateRange(dateRange);
  }
  createStationHelper();
  stationsWanted = getStationHelper().subset(boundingBox);
  if (dateRange != null)
    filter = new PointIteratorFiltered.SpaceAndTimeFilter(null, dateRange);
}
 
Example #27
Source File: MetadataExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static ThreddsMetadata.GeospatialCoverage extractGeospatial(FeatureDatasetPoint fd) {
  LatLonRect llbb = fd.getBoundingBox();
  if (llbb != null) {
    ThreddsMetadata.GeospatialCoverage gc = new ThreddsMetadata.GeospatialCoverage();
    gc.setBoundingBox(llbb);
    return gc;
  }
  return null;
}
 
Example #28
Source File: InvDatasetFcGrib.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ThreddsMetadata.GeospatialCoverage extractGeospatial(GribCollectionImmutable.GroupGC group) {
  GdsHorizCoordSys gdsCoordSys = group.getGdsHorizCoordSys();
  LatLonRect llbb = GridCoordSys.getLatLonBoundingBox(gdsCoordSys.proj, gdsCoordSys.getStartX(),
      gdsCoordSys.getStartY(), gdsCoordSys.getEndX(), gdsCoordSys.getEndY());


  double dx = 0.0, dy = 0.0;
  if (gdsCoordSys.isLatLon()) {
    dx = Math.abs(gdsCoordSys.dx);
    dy = Math.abs(gdsCoordSys.dy);
  }

  return new ThreddsMetadata.GeospatialCoverage(llbb, null, dx, dy);
}
 
Example #29
Source File: FeatureDatasetImpl.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void getDetailInfo(java.util.Formatter sf) {
  sf.format("FeatureDataset on location= %s%n", getLocation());
  sf.format("  featureType= %s%n", getFeatureType());
  sf.format("  title= %s%n", getTitle());
  sf.format("  desc= %s%n", getDescription());
  sf.format("  range= %s%n", getCalendarDateRange());
  sf.format("  start= %s%n", getCalendarDateEnd());
  sf.format("  end  = %s%n", getCalendarDateEnd());
  LatLonRect bb = getBoundingBox();
  sf.format("  bb   = %s%n", bb);
  if (bb != null)
    sf.format("  bb   = %s%n", getBoundingBox().toString2());

  sf.format("  has netcdf = %b%n", (getNetcdfFile() != null));
  if (!attributes().isEmpty()) {
    sf.format("  Attributes%n");
    for (Attribute a : attributes())
      sf.format("    %s%n", a);
  }

  List<VariableSimpleIF> vars = getDataVariables();
  sf.format("%n  Data Variables (%d)%n", vars.size());
  for (VariableSimpleIF v : vars) {
    sf.format("    name='%s' desc='%s' units=%s' type='%s' dims=(", v.getShortName(), v.getDescription(),
        v.getUnitsString(), v.getDataType());
    for (Dimension d : v.getDimensions())
      sf.format("%s ", d);
    sf.format(")%n");
  }

  if (!parseInfo.toString().isEmpty())
    sf.format("%nparseInfo=%n%s%n", parseInfo);
}
 
Example #30
Source File: CoverageCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Ctor
 * 
 * @param name CoverageCollection name
 * @param coverageType CoverageCollection type
 * @param atts CoverageCollection attributes
 * @param latLonBoundingBox if null, calculate
 * @param projBoundingBox if null, calculate
 * @param calendarDateRange need this to get the Calendar
 * @param coordSys list of coordinate systems
 * @param coordTransforms list of coordinate transforms
 * @param coordAxes list of coordinate axes
 * @param coverages list of coverages
 * @param reader delegate for reading
 */
public CoverageCollection(String name, FeatureType coverageType, AttributeContainer atts,
    LatLonRect latLonBoundingBox, ProjectionRect projBoundingBox, CalendarDateRange calendarDateRange,
    List<CoverageCoordSys> coordSys, List<CoverageTransform> coordTransforms, List<CoverageCoordAxis> coordAxes,
    List<Coverage> coverages, CoverageReader reader) {
  this.name = name;
  this.atts = atts;
  this.calendarDateRange = calendarDateRange;
  this.coverageType = coverageType;

  this.coordSys = coordSys;
  this.coordTransforms = coordTransforms;
  this.coordAxes = coordAxes;

  this.coverageSets = wireObjectsTogether(coverages);
  this.hcs = wireHorizCoordSys();
  this.reader = reader;

  if (hcs.isProjection()) {
    if (projBoundingBox != null)
      this.projBoundingBox = projBoundingBox;
    else
      this.projBoundingBox = hcs.calcProjectionBoundingBox();
  } else {
    this.projBoundingBox = null;
  }

  if (latLonBoundingBox != null)
    this.latLonBoundingBox = latLonBoundingBox;
  else
    this.latLonBoundingBox = hcs.calcLatLonBoundingBox();
}