static private void doOne(ProjectionImpl proj, double lat, double lon) { LatLonPointImpl startL = new LatLonPointImpl(lat, lon); ProjectionPoint p = proj.latLonToProj(startL); LatLonPointImpl endL = (LatLonPointImpl) proj.projToLatLon(p); System.out.println("start = " + startL.toString(8)); System.out.println("xy = " + p.toString()); System.out.println("end = " + endL.toString(8)); }
/** * Get the label to be used in the gui for this type of projection. * This defaults to call getClassName * * @return Type label */ public String getProjectionTypeLabel() { return getClassName(); }
/** * Create a Projection Coordinate Transform. * @param name name of transform, must be unique within the NcML. * @param authority naming authority. * @param proj projection function. */ public ProjectionCT (String name, String authority, ProjectionImpl proj) { super( name, authority, TransformType.Projection); this.proj = proj; for (Parameter p : proj.getProjectionParameters()) { addParameter( p); } }
@Override public ProjectionImpl constructCopy() { ProjectionImpl result = new RotatedLatLon(latpole, lonpole, polerotate); result.setDefaultMapArea(defaultMapArea); result.setName(name); return result; }
protected CoverageCSImpl(NetcdfDataset ds, CoordinateSystem cs, CoverageCSFactory fac) { this.ds = ds; this.cs = cs; this.fac = fac; // set canonical area ProjectionImpl projOrig = cs.getProjection(); if (projOrig != null) { projection = projOrig.constructCopy(); projection.setDefaultMapArea(getBoundingBox()); // LOOK too expensive for 2D } }
public void testProjectionProjMax(ProjectionImpl proj, double xMax, double yMax) { java.util.Random r = new java.util.Random((long) this.hashCode()); ProjectionPointImpl startP = new ProjectionPointImpl(); for (int i = 0; i < NTRIALS; i++) { double x = xMax * (2 * r.nextDouble() - 1); double y = yMax * (2 * r.nextDouble() - 1); startP.setLocation(x, y); try { LatLonPoint ll = proj.projToLatLon(startP); ProjectionPoint endP = proj.latLonToProj(ll); if (show) { System.out.println("start = " + startP); System.out.println("interL = " + ll); System.out.println("end = " + endP); } Assert.assertEquals(startP.toString(), startP.getX(), endP.getX(), tolerence); Assert.assertEquals(startP.toString(), startP.getY(), endP.getY(), tolerence); } catch (IllegalArgumentException e) { System.out.printf("IllegalArgumentException=%s%n", e.getMessage()); continue; } } if (show) System.out.println("Tested " + NTRIALS + " pts for projection " + proj.getClassName()); }
double lrlon = -70.1154; ProjectionPointImpl ptul = (ProjectionPointImpl) projection.latLonToProj(new LatLonPointImpl(ullat, ullon)); ProjectionPointImpl ptlr = (ProjectionPointImpl) projection.latLonToProj(new LatLonPointImpl(lrlat, lrlon)); ProjectionPointImpl ptc = (ProjectionPointImpl) projection.latLonToProj(new LatLonPointImpl(clat, clon)); double startX = ptul.getX(); double startY = ptlr.getY(); Variable ct = new Variable(ncfile, null, null, projection.getClassName()); List params = projection.getProjectionParameters();
out.println(", " + proj.getClassName() + " projection;"); List<Parameter> params = proj.getProjectionParameters(); for (Parameter p : params) out.println(" " + p.getName() + " " + p.getStringValue());
/** * Alternate way to calculate latLonToProjBB, originally in GridCoordSys. * Difficult to do this in a general way. * * @param latlonRect desired lat/lon rectangle * @return a ProjectionRect */ ProjectionRect latLonToProjBB2(LatLonRect latlonRect) { double minx, maxx, miny, maxy; LatLonPointImpl llpt = latlonRect.getLowerLeftPoint(); LatLonPointImpl urpt = latlonRect.getUpperRightPoint(); LatLonPointImpl lrpt = latlonRect.getLowerRightPoint(); LatLonPointImpl ulpt = latlonRect.getUpperLeftPoint(); if (isLatLon()) { minx = getMinOrMaxLon(llpt.getLongitude(), ulpt.getLongitude(), true); miny = Math.min(llpt.getLatitude(), lrpt.getLatitude()); maxx = getMinOrMaxLon(urpt.getLongitude(), lrpt.getLongitude(), false); maxy = Math.min(ulpt.getLatitude(), urpt.getLatitude()); } else { ProjectionPoint ll = latLonToProj(llpt, new ProjectionPointImpl()); ProjectionPoint ur = latLonToProj(urpt, new ProjectionPointImpl()); ProjectionPoint lr = latLonToProj(lrpt, new ProjectionPointImpl()); ProjectionPoint ul = latLonToProj(ulpt, new ProjectionPointImpl()); minx = Math.min(ll.getX(), ul.getX()); miny = Math.min(ll.getY(), lr.getY()); maxx = Math.max(ur.getX(), lr.getX()); maxy = Math.max(ul.getY(), ur.getY()); } return new ProjectionRect(minx, miny, maxx, maxy); }
LatLonPoint llpt = projToLatLon(bb.getLowerLeftPoint(), new LatLonPointImpl()); LatLonPoint lrpt = projToLatLon(bb.getLowerRightPoint(), new LatLonPointImpl()); LatLonPoint urpt = projToLatLon(bb.getUpperRightPoint(), new LatLonPointImpl()); LatLonPoint ulpt = projToLatLon(bb.getUpperLeftPoint(), new LatLonPointImpl()); double lonMin = getMinOrMaxLon(llpt.getLongitude(), ulpt.getLongitude(), true); double lonMax = getMinOrMaxLon(lrpt.getLongitude(), urpt.getLongitude(), false);
/** * Get the bounding box in lat/lon. * * @return the LatLonRectangle for the bounding box */ public LatLonRect getDefaultMapAreaLL() { return projToLatLonBB(defaultMapArea); }
@Test @Category(NeedsCdmUnitTest.class) public void testMSG() throws Exception { String filename = TestDir.cdmUnitTestDir + "transforms/Eumetsat.VerticalPerspective.grb"; try(GridDataset dataset = GridDataset.open(filename)) { logger.debug("open {}", filename); GeoGrid grid = dataset.findGridDatatypeByAttribute(Grib.VARIABLE_ID_ATTNAME, "VAR_3-0-8"); // "Pixel_scene_type"); assert null != grid : dataset.getLocation(); GridCoordSystem gcs = grid.getCoordinateSystem(); assert null != gcs; assert grid.getRank() == 3; // bbox = ll: 16.79S 20.5W+ ur: 14.1N 20.09E LatLonRect bbox = new LatLonRect(new LatLonPointImpl(-16.79, -20.5), new LatLonPointImpl(14.1, 20.9)); ProjectionImpl p = gcs.getProjection(); ProjectionRect prect = p.latLonToProjBB(bbox); // must override default implementation logger.debug("{} -> {}", bbox, prect); ProjectionRect expected = new ProjectionRect( new ProjectionPointImpl(-2129.5688, -1793.0041), 4297.8453, 3308.3885); assert prect.nearlyEquals(expected); LatLonRect bb2 = p.projToLatLonBB(prect); logger.debug("{} -> {}", prect, bb2); GeoGrid grid_section = grid.subset(null, null, bbox, 1, 1, 1); Array data = grid_section.readDataSlice(-1, -1, -1, -1); assert data.getRank() == 3; int[] shape = data.getShape(); assert shape[0] == 1 : shape[0] + " should be 1"; assert shape[1] == 363 : shape[1] + " should be 363"; assert shape[2] == 479 : shape[2] + " should be 479"; } }
f.format(" Projection: %s %s%n", proj.getName(), proj.paramsToString());
/** * Convert lat/lon coordinates to projection coordinates. * * @param from array of lat/lon coordinates: from[2][n], * where from[0][i], from[1][i] is the (lat,lon) * coordinate of the ith point * @return resulting array of projection coordinates, where to[0][i], * to[1][i] is the (x,y) coordinate of the ith point */ public double[][] latLonToProj(double[][] from) { return latLonToProj(from, new double[2][from[0].length]); }
ProjectionPoint pp = proj.latLonToProj(latlon); optb = xhelper.subsetContaining(pp.getX()); if (optb.isPresent()) xaxisSubset = new CoverageCoordAxis1D(optb.get()); ProjectionRect prect = proj.latLonToProjBB(llbb); // allow projection to override opt = xAxis.subset(prect.getMinX(), prect.getMaxX(), horizStride); if (opt.isPresent()) xaxisSubset = (CoverageCoordAxis1D) opt.get();
/** * Create a ProjectionRect from the given LatLonRect. * Handles lat/lon points that do not intersect the projection panel. * LOOK NEEDS OVERRIDDING * @param rect the LatLonRect * @return ProjectionRect, or null if no part of the LatLonRect intersects the projection plane */ @Override public ProjectionRect latLonToProjBB(LatLonRect rect) { return super.latLonToProjBB(rect); }
/** * Convert projection coordinates to lat/lon coordinates. * * @param from array of projection coordinates: from[2][n], * where from[0][i], from[1][i] is the x, y coordinate * of the ith point * @return resulting array of lat/lon coordinates, where to[0][i], to[1][i] * is the lat,lon coordinate of the ith point */ public double[][] projToLatLon(double[][] from) { return projToLatLon(from, new double[2][from[0].length]); }
/** * Get a String representation of this projection. * * @return the name of the projection. This is what gets * displayed when you add the projection object to * a UI widget (e.g. label, combobox) */ public String toString() { return getName(); }
/** * Show Grids and coordinate systems. * @param buf put info here */ private void getInfo(Formatter buf) { int countGridset = 0; for (Gridset gs : gridsetHash.values()) { GridCoordSystem gcs = gs.getGeoCoordSystem(); buf.format("%nGridset %d coordSys=%s", countGridset, gcs); buf.format(" LLbb=%s ", gcs.getLatLonBoundingBox()); if ((gcs.getProjection() != null) && !gcs.getProjection().isLatLon()) buf.format(" bb= %s", gcs.getBoundingBox()); buf.format("%n"); buf.format("Name__________________________Unit__________________________hasMissing_Description%n"); for (GridDatatype grid : gs.getGrids()) { buf.format("%s%n", grid.getInfo()); } countGridset++; buf.format("%n"); } buf.format("%nGeoReferencing Coordinate Axes%n"); buf.format("Name__________________________Units_______________Type______Description%n"); for (CoordinateAxis axis : ncd.getCoordinateAxes()) { if (axis.getAxisType() == null) continue; axis.getInfo(buf); buf.format("%n"); } }
void doTest(ProjectionImpl p, LatLonRect rect) { ProjectionRect prect = p.latLonToProjBB( rect); ProjectionRect prect2 = p.latLonToProjBB2( rect); if (!prect.nearlyEquals(prect2)) { System.out.println("\nFAIL Projection= " + p); System.out.println(" llbb= " + rect.toString2()); System.out.println(" latLonToProjBB= " + prect); System.out.println(" latLonToProjBB2= " + prect2); assert false; } }