/** * Method for retrieving the elevation at a given (x, y) pair. * * @param x the query longitude (NAD83) * @param y the query latitude (NAD83) * @return elevation in meters */ private double getElevation(double x, double y) { double values[] = new double[1]; try { // We specify a CRS here because otherwise the coordinates are assumed to be in the coverage's native CRS. // That assumption is fine when the coverage happens to be in longitude-first WGS84 but we want to support // GeoTIFFs in various projections. Note that GeoTools defaults to strict EPSG axis ordering of (lat, long) // for DefaultGeographicCRS.WGS84, but OTP is using (long, lat) throughout and assumes unprojected DEM // rasters to also use (long, lat). coverage.evaluate(new DirectPosition2D(GeometryUtils.WGS84_XY, x, y), values); } catch (org.opengis.coverage.PointOutsideCoverageException e) { nPointsOutsideDEM += 1; } nPointsEvaluated += 1; return values[0] * elevationUnitMultiplier; }
DirectPosition2D orig = new DirectPosition2D(x, y); DirectPosition2D transformed = new DirectPosition2D(); mathTransform.transform(orig, transformed);
/** * Creates a circle using the specified center and radius. * * @param center of the circle. * @param radius of the circle. */ protected Circle(DirectPosition center, double radius) { this.center = new DirectPosition2D(center); this.radius = radius; }
/** * Sets the center. * * @param center coordinates */ protected void setCenter(DirectPosition center) { this.center = new DirectPosition2D(center); }
/** Creates a circle with center [0,0] and radius = 0. */ protected Circle() { this(new DirectPosition2D(0, 0), 0); }
public void transform(double[] srcPts, int srcOff, final double[] dstPt, int dstOff, int numPts) throws TransformException { for (int i = srcOff; i < numPts; i++) { Point2D pos = (Point2D) (new DirectPosition2D(srcPts[2 * i], srcPts[(2 * i) + 1])); TINTriangle triangle = searchTriangle((DirectPosition) pos); AffineTransform AT = (AffineTransform) trianglesToKeysMap.get(triangle); Point2D dst = AT.transform(pos, null); dstPt[2 * i] = dst.getX(); dstPt[(2 * i) + 1] = dst.getY(); } }
/** * Constructs a string for the specified point. This is used for formatting error messages. * * @param point The coordinate point to format. * @param locale The locale for formatting numbers. * @return The coordinate point as a string, without '(' or ')' characters. */ static String toString(final Point2D point, final Locale locale) { return toString((DirectPosition) new DirectPosition2D(point), locale); }
/** * Gets the mouse position in world coordinates. * * @return world position */ public DirectPosition2D getWorldPos() { return new DirectPosition2D( worldCoords.getCoordinateReferenceSystem(), worldCoords.x, worldCoords.y); }
/** Constructor */ public ZoomInTool() { Toolkit tk = Toolkit.getDefaultToolkit(); ImageIcon imgIcon = new ImageIcon(getClass().getResource(CURSOR_IMAGE)); cursor = tk.createCustomCursor(imgIcon.getImage(), CURSOR_HOTSPOT, TOOL_NAME); startPosDevice = new Point(); startPosWorld = new DirectPosition2D(); dragged = false; }
/** * Constructs an error message for a point that can not be evaluated. This is used for * formatting error messages. * * @param point The coordinate point to format. * @param outside {@code true} if the evaluation failed because the given point is outside the * coverage, or {@code false} if it failed for an other (unknown) reason. * @return An error message. * @since 2.5 */ protected String formatEvaluateError(final Point2D point, final boolean outside) { return formatEvaluateError((DirectPosition) new DirectPosition2D(point), outside); }
/** * Creates a mapped position with {@linkplain #getSource source} and {@linkplain #getTarget * target} position of the specified dimension. The initial coordinate values are 0. */ public MappedPosition(final int dimension) { if (dimension == 2) { source = new DirectPosition2D(); target = new DirectPosition2D(); } else { source = new GeneralDirectPosition(dimension); target = new GeneralDirectPosition(dimension); } }
/** * The contains test whether the coordinate p is within the circle. Triangle contains coordinate * if the distance between center and p is smaller then the radius that is reduced by tolerance. * This is used for triangulation when there are four points on one circle to avoid neverending * loop. * * @param p - the point to be tested * @return True if the circle contais p, False if not. */ protected boolean contains(DirectPosition p) { if (center.distance(new DirectPosition2D(p)) < (this.radius - tolerance)) { return true; } else { return false; } } }
/** * A coordinate position consisting of all the maximal ordinates for each dimension for all * points within the {@code Envelope}. */ public DirectPosition getUpperCorner() { return new DirectPosition2D(crs, getMaxX(), getMaxY()); }
/** * A coordinate position consisting of all the minimal ordinates for each dimension for all * points within the {@code Envelope}. * * @return The lower corner. * @todo Change the return type to {@link DirectPosition2D} when we will be allowed to compile * for J2SE 1.5. */ public DirectPosition getLowerCorner() { return new DirectPosition2D(crs, getMinX(), getMinY()); }
/** * A coordinate position consisting of all the maximal ordinates for each dimension for all * points within the {@code Envelope}. * * @return The upper corner. * @todo Change the return type to {@link DirectPosition2D} when we will be allowed to compile * for J2SE 1.5. */ public DirectPosition getUpperCorner() { return new DirectPosition2D(crs, getMaxX(), getMaxY()); }
/** * A coordinate position consisting of all the minimal ordinates for each dimension for all * points within the {@code Envelope}. */ public DirectPosition getLowerCorner() { return new DirectPosition2D(crs, getMinX(), getMinY()); }
/** * Helper for constructors to calculate mouse position in world coordinates. * * @param pane source map pane * @param event source mouse event * @return position in world coordinates */ private DirectPosition2D calculateWorldPos(MapPane pane, MouseEvent event) { AffineTransform tr = pane.getScreenToWorldTransform(); DirectPosition2D pos = new DirectPosition2D(event.getX(), event.getY()); tr.transform(pos, pos); pos.setCoordinateReferenceSystem(pane.getMapContent().getCoordinateReferenceSystem()); return pos; } }
/** * Returns reduced coordinates of vertices so the first vertex has [0,0] coordinats. * * @return The List of reduced vertives */ protected List<DirectPosition> reduce() { // Coordinate[] redCoords = new Coordinate[coordinates.length]; ArrayList<DirectPosition> redCoords = new ArrayList<DirectPosition>(); for (int i = 0; i < vertices.length; i++) { redCoords.add( new DirectPosition2D( vertices[i].getCoordinateReferenceSystem(), vertices[i].getCoordinate()[0] - vertices[0].getCoordinate()[0], vertices[i].getCoordinate()[1] - vertices[0].getCoordinate()[1])); } return redCoords; }
static DirectPosition[] positions(LineString line) { CoordinateSequence coordinates = line.getCoordinateSequence(); DirectPosition[] dps = new DirectPosition[coordinates.size()]; double x; double y; for (int i = 0; i < dps.length; i++) { x = coordinates.getOrdinate(i, 0); y = coordinates.getOrdinate(i, 1); dps[i] = new DirectPosition2D(x, y); } return dps; }
public void testCRS_CH1903_LV03() throws NoSuchAuthorityCodeException, FactoryException, MismatchedDimensionException, TransformException { CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326", false); // WGS84 CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:21781", false); // CH1903_LV03 MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true); // test coordinate: Berne, old reference point // see // http://www.swisstopo.admin.ch/internet/swisstopo/en/home/topics/survey/sys/refsys/switzerland.html DirectPosition2D source = new DirectPosition2D(sourceCRS, 46.9510827861504654, 7.4386324175389165); DirectPosition2D result = new DirectPosition2D(); transform.transform(source, result); assertEquals(600000.0, result.x, 0.1); assertEquals(200000.0, result.y, 0.1); }