public GridCoordSys getGridCoordSys(VariableEnhanced ve) { List<CoordinateSystem> csList = ve.getCoordinateSystems(); for (CoordinateSystem cs : csList) { if (GridCoordSys.isGridCoordSys(null, cs, ve)) { return new GridCoordSys(cs, null); } } return null; }
/** * Given a point in x,y coordinate space, find the x,y index in the coordinate system. * * @deprecated use findXYindexFromCoord */ public int[] findXYCoordElement(double x_coord, double y_coord, int[] result) { return findXYindexFromCoord(x_coord, y_coord, result); }
@Override public void setProjectionBoundingBox() { // set canonical area if (proj != null) { proj.setDefaultMapArea(getBoundingBox()); // LOOK too expensive for 2D } }
@Override public void show(Formatter f, boolean showCoords) { f.format("Coordinate System (%s)%n%n", getName()); if (getRunTimeAxis() != null) { f.format("rt=%s (%s)", runTimeAxis.getFullName(), runTimeAxis.getClass().getName()); if (showCoords) showCoords(runTimeAxis, f); f.format("%n"); if (getEnsembleAxis() != null) { f.format("ens=%s (%s)", ensembleAxis.getFullName(), ensembleAxis.getClass().getName()); if (showCoords) showCoords(ensembleAxis, f); f.format("%n"); if (getTimeAxis() != null) { f.format("t=%s (%s)", tAxis.getFullName(), tAxis.getClass().getName()); if (showCoords) showCoords(tAxis, f); f.format("%n"); if (getVerticalAxis() != null) { f.format("z=%s (%s)", vertZaxis.getFullName(), vertZaxis.getClass().getName()); if (showCoords) showCoords(vertZaxis, f); f.format("%n"); if (getYHorizAxis() != null) { f.format("y=%s (%s)", horizYaxis.getFullName(), horizYaxis.getClass().getName()); if (showCoords) showCoords(horizYaxis, f); f.format("%n"); if (getXHorizAxis() != null) {
CoordinateAxis xaxis = from.getXHorizAxis(); CoordinateAxis yaxis = from.getYHorizAxis(); } else if ((xaxis instanceof CoordinateAxis2D) && (yaxis instanceof CoordinateAxis2D) && from.isLatLon()) { CoordinateAxis2D lon_axis = (CoordinateAxis2D) xaxis; CoordinateAxis2D lat_axis = (CoordinateAxis2D) yaxis; if (from.isGeoXY()) { xAxis = horizXaxis; yAxis = horizYaxis; ProjectionImpl projOrig = from.getProjection(); if (projOrig != null) { proj = projOrig.constructCopy(); proj.setDefaultMapArea(getBoundingBox()); // LOOK expensive for 2D CoordinateAxis1D zaxis = from.getVerticalAxis(); if (zaxis != null) { vertZaxis = (z_range == null) ? zaxis : zaxis.section(z_range); if (from.getVerticalCT() != null) { VerticalTransform vtFrom = from.getVerticalTransform(); // LOOK may need to make sure this exists? if (vtFrom != null) vt = vtFrom.subset(t_range, z_range, y_range, x_range); vCT = from.getVerticalCT(); CoordinateAxis1D eaxis = from.getEnsembleAxis(); if (eaxis != null) {
for (CoordinateSystem cs : csList) { Element csElem; if (GridCoordSys.isGridCoordSys(null, cs, null)) { GridCoordSys gcs = new GridCoordSys(cs, null); csElem = new Element("gridCoordSystem"); csElem.setAttribute("name", cs.getName()); csElem.setAttribute("horizX", gcs.getXHorizAxis().getFullName()); csElem.setAttribute("horizY", gcs.getYHorizAxis().getFullName()); if (gcs.hasVerticalAxis()) csElem.setAttribute("vertical", gcs.getVerticalAxis().getFullName()); if (gcs.hasTimeAxis()) csElem.setAttribute("time", cs.getTaxis().getFullName()); } else { gridElem.setAttribute("udunits", isUdunits(ve.getUnitsString())); gridElem.setAttribute("coordSys", gcs.getName());
this.gcs = gcs; CoordinateAxis xaxis = gcs.getXHorizAxis(); if (xaxis instanceof CoordinateAxis1D) { xDimOrgIndex = findDimension(gcs.getXHorizAxis().getDimension(0)); yDimOrgIndex = findDimension(gcs.getYHorizAxis().getDimension(0)); yDimOrgIndex = findDimension(gcs.getXHorizAxis().getDimension(0)); xDimOrgIndex = findDimension(gcs.getXHorizAxis().getDimension(1)); if (gcs.getVerticalAxis() != null) zDimOrgIndex = findDimension(gcs.getVerticalAxis().getDimension(0)); if (gcs.getTimeAxis() != null) { if (gcs.getTimeAxis1D() != null) tDimOrgIndex = findDimension(gcs.getTimeAxis1D().getDimension(0)); else tDimOrgIndex = findDimension(gcs.getTimeAxis().getDimension(1)); if (gcs.getEnsembleAxis() != null) eDimOrgIndex = findDimension(gcs.getEnsembleAxis().getDimension(0)); if (gcs.getRunTimeAxis() != null) rtDimOrgIndex = findDimension(gcs.getRunTimeAxis().getDimension(0));
if (!(p instanceof RotatedPole) && !(p instanceof RotatedLatLon)) { horizXaxis = convertUnits(horizXaxis); horizYaxis = convertUnits(horizYaxis); if (projOrig != null) { proj = projOrig.constructCopy(); proj.setDefaultMapArea(getBoundingBox()); // LOOK too expensive for 2D this.name = makeName(coordAxes); Attribute att = getXHorizAxis().findAttribute(_Coordinate.Stagger); if (att != null) setHorizStaggerType(att.getStringValue());
if (isLatLon()) { double startLat = horizYaxis.getMinValue(); double startLon = horizXaxis.getMinValue(); Projection dataProjection = getProjection(); ProjectionRect bb = getBoundingBox(); resultNP = findXYindexFromLatLon(90.0, 0, null); if (resultNP[0] != -1 && resultNP[1] != -1) includesNorthPole = true; boolean includesSouthPole = false; int[] resultSP = new int[2]; resultSP = findXYindexFromLatLon(-90.0, 0, null); if (resultSP[0] != -1 && resultSP[1] != -1) includesSouthPole = true; double lonMin = getMinOrMaxLon(llpt.getLongitude(), ulpt.getLongitude(), true); double lonMax = getMinOrMaxLon(lrpt.getLongitude(), urpt.getLongitude(), false);
if (isLatLon()) { double startLat = horizYaxis.getMinValue(); double startLon = horizXaxis.getMinValue(); ProjectionImpl dataProjection = getProjection(); ProjectionRect bb = getBoundingBox(); llbb = dataProjection.projToLatLonBB(bb);
/** * Given a lat,lon point, find the x,y index in the coordinate system. * * @param lat latitude position. * @param lon longitude position. * @param result put result in here, may be null * @return int[2], 0=x,1=y indices in the coordinate system of the point. These will be -1 if out of range. */ @Override public int[] findXYindexFromLatLon(double lat, double lon, int[] result) { Projection dataProjection = getProjection(); ProjectionPoint pp = dataProjection.latLonToProj(new LatLonPointImpl(lat, lon), new ProjectionPointImpl()); return findXYindexFromCoord(pp.getX(), pp.getY(), result); }
/** * Given a lat,lon point, find the x,y index in the coordinate system. * If outside the range, the closest point is returned * * @param lat latitude position. * @param lon longitude position. * @param result put result in here, may be null * @return int[2], 0=x,1=y indices in the coordinate system of the point. */ @Override public int[] findXYindexFromLatLonBounded(double lat, double lon, int[] result) { Projection dataProjection = getProjection(); ProjectionPoint pp = dataProjection.latLonToProj(new LatLonPointImpl(lat, lon), new ProjectionPointImpl()); return findXYindexFromCoordBounded(pp.getX(), pp.getY(), result); }
/** * Get the string name for the ith time coordinate. * * @param index which time coordinate * @return time name. * @deprecated */ public String getTimeName(int index) { List<CalendarDate> cdates = getCalendarDates(); if ((index < 0) || (index >= cdates.size())) throw new IllegalArgumentException("getTimeName illegal index = " + index); return cdates.get(index).toString(); }
public GridDatatype makeSubset(Range rt_range, Range e_range, Range t_range, Range z_range, Range y_range, Range x_range) throws InvalidRangeException { // get the ranges list int rank = getRank(); Range[] ranges = new Range[rank]; if (null != getXDimension()) ranges[xDimOrgIndex] = x_range; if (null != getYDimension()) ranges[yDimOrgIndex] = y_range; if (null != getZDimension()) ranges[zDimOrgIndex] = z_range; if (null != getTimeDimension()) ranges[tDimOrgIndex] = t_range; if (null != getRunTimeDimension()) ranges[rtDimOrgIndex] = rt_range; if (null != getEnsembleDimension()) ranges[eDimOrgIndex] = e_range; List<Range> rangesList = Arrays.asList(ranges); // subset the variable VariableDS v_section = (VariableDS) vs.section( new Section(rangesList)); List<Dimension> dims = v_section.getDimensions(); for (Dimension dim : dims) { dim.setShared(true); // make them shared (section will make them unshared) } // subset the axes in the GridCoordSys GridCoordSys gcs_section = new GridCoordSys(gcs, rt_range, e_range, t_range, z_range, y_range, x_range); // now we can make the geogrid return new GeoGrid(dataset, v_section, gcs_section); }
@Test @Category(NeedsCdmUnitTest.class) public void testVerticalAxis() throws Exception { String uri = TestDir.cdmUnitTestDir + "ncml/nc/cg/CG2006158_120000h_usfc.nc"; String varName = "CGusfc"; try (GridDataset dataset = GridDataset.open(uri)) { GeoGrid grid = dataset.findGridByName(varName); assert null != grid; GridCoordSystem gcsi = grid.getCoordinateSystem(); assert null != gcsi; assert (gcsi.getVerticalAxis() != null); GridCoordSys gcs = (GridCoordSys) grid.getCoordinateSystem(); assert null != gcs; assert gcs.hasVerticalAxis(); // returns true. // subset geogrid GeoGrid subg = grid.subset(null, null, null, 1, 1, 1); assert null != subg; GridCoordSystem gcsi2 = subg.getCoordinateSystem(); assert null != gcsi2; assert (gcsi2.getVerticalAxis() != null); GridCoordSys gcs2 = (GridCoordSys) subg.getCoordinateSystem(); assert null != gcs2; assert !gcs2.hasVerticalAxis(); // fails } }
CoordinateAxis xaxis = from.getXHorizAxis(); CoordinateAxis yaxis = from.getYHorizAxis(); } else if ((xaxis instanceof CoordinateAxis2D) && (yaxis instanceof CoordinateAxis2D) && from.isLatLon()) { CoordinateAxis2D lon_axis = (CoordinateAxis2D) xaxis; CoordinateAxis2D lat_axis = (CoordinateAxis2D) yaxis; if (from.isGeoXY()) { xAxis = horizXaxis; yAxis = horizYaxis; ProjectionImpl projOrig = from.getProjection(); if (projOrig != null) { proj = projOrig.constructCopy(); proj.setDefaultMapArea(getBoundingBox()); // LOOK expensive for 2D CoordinateAxis1D zaxis = from.getVerticalAxis(); if (zaxis != null) { vertZaxis = (z_range == null) ? zaxis : zaxis.section(z_range); if (from.getVerticalCT() != null) { VerticalTransform vtFrom = from.getVerticalTransform(); // LOOK may need to make sure this exists? if (vtFrom != null) vt = vtFrom.subset(t_range, z_range, y_range, x_range); vCT = from.getVerticalCT(); CoordinateAxis1D eaxis = from.getEnsembleAxis(); if (eaxis != null) {
for (CoordinateSystem cs : csList) { Element csElem; if (GridCoordSys.isGridCoordSys(null, cs, null)) { GridCoordSys gcs = new GridCoordSys(cs, null); csElem = new Element("gridCoordSystem"); csElem.setAttribute("name", cs.getName()); csElem.setAttribute("horizX", gcs.getXHorizAxis().getFullName()); csElem.setAttribute("horizY", gcs.getYHorizAxis().getFullName()); if (gcs.hasVerticalAxis()) csElem.setAttribute("vertical", gcs.getVerticalAxis().getFullName()); if (gcs.hasTimeAxis()) csElem.setAttribute("time", cs.getTaxis().getFullName()); } else { gridElem.setAttribute("udunits", isUdunits(ve.getUnitsString())); gridElem.setAttribute("coordSys", gcs.getName());
@Override public void show(Formatter f, boolean showCoords) { f.format("Coordinate System (%s)%n", getName()); if (getRunTimeAxis() != null) { f.format(" rt=%s (%s)", runTimeAxis.getNameAndDimensions(), runTimeAxis.getClass().getName()); if (showCoords) showCoords(runTimeAxis, f); f.format("%n"); if (getEnsembleAxis() != null) { f.format(" ens=%s (%s)", ensembleAxis.getNameAndDimensions(), ensembleAxis.getClass().getName()); if (showCoords) showCoords(ensembleAxis, f); f.format("%n"); if (getTimeAxis() != null) { f.format(" t=%s (%s)", tAxis.getNameAndDimensions(), tAxis.getClass().getName()); if (showCoords) showCoords(tAxis, f); f.format("%n"); if (getVerticalAxis() != null) { f.format(" z=%s (%s)", vertZaxis.getNameAndDimensions(), vertZaxis.getClass().getName()); if (showCoords) showCoords(vertZaxis, f); f.format("%n"); if (getYHorizAxis() != null) { f.format(" y=%s (%s)", horizYaxis.getNameAndDimensions(), horizYaxis.getClass().getName()); if (showCoords) showCoords(horizYaxis, f); f.format("%n"); if (getXHorizAxis() != null) {
this.gcs = gcs; CoordinateAxis xaxis = gcs.getXHorizAxis(); if (xaxis instanceof CoordinateAxis1D) { xDimOrgIndex = findDimension(gcs.getXHorizAxis().getDimension(0)); yDimOrgIndex = findDimension(gcs.getYHorizAxis().getDimension(0)); yDimOrgIndex = findDimension(gcs.getXHorizAxis().getDimension(0)); xDimOrgIndex = findDimension(gcs.getXHorizAxis().getDimension(1)); if (gcs.getVerticalAxis() != null) zDimOrgIndex = findDimension(gcs.getVerticalAxis().getDimension(0)); if (gcs.getTimeAxis() != null) { if (gcs.getTimeAxis1D() != null) tDimOrgIndex = findDimension(gcs.getTimeAxis1D().getDimension(0)); else tDimOrgIndex = findDimension(gcs.getTimeAxis().getDimension(1)); if (gcs.getEnsembleAxis() != null) eDimOrgIndex = findDimension(gcs.getEnsembleAxis().getDimension(0)); if (gcs.getRunTimeAxis() != null) rtDimOrgIndex = findDimension(gcs.getRunTimeAxis().getDimension(0));
if (!(p instanceof RotatedPole) && !(p instanceof RotatedLatLon)) { horizXaxis = convertUnits(horizXaxis); horizYaxis = convertUnits(horizYaxis); if (projOrig != null) { proj = projOrig.constructCopy(); proj.setDefaultMapArea(getBoundingBox()); // LOOK too expensive for 2D this.name = makeName(coordAxes); Attribute att = getXHorizAxis().findAttribute(_Coordinate.Stagger); if (att != null) setHorizStaggerType(att.getStringValue());