private void testAllMethods(String location) throws IOException {
    // RadialDatasetSweep rds = datasetFactory.open( location, null);
    RadialDatasetSweep rds =
        (RadialDatasetSweep)
            TypedDatasetFactory.open(FeatureType.RADIAL, location, null, new StringBuilder());

    System.out.println(location + "-----------");
    if (show) System.out.println(rds.getDetailInfo());

    Date d1 = rds.getStartDate();
    Date d2 = rds.getEndDate();
    if ((d1 != null) && (d2 != null)) assert d1.before(d2) || d1.equals(d2);

    ucar.unidata.geoloc.EarthLocation eloc = rds.getCommonOrigin();
    assert eloc != null;
    LatLonPoint llp = new LatLonPointImpl(eloc.getLatitude(), eloc.getLongitude());

    LatLonRect bb = rds.getBoundingBox();
    assert bb.contains(llp);

    List rvars = rds.getDataVariables();
    assert null != rvars;
    assert 0 < rvars.size();
    for (int i = 0; i < rvars.size(); i++) {
      RadialDatasetSweep.RadialVariable rv = (RadialDatasetSweep.RadialVariable) rvars.get(i);
      testRadialVariable(rv);
    }
  }
  /**
   * 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;
  }
示例#3
0
 private void addLatLonParameters(Element parent, LatLonRect bbox) {
   // lat
   Element lat = getDocument().createElement("ows:Parameter");
   lat.setAttribute("name", "lat");
   lat.setAttribute("use", "required");
   Element latAllowedValues = getDocument().createElement("ows:AllowedValues");
   // min
   Element latMin = getDocument().createElement("ows:MinimumValue");
   latMin.setTextContent(bbox.getLowerLeftPoint().getLatitude() + "");
   latAllowedValues.appendChild(latMin);
   // max
   Element latMax = getDocument().createElement("ows:MaximumValue");
   latMax.setTextContent(bbox.getUpperRightPoint().getLatitude() + "");
   latAllowedValues.appendChild(latMax);
   lat.appendChild(latAllowedValues);
   parent.appendChild(lat);
   // lon
   Element lon = getDocument().createElement("ows:Parameter");
   lon.setAttribute("name", "lon");
   lon.setAttribute("use", "required");
   Element lonAllowedValues = getDocument().createElement("ows:AllowedValues");
   // min
   Element lonMin = getDocument().createElement("ows:MinimumValue");
   lonMin.setTextContent(bbox.getLowerLeftPoint().getLongitude() + "");
   lonAllowedValues.appendChild(lonMin);
   // max
   Element lonMax = getDocument().createElement("ows:MaximumValue");
   lonMax.setTextContent(bbox.getUpperRightPoint().getLongitude() + "");
   lonAllowedValues.appendChild(lonMax);
   lon.appendChild(lonAllowedValues);
   parent.appendChild(lon);
 }
  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;
  }
  private static void makeSelectBB(StringBuffer sbuff, LatLonRect bb) {
    // LAT min max;LON min max
    // For ADDE URL's, lon is positive east, on the server, lon is positive west.
    // AddeURLConnection handles the conversion.
    // Format for lat/lon is either decimal degrees or DD:MM:SS

    LatLonPoint ll = bb.getLowerLeftPoint();
    LatLonPoint ur = bb.getUpperRightPoint();
    sbuff.append("LAT ");
    sbuff.append(ll.getLatitude());
    sbuff.append(" ");
    sbuff.append(ur.getLatitude());
    sbuff.append(";LON ");
    sbuff.append(ll.getLongitude());
    sbuff.append(" ");
    sbuff.append(ur.getLongitude());
  }
 @Override
 public PointFeatureCollection subset(LatLonRect boundingBox, CalendarDateRange dateRange)
     throws IOException {
   if (boundingBox != null) {
     if (!boundingBox.contains(s.getLatLon())) return null;
     if (dateRange == null) return this;
   }
   return subset(dateRange);
 }
  private boolean filter(PointFeature pdata) {
    if ((filter_date != null) && !filter_date.included(pdata.getObservationTimeAsDate()))
      return false;

    if ((filter_bb != null)
        && !filter_bb.contains(
            pdata.getLocation().getLatitude(), pdata.getLocation().getLongitude())) return false;

    return true;
  }
示例#8
0
  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;
  }
示例#9
0
  private Element getStationBounds(LatLonRect rect) {
    Element retval = getDocument().createElement("gml:boundedBy");

    if (rect != null) {
      Element envelope = getDocument().createElement("gml:Envelope");
      envelope.setAttribute("srsName", "http://www.opengis.net/def/crs/EPSG/0/4326");
      // lower corner
      Element lowercorner = getDocument().createElement("gml:lowerCorner");
      lowercorner.setTextContent(
          rect.getLowerLeftPoint().getLatitude() + " " + rect.getLowerLeftPoint().getLongitude());
      envelope.appendChild(lowercorner);
      // upper corner
      Element uppercorner = getDocument().createElement("gml:upperCorner");
      uppercorner.setTextContent(
          rect.getUpperRightPoint().getLatitude() + " " + rect.getUpperRightPoint().getLongitude());
      envelope.appendChild(uppercorner);
      retval.appendChild(envelope);
    }

    return retval;
  }
示例#10
0
  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 - 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]
    if (gcs.hasTimeAxis()) {
      DateRange dr = gcs.getDateRange();
      if (dr != null) {
        lonLatEnvelopeElem.addContent(
            new Element("timePosition", gmlNS).addContent(dr.getStart().toDateTimeStringISO()));
        lonLatEnvelopeElem.addContent(
            new Element("timePosition", gmlNS).addContent(dr.getEnd().toDateTimeStringISO()));
      }
    }

    return lonLatEnvelopeElem;
  }
  /**
   * get all radar station within box.
   *
   * @param boundingBox _more_
   * @param cancel _more_
   * @return List of type DqcRadarStation objects
   * @throws IOException java io exception
   */
  public List getStations(
      ucar.unidata.geoloc.LatLonRect boundingBox, ucar.nc2.util.CancelTask cancel)
      throws IOException {
    List sl = selStation.getStations();
    ArrayList dsl = new ArrayList();

    for (Iterator it = sl.iterator(); it.hasNext(); ) {
      Station s = (Station) it.next();
      LatLonPointImpl latlonPt = new LatLonPointImpl();
      latlonPt.set(s.getLocation().getLatitude(), s.getLocation().getLongitude());
      if (boundingBox.contains(latlonPt)) {
        dsl.add(s);
      }
      if ((cancel != null) && cancel.isCancel()) {
        return null;
      }
    }

    return dsl;
  }
  private void createStations(List<ucar.unidata.geoloc.Station> stnList) throws IOException {
    int nstns = stnList.size();

    // see if there's altitude, wmoId for any stations
    for (int i = 0; i < nstns; i++) {
      ucar.unidata.geoloc.Station stn = stnList.get(i);

      // if (!Double.isNaN(stn.getAltitude()))
      //  useAlt = true;
      if ((stn.getWmoId() != null) && (stn.getWmoId().trim().length() > 0)) useWmoId = true;
    }

    /* if (useAlt)
    ncfile.addGlobalAttribute("altitude_coordinate", altName); */

    // find string lengths
    for (int i = 0; i < nstns; i++) {
      ucar.unidata.geoloc.Station station = stnList.get(i);
      name_strlen = Math.max(name_strlen, station.getName().length());
      desc_strlen = Math.max(desc_strlen, station.getDescription().length());
      if (useWmoId) wmo_strlen = Math.max(wmo_strlen, station.getName().length());
    }

    LatLonRect llbb = getBoundingBox(stnList);
    ncfile.addGlobalAttribute(
        "geospatial_lat_min", Double.toString(llbb.getLowerLeftPoint().getLatitude()));
    ncfile.addGlobalAttribute(
        "geospatial_lat_max", Double.toString(llbb.getUpperRightPoint().getLatitude()));
    ncfile.addGlobalAttribute(
        "geospatial_lon_min", Double.toString(llbb.getLowerLeftPoint().getLongitude()));
    ncfile.addGlobalAttribute(
        "geospatial_lon_max", Double.toString(llbb.getUpperRightPoint().getLongitude()));

    // add the dimensions
    Dimension recordDim = ncfile.addUnlimitedDimension(recordDimName);
    recordDims.add(recordDim);

    Dimension stationDim = ncfile.addDimension(stationDimName, nstns);
    stationDims.add(stationDim);

    // add the station Variables using the station dimension
    Variable v = ncfile.addVariable(latName, DataType.DOUBLE, stationDimName);
    ncfile.addVariableAttribute(v, new Attribute("units", "degrees_north"));
    ncfile.addVariableAttribute(v, new Attribute("long_name", "station latitude"));

    v = ncfile.addVariable(lonName, DataType.DOUBLE, stationDimName);
    ncfile.addVariableAttribute(v, new Attribute("units", "degrees_east"));
    ncfile.addVariableAttribute(v, new Attribute("long_name", "station longitude"));

    if (useAlt) {
      v = ncfile.addVariable(altName, DataType.DOUBLE, stationDimName);
      ncfile.addVariableAttribute(v, new Attribute("units", "meters"));
      ncfile.addVariableAttribute(v, new Attribute("long_name", "station altitude"));
    }

    v = ncfile.addStringVariable(idName, stationDims, name_strlen);
    ncfile.addVariableAttribute(v, new Attribute("long_name", "station identifier"));

    v = ncfile.addStringVariable(descName, stationDims, desc_strlen);
    ncfile.addVariableAttribute(v, new Attribute("long_name", "station description"));

    if (useWmoId) {
      v = ncfile.addStringVariable(wmoName, stationDims, wmo_strlen);
      ncfile.addVariableAttribute(v, new Attribute("long_name", "station WMO id"));
    }

    v = ncfile.addVariable(numProfilesName, DataType.INT, stationDimName);
    ncfile.addVariableAttribute(
        v, new Attribute("long_name", "number of profiles in linked list for this station"));

    v = ncfile.addVariable(firstProfileName, DataType.INT, stationDimName);
    ncfile.addVariableAttribute(
        v, new Attribute("long_name", "index of first profile in linked list for this station"));
  }
  @Test
  public void bugReport() throws IOException {

    try (GridDataset dataset =
        GridDataset.open(
            "http://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3_0_run1_200001.nc")) {

      GridDatatype firstGridInfo = dataset.getGrids().get(0);
      System.out.println("Grid name =" + firstGridInfo.getName());
      GeoGrid firstGrid = (GeoGrid) dataset.getGrids().get(0);

      System.out.println("WHOLE GRID");
      GridCoordSystem gcs = firstGrid.getCoordinateSystem();
      System.out.println("is lat/lon system ? " + gcs.isLatLon());
      assert gcs.isLatLon();

      LatLonRect rect = gcs.getLatLonBoundingBox();
      System.out.println(
          "gcs bounding box : latmin="
              + rect.getLatMin()
              + " latmax="
              + rect.getLatMax()
              + " lonmin="
              + rect.getLonMin()
              + " lonmax="
              + rect.getLonMax());
      System.out.println("projection       : " + gcs.getProjection());
      System.out.println(
          "width =" + gcs.getXHorizAxis().getSize() + ", height=" + gcs.getYHorizAxis().getSize());
      System.out.println(
          "X is regular     ? " + ((CoordinateAxis1D) gcs.getXHorizAxis()).isRegular());
      System.out.println("X is contiguous  ? " + gcs.getXHorizAxis().isContiguous());
      System.out.println(
          "X start          : " + ((CoordinateAxis1D) gcs.getXHorizAxis()).getStart());
      System.out.println(
          "X increment      : " + ((CoordinateAxis1D) gcs.getXHorizAxis()).getIncrement());
      System.out.println(
          "Y is regular     ? " + ((CoordinateAxis1D) gcs.getYHorizAxis()).isRegular());
      System.out.println("Y is contiguous  ? " + gcs.getYHorizAxis().isContiguous());
      System.out.println(
          "Y start          : " + ((CoordinateAxis1D) gcs.getYHorizAxis()).getStart());
      System.out.println(
          "Y increment      : " + ((CoordinateAxis1D) gcs.getYHorizAxis()).getIncrement());

      LatLonPoint p = gcs.getLatLon(0, 0);
      System.out.println("index (0,0) --> lat/lon : " + p.getLatitude() + " ; " + p.getLongitude());
      p = gcs.getLatLon(1, 1);
      System.out.println("index (1,1) --> lat/lon : " + p.getLatitude() + " ; " + p.getLongitude());

      System.out.println("looking up lat=" + p.getLatitude() + "  lon=" + p.getLongitude());
      int[] xy = gcs.findXYindexFromLatLon(p.getLatitude(), p.getLongitude(), null);
      System.out.println("index= (" + xy[0] + ", " + xy[1] + ")");
      Assert.assertEquals(xy[0], 1);
      Assert.assertEquals(xy[1], 1);

      // --------------------------------------------------------------------------
      double latMin = -20.D, latMax = -10.D, lonMin = 35.D, lonMax = 45.D;
      System.out.println(
          "\nSUBGRID (latmin="
              + latMin
              + "  latmax="
              + latMax
              + "  lonmin="
              + lonMin
              + "  lonmax="
              + lonMax
              + ")");

      LatLonRect latLonRect =
          new LatLonRect(new LatLonPointImpl(latMin, lonMin), new LatLonPointImpl(latMax, lonMax));

      GeoGrid gridSubset = firstGrid.subset(null, null, latLonRect, 0, 1, 1);

      GridCoordSystem gcs2 = gridSubset.getCoordinateSystem();

      rect = gcs2.getLatLonBoundingBox();
      System.out.println("is lat/lon system ? " + gcs2.isLatLon());
      System.out.println(
          "gcs bounding box : latmin="
              + rect.getLatMin()
              + " latmax="
              + rect.getLatMax()
              + " lonmin="
              + rect.getLonMin()
              + " lonmax="
              + rect.getLonMax());
      System.out.println("projection       : " + gcs.getProjection());
      System.out.println(
          "width ="
              + gcs2.getXHorizAxis().getSize()
              + ", height="
              + gcs2.getYHorizAxis().getSize());
      System.out.println(
          "X is regular     ? " + ((CoordinateAxis1D) gcs2.getXHorizAxis()).isRegular());
      System.out.println("X is contiguous  ? " + gcs2.getXHorizAxis().isContiguous());
      System.out.println(
          "X start          : " + ((CoordinateAxis1D) gcs2.getXHorizAxis()).getStart());
      System.out.println(
          "X increment      : " + ((CoordinateAxis1D) gcs2.getXHorizAxis()).getIncrement());
      System.out.println(
          "Y is regular     ? " + ((CoordinateAxis1D) gcs2.getYHorizAxis()).isRegular());
      System.out.println("Y is contiguous  ? " + gcs2.getYHorizAxis().isContiguous());
      System.out.println(
          "Y start          : " + ((CoordinateAxis1D) gcs2.getYHorizAxis()).getStart());
      System.out.println(
          "Y increment      : " + ((CoordinateAxis1D) gcs2.getYHorizAxis()).getIncrement());

      p = gcs2.getLatLon(0, 0);
      System.out.println("index (0,0) --> lat/lon : " + p.getLatitude() + " ; " + p.getLongitude());
      p = gcs2.getLatLon(1, 1);
      System.out.println("index (1,1) --> lat/lon : " + p.getLatitude() + " ; " + p.getLongitude());

      System.out.println("looking up lat=" + p.getLatitude() + "  lon=" + p.getLongitude());
      xy = gcs2.findXYindexFromLatLon(p.getLatitude(), p.getLongitude(), null);
      System.out.println("index= (" + xy[0] + ", " + xy[1] + ")");
      Assert.assertEquals(xy[0], 1);
      Assert.assertEquals(xy[1], 1);

    } catch (IOException | InvalidRangeException e) {
      e.printStackTrace();
    }
  }