Java Code Examples for ucar.unidata.geoloc.LatLonRect#extend()

The following examples show how to use ucar.unidata.geoloc.LatLonRect#extend() . 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: 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 2
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 3
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 4
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 5
Source File: WriterProfileObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private LatLonRect getBoundingBox(List stnList) {
  ucar.unidata.geoloc.Station s = (ucar.unidata.geoloc.Station) stnList.get(0);
  LatLonPointImpl llpt = new LatLonPointImpl();
  llpt.set(s.getLatitude(), s.getLongitude());
  LatLonRect rect = new LatLonRect(llpt, .001, .001);

  for (int i = 1; i < stnList.size(); i++) {
    s = (ucar.unidata.geoloc.Station) stnList.get(i);
    llpt.set(s.getLatitude(), s.getLongitude());
    rect.extend(llpt);
  }

  return rect;
}
 
Example 6
Source File: WriterStationObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private LatLonRect getBoundingBox(List stnList) {
  ucar.unidata.geoloc.Station s = (ucar.unidata.geoloc.Station) stnList.get(0);
  LatLonPointImpl llpt = new LatLonPointImpl();
  llpt.set(s.getLatitude(), s.getLongitude());
  LatLonRect rect = new LatLonRect(llpt, .001, .001);

  for (int i = 1; i < stnList.size(); i++) {
    s = (ucar.unidata.geoloc.Station) stnList.get(i);
    llpt.set(s.getLatitude(), s.getLongitude());
    rect.extend(llpt);
  }

  return rect;
}
 
Example 7
Source File: WriterCFStationObsDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private LatLonRect getBoundingBox(List stnList) {
  ucar.unidata.geoloc.Station s = (ucar.unidata.geoloc.Station) stnList.get(0);
  LatLonPointImpl llpt = new LatLonPointImpl();
  llpt.set(s.getLatitude(), s.getLongitude());
  LatLonRect rect = new LatLonRect(llpt, .001, .001);

  for (int i = 1; i < stnList.size(); i++) {
    s = (ucar.unidata.geoloc.Station) stnList.get(i);
    llpt.set(s.getLatitude(), s.getLongitude());
    rect.extend(llpt);
  }

  return rect;
}
 
Example 8
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;
}