/** * Determine if this bounding box is contained in another LatLonRect. * * @param b the other box to see if it contains this one * @return true if b contained in this bounding box */ public boolean containedIn(LatLonRect b) { return (b.getWidth() >= width) && b.contains(upperRight) && b.contains(lowerLeft); }
/** * Determine if this bounding box is contained in another LatLonRect. * * @param b the other box to see if it contains this one * @return true if b contained in this bounding box */ public boolean containedIn(LatLonRect b) { return (b.getWidth() >= width) && b.contains(upperRight) && b.contains(lowerLeft); }
/** * Determine if this bounding box is contained in another LatLonRect. * * @param b the other box to see if it contains this one * @return true if b contained in this bounding box */ public boolean containedIn(LatLonRect b) { return (b.getWidth() >= width) && b.contains(upperRight) && b.contains(lowerLeft); }
/** * Determine if this bounding box is contained in another LatLonRect. * * @param b the other box to see if it contains this one * @return true if b contained in this bounding box */ public boolean containedIn(LatLonRect b) { return (b.getWidth() >= width) && b.contains(upperRight) && b.contains(lowerLeft); }
public void setBoundingBox(LatLonRect bb) { LatLonPointImpl llpt = bb.getLowerLeftPoint(); LatLonPointImpl urpt = bb.getUpperRightPoint(); double height = urpt.getLatitude() - llpt.getLatitude(); this.eastwest = new Range(llpt.getLongitude(), bb.getWidth(), 0.0, CDM.LON_UNITS); this.northsouth = new Range(llpt.getLatitude(), height, 0.0, CDM.LAT_UNITS); if ((bb.getWidth() > 358) && (height > 178)) setGlobal(true); // LOOK ?? }
public void setBoundingBox(LatLonRect bb) { LatLonPointImpl llpt = bb.getLowerLeftPoint(); LatLonPointImpl urpt = bb.getUpperRightPoint(); double height = urpt.getLatitude() - llpt.getLatitude(); this.eastwest = new Range(llpt.getLongitude(), bb.getWidth(), 0.0, CDM.LON_UNITS); this.northsouth = new Range(llpt.getLatitude(), height, 0.0, CDM.LAT_UNITS); if ((bb.getWidth() > 358) && (height > 178)) setGlobal(true); // LOOK ?? }
public void setBoundingBox(LatLonRect bb) { LatLonPointImpl llpt = bb.getLowerLeftPoint(); LatLonPointImpl urpt = bb.getUpperRightPoint(); double height = urpt.getLatitude() - llpt.getLatitude(); this.eastwest = new Range(llpt.getLongitude(), bb.getWidth(), 0.0, CDM.LON_UNITS); this.northsouth = new Range(llpt.getLatitude(), height, 0.0, CDM.LAT_UNITS); if ((bb.getWidth() > 358) && (height > 178)) setGlobal(true); // LOOK ?? }
/** * Copy Constructor * * @param r rectangle to copy */ public LatLonRect(LatLonRect r) { this(r.getLowerLeftPoint(), r.getUpperRightPoint().getLatitude() - r.getLowerLeftPoint().getLatitude(), r.getWidth()); }
/** * Copy Constructor * * @param r rectangle to copy */ public LatLonRect(LatLonRect r) { this(r.getLowerLeftPoint(), r.getUpperRightPoint().getLatitude() - r.getLowerLeftPoint().getLatitude(), r.getWidth()); }
/** * Copy Constructor * * @param r rectangle to copy */ public LatLonRect(LatLonRect r) { this(r.getLowerLeftPoint(), r.getUpperRightPoint().getLatitude() - r.getLowerLeftPoint().getLatitude(), r.getWidth()); }
/** * Copy Constructor * * @param r rectangle to copy */ public LatLonRect(LatLonRect r) { this(r.getLowerLeftPoint(), r.getUpperRightPoint().getLatitude() - r.getLowerLeftPoint().getLatitude(), r.getWidth()); }
protected void finishCalcBounds() { if (!calcBounds) return; if ((bb != null) && bb.crossDateline() && (bb.getWidth() > 350.0)) { // call it global - less confusing double lat_min = bb.getLowerLeftPoint().getLatitude(); double deltaLat = bb.getUpperLeftPoint().getLatitude() - lat_min; bb = new LatLonRect(new LatLonPointImpl(lat_min, -180.0), deltaLat, 360.0); } info.bbox = bb; info.minTime = minTime; info.maxTime = maxTime; info.nobs = count; info.nfeatures = count; info.setComplete(); }
CdmrFeatureProto.Rectangle.Builder encodeRectangle(LatLonRect rect) { CdmrFeatureProto.Rectangle.Builder builder = CdmrFeatureProto.Rectangle.newBuilder(); // this(r.getLowerLeftPoint(), r.getUpperRightPoint().getLatitude() - r.getLowerLeftPoint().getLatitude(), r.getWidth()); LatLonPoint ll = rect.getLowerLeftPoint(); LatLonPoint ur = rect.getUpperRightPoint(); builder.setStartx(ll.getLongitude()); builder.setStarty(ll.getLatitude()); builder.setIncx(rect.getWidth()); builder.setIncy(ur.getLatitude() - ll.getLatitude()); return builder; }
private void checkLatLonSubset(CoverageCollection gcs, Coverage coverage, LatLonRect bbox, int[] expectedShape) throws Exception { System.out.printf(" coverage llbb = %s width=%f%n", gcs.getLatlonBoundingBox().toString2(), gcs.getLatlonBoundingBox().getWidth()); System.out.printf(" constrain bbox= %s width=%f%n", bbox.toString2(), bbox.getWidth()); SubsetParams params = new SubsetParams().setLatLonBoundingBox(bbox).setTimePresent(); GeoReferencedArray geo = coverage.readData(params); CoverageCoordSys gcs2 = geo.getCoordSysForData(); Assert.assertNotNull("CoordSysForData", gcs2); System.out.printf(" data cs shape=%s%n", Misc.showInts(gcs2.getShape())); System.out.printf(" data shape=%s%n", Misc.showInts(geo.getData().getShape())); Assert.assertArrayEquals("CoordSys=Data shape", gcs2.getShape(), geo.getData().getShape()); Assert.assertArrayEquals("expected data shape", expectedShape, geo.getData().getShape()); }
/** * Split a latlon rectangle to the equivalent ProjectionRect * using this LatLonProjection to split it at the seam if needed. * * @param latlonR the latlon rectangle to transform * @return 1 or 2 ProjectionRect. If it doesnt cross the seam, * the second rectangle is null. */ public ProjectionRect[] latLonToProjRect(LatLonRect latlonR) { double lat0 = latlonR.getLowerLeftPoint().getLatitude(); double height = Math.abs(latlonR.getUpperRightPoint().getLatitude() - lat0); double width = latlonR.getWidth(); double lon0 = LatLonPointImpl.lonNormal( latlonR.getLowerLeftPoint().getLongitude(), centerLon); double lon1 = LatLonPointImpl.lonNormal( latlonR.getUpperRightPoint().getLongitude(), centerLon); ProjectionRect[] rects = new ProjectionRect[] {new ProjectionRect(), new ProjectionRect()}; if (lon0 < lon1) { rects[0].setRect(lon0, lat0, width, height); rects[1] = null; } else { double y = centerLon + 180 - lon0; rects[0].setRect(lon0, lat0, y, height); rects[1].setRect(lon1 - width + y, lat0, width - y, height); } return rects; }
@Test @Category(NeedsCdmUnitTest.class) public void testBBSubset() throws Exception { try (GridDataset dataset = GridDataset.open( "dods://localhost:8081/thredds/dodsC/cdmUnitTest/ncss/CONUS_80km_nc/GFS_CONUS_80km_20120419_0000.nc")) { GeoGrid grid = dataset.findGridByName("Pressure"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; logger.debug("original bbox = {}", gcs.getBoundingBox()); logger.debug("lat/lon bbox = {}", gcs.getLatLonBoundingBox()); LatLonRect llbb = gcs.getLatLonBoundingBox(); LatLonRect llbb_subset = new LatLonRect(llbb.getLowerLeftPoint(), 20.0, llbb.getWidth() / 2); logger.debug("subset lat/lon bbox = {}", llbb_subset); GeoGrid grid_section = grid.subset(null, null, llbb_subset, 1, 1, 1); GridCoordSystem gcs2 = grid_section.getCoordinateSystem(); assert null != gcs2; logger.debug("result lat/lon bbox = {}", gcs2.getLatLonBoundingBox()); logger.debug("result bbox = " + gcs2.getBoundingBox()); ProjectionRect pr = gcs2.getProjection().getDefaultMapArea(); logger.debug("projection mapArea = {}", pr); assert (pr.nearlyEquals(gcs2.getBoundingBox())); } }
@Test @Category(NeedsExternalResource.class) public void testScaleOffset() throws Exception { try (GridDataset dataset = GridDataset.open("http://esrl.noaa.gov/psd/thredds/dodsC/Datasets/noaa.oisst.v2/sst.wkmean.1990-present.nc")) { GeoGrid grid = dataset.findGridByName("sst"); assert null != grid; GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; logger.debug("original bbox = {} ({})", gcs.getBoundingBox(), gcs.getLatLonBoundingBox()); LatLonRect llbb = gcs.getLatLonBoundingBox(); LatLonRect llbb_subset = new LatLonRect(llbb.getLowerLeftPoint(), 20.0, llbb.getWidth() / 2); GeoGrid grid2 = grid.subset(null, null, llbb_subset, 1, 1, 1); GridCoordSystem gcs2 = grid2.getCoordinateSystem(); assert null != gcs2; logger.debug("subset bbox = {} ({})", gcs2.getBoundingBox(), gcs2.getLatLonBoundingBox()); logger.debug("original grid var = {}", grid.getVariable()); logger.debug("subset grid var = {}", grid2.getVariable()); Array data = grid.readDataSlice(0, 0, 159, 0); Array data2 = grid2.readDataSlice(0, 0, 0, 0); logger.debug(NCdumpW.toString(data, "org", null)); logger.debug(NCdumpW.toString(data2, "subset", null)); ucar.unidata.util.test.CompareNetcdf.compareData(data, data2); } }
protected void finishCalcBounds() { if (!calcBounds) return; if ((bb != null) && bb.crossDateline() && (bb.getWidth() > 350.0)) { // call it global - less confusing double lat_min = bb.getLowerLeftPoint().getLatitude(); double deltaLat = bb.getUpperLeftPoint().getLatitude() - lat_min; bb = new LatLonRect(new LatLonPointImpl(lat_min, -180.0), deltaLat, 360.0); } if (collection != null) { if (collection.getBoundingBox() == null) collection.setBoundingBox(bb); if (collection.getCalendarDateRange() == null) { CalendarDateRange dr = getCalendarDateRange(); if (dr != null) collection.setCalendarDateRange(dr); } if (collection.size() <= 0) { if (count < 0) count = 0; collection.setSize(count); } } }
protected void finishCalcBounds() { if (!calcBounds) return; if ((bb != null) && bb.crossDateline() && (bb.getWidth() > 350.0)) { // call it global - less confusing double lat_min = bb.getLowerLeftPoint().getLatitude(); double deltaLat = bb.getUpperLeftPoint().getLatitude() - lat_min; bb = new LatLonRect(new LatLonPointImpl(lat_min, -180.0), deltaLat, 360.0); } if (collection != null) { if (collection.getBoundingBox() == null) collection.setBoundingBox(bb); if (collection.getCalendarDateRange() == null) { CalendarDateRange dr = getCalendarDateRange(); if (dr != null) collection.setCalendarDateRange(dr); } if (collection.size() <= 0) { if (count < 0) count = 0; collection.setSize(count); } } }
@Test @Category(NeedsExternalResource.class) public void testDodsSubset() throws Exception { String filename = "dods://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/CONUS_80km/best"; 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 gribId = "Pressure_surface"; 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); // Assert.assertArrayEquals(new int[]{65, 361, 720}, cs.getShape()); LatLonRect llbb = gcs.getLatlonBoundingBox(); LatLonRect llbb_subset = new LatLonRect(llbb.getLowerLeftPoint(), 20.0, llbb.getWidth() / 2); checkLatLonSubset(gcs, coverage, llbb_subset, new int[]{1, 35, 46}); } }