/** * Find the best index for the given lat,lon point. * * @param wantLat lat of point * @param wantLon lon of point * @param rectIndex return (row,col) index, or best guess here. may not be null * @return false if not in the grid. */ public boolean findCoordElement(double wantLat, double wantLon, int[] rectIndex) { double wantLonNormal = LatLonPointImpl.lonNormalFrom(wantLon, lonMinMax.min); return findCoordElementNoForce(wantLat, wantLonNormal, rectIndex); }
private Optional<CoverageCoordAxis> subsetLon(LatLonRect llbb, int stride) throws InvalidRangeException { double wantMin = LatLonPointImpl.lonNormalFrom(llbb.getLonMin(), lonAxis.getStartValue()); double wantMax = LatLonPointImpl.lonNormalFrom(llbb.getLonMax(), lonAxis.getStartValue()); double start = lonAxis.getStartValue(); double end = lonAxis.getEndValue(); // use MAMath.MinMax as a container for two values, min and max List<MAMath.MinMax> lonIntvs = subsetLonIntervals(wantMin, wantMax, start, end); if (lonIntvs.size() == 0) return Optional.empty(String.format( "longitude want [%f,%f] does not intersect lon axis [%f,%f]", wantMin, wantMax, start, end)); if (lonIntvs.size() == 1) { MAMath.MinMax lonIntv = lonIntvs.get(0); return lonAxis.subset(lonIntv.min, lonIntv.max, stride); } // this is the seam crossing case return lonAxis.subsetByIntervals(lonIntvs, stride); }
Edges() { latEdge = (ArrayDouble.D2) latAxis2D.getCoordBoundsAsArray(); lonEdge = (ArrayDouble.D2) lonAxis2D.getCoordBoundsAsArray(); // assume missing values have been converted to NaNs latMinMax = MAMath.getMinMax(latEdge); lonMinMax = MAMath.getMinMax(lonEdge); // normalize to [minLon,minLon+360] int nlons = (int) lonEdge.getSize(); for (int i = 0; i < nlons; i++) { double nonVal = lonEdge.getDouble(i); lonEdge.setDouble(i, LatLonPointImpl.lonNormalFrom(nonVal, lonMinMax.min)); } if (debug) System.out.printf("Bounds (%d %d): lat= (%f,%f) lon = (%f,%f) %n", nrows, ncols, latMinMax.min, latMinMax.max, lonMinMax.min, lonMinMax.max); }
double minx = LatLonPointImpl.lonNormalFrom(llpt.getLongitude(), lonMinMax.min); double maxx = LatLonPointImpl.lonNormalFrom(urpt.getLongitude(), lonMinMax.min);
minx = LatLonPointImpl.lonNormalFrom( minx, minLon); maxx = LatLonPointImpl.lonNormalFrom( maxx, minLon);
minx = LatLonPointImpl.lonNormalFrom( minx, minLon); maxx = LatLonPointImpl.lonNormalFrom( maxx, minLon);
minx = LatLonPointImpl.lonNormalFrom( minx, minLon); maxx = LatLonPointImpl.lonNormalFrom( maxx, minLon);
CoordAxisHelper yhelper = new CoordAxisHelper(latAxis); double lonNormal = LatLonPointImpl.lonNormalFrom(latlon.getLongitude(), lonAxis.getStartValue()); optb = xhelper.subsetContaining(lonNormal); if (optb.isPresent()) lonaxisSubset = new CoverageCoordAxis1D(optb.get());
public Optional<CoordReturn> findXYindexFromCoord(double x, double y) { CoordReturn result = new CoordReturn(); if (isProjection) { CoordAxisHelper xhelper = new CoordAxisHelper(xAxis); CoordAxisHelper yhelper = new CoordAxisHelper(yAxis); result.x = xhelper.findCoordElement(x, false); result.y = yhelper.findCoordElement(y, false); if (result.x >= 0 && result.x < xAxis.getNcoords() && result.y >= 0 && result.y < yAxis.getNcoords()) { result.xcoord = xAxis.getCoordMidpoint(result.x); result.ycoord = yAxis.getCoordMidpoint(result.y); return Optional.of(result); } else { return Optional.empty("not in grid"); } } else { // 1D lat lon case CoordAxisHelper xhelper = new CoordAxisHelper(lonAxis); CoordAxisHelper yhelper = new CoordAxisHelper(latAxis); double lon = LatLonPointImpl.lonNormalFrom(x, lonAxis.getStartValue()); result.x = xhelper.findCoordElement(lon, false); result.y = yhelper.findCoordElement(y, false); if (result.x >= 0 && result.x < lonAxis.getNcoords() && result.y >= 0 && result.y < latAxis.getNcoords()) { result.xcoord = lonAxis.getCoordMidpoint(result.x); result.ycoord = latAxis.getCoordMidpoint(result.y); return Optional.of(result); } else { return Optional.empty("not in grid"); } } }