public EnvelopeParameter(String param) { String[] tokens = param.split(","); try { double minx = Double.parseDouble(tokens[0]); double miny = Double.parseDouble(tokens[1]); double maxx = Double.parseDouble(tokens[2]); double maxy = Double.parseDouble(tokens[3]); // null crs, set later from another parameter env = new Envelope2D(null, minx, miny, maxx-minx, maxy-miny); } catch (Exception e) { throw new WebApplicationException(fail(param, e)); } }
/** * Produce a single grayscale raster of travel time, like travel time tiles but not broken into tiles. */ @Path("/{surfaceId}/raster") @GET @Produces("image/*") public Response getRaster( @PathParam("surfaceId") Integer surfaceId, @QueryParam("width") @DefaultValue("1024") Integer width, @QueryParam("height") @DefaultValue("768") Integer height, @QueryParam("resolution") Double resolution, @QueryParam("time") IsoTimeParameter time, @QueryParam("format") @DefaultValue("image/geotiff") MIMEImageFormat format, @QueryParam("crs") @DefaultValue("EPSG:4326") CRSParameter crs) throws Exception { TimeSurface surface = otpServer.surfaceCache.get(surfaceId); Router router = otpServer.getRouter(surface.routerId); // BoundingBox is a subclass of Envelope, an Envelope2D constructor parameter Envelope2D bbox = new Envelope2D(router.graph.getGeomIndex().getBoundingBox(crs.crs)); if (resolution != null) { width = (int) Math.ceil(bbox.width / resolution); height = (int) Math.ceil(bbox.height / resolution); } TileRequest tileRequest = new TileRequest(bbox, width, height); RenderRequest renderRequest = new RenderRequest(format, Layer.TRAVELTIME, Style.GRAY, false, false); return router.renderer.getResponse(tileRequest, surface, null, renderRequest); }
public static Envelope2D tile2Envelope(final int x, final int y, final int zoom) { double maxLat = tile2lat(y, zoom); double minLat = tile2lat(y + 1, zoom); double minLon = tile2lon(x, zoom); double maxLon = tile2lon(x + 1, zoom); return new Envelope2D(DefaultGeographicCRS.WGS84, minLon, minLat, maxLon-minLon, maxLat-minLat); }
public BoundingBox toBounds(CoordinateReferenceSystem targetCRS) throws TransformException { Envelope transformed = new GeneralEnvelope((BoundingBox) this); transformed = CRS.transform(transformed, targetCRS); return new Envelope2D(transformed); }
private static GridCoverage2D readCoverage(String imageFileName) throws Exception { BufferedImage bi = ImageIO.read(CompositeTest.class.getResourceAsStream("test-data/" + imageFileName)); GridCoverageFactory factory = new GridCoverageFactory(); Envelope2D envelope = new Envelope2D( DefaultEngineeringCRS.GENERIC_2D, 0, 0, bi.getWidth(), bi.getHeight()); return factory.create(imageFileName, bi, envelope); }
static Envelope2D doInscribeFullDisk(Envelope2D circumscribed) { double dx = circumscribed.getWidth() / SQRT2; double dy = circumscribed.getHeight() / SQRT2; return new Envelope2D( circumscribed.getCoordinateReferenceSystem(), circumscribed.getCenterX() - dx / 2., circumscribed.getCenterY() - dy / 2., dx, dy); }
@Before public void setupTest() { Rectangle2D bounds = new Rectangle2D.Double(-20.0, -20.0, 40.0, 40.0); this.envelope2D = new Envelope2D(crs, bounds); this.australia = new Envelope2D(this.crs); australia.include(40, 110); australia.include(10, 150); this.newZealand = new Envelope2D(DefaultEngineeringCRS.CARTESIAN_2D); newZealand.include(50, 165); newZealand.include(33, 180); this.somewhereIntersectingAustralia = new Envelope2D(this.crs); somewhereIntersectingAustralia.include(50, 145); somewhereIntersectingAustralia.include(33, 180); this.somewhereInAustralia = new Envelope2D(this.crs); somewhereInAustralia.include(35, 140); somewhereInAustralia.include(40, 145); }
/** * Reduces the specified envelope to a two-dimensional one. If the given envelope has more than * two dimensions, then a new one is created using only the coordinates at ({@link * #axisDimensionX}, {@link #axisDimensionY}) index. * * <p>The {@link Envelope#getCoordinateReferenceSystem coordinate reference system} of the * source envelope is ignored. The coordinate reference system of the target envelope will be * {@link #getCoordinateReferenceSystem2D} or {@code null}. * * @param envelope The envelope to reduce, or {@code null}. This envelope will not be modified. * @return An envelope with exactly 2 dimensions, or {@code null} if {@code envelope} was null. * The returned envelope is always a new instance, so it can be modified safely. * @since 2.5 */ public Envelope2D reduce(final Envelope envelope) { if (envelope == null) { return null; } return new Envelope2D( crs2D, envelope.getMinimum(axisDimensionX), envelope.getMinimum(axisDimensionY), envelope.getSpan(axisDimensionX), envelope.getSpan(axisDimensionY)); }
/** * If the mouse was dragged, determines the bounds of the box that the user defined and passes * this to the mapPane's {@code setDisplayArea} method. * * @param ev the mouse event */ @Override public void onMouseReleased(MapMouseEvent ev) { if (dragged && !ev.getPoint().equals(startPosDevice)) { Envelope2D env = new Envelope2D(); env.setFrameFromDiagonal(startPosWorld, ev.getWorldPos()); dragged = false; getMapPane().setDisplayArea(env); } }
/** * Zoom in by the currently set increment, with the map centred at the location (in world * coords) of the mouse click * * @param e map mapPane mouse event */ @Override public void onMouseClicked(MapMouseEvent e) { Rectangle paneArea = ((JComponent) getMapPane()).getVisibleRect(); DirectPosition2D mapPos = e.getWorldPos(); double scale = getMapPane().getWorldToScreenTransform().getScaleX(); double newScale = scale * zoom; DirectPosition2D corner = new DirectPosition2D( mapPos.getX() - 0.5d * paneArea.getWidth() / newScale, mapPos.getY() + 0.5d * paneArea.getHeight() / newScale); Envelope2D newMapArea = new Envelope2D(); newMapArea.setFrameFromCenter(mapPos, corner); getMapPane().setDisplayArea(newMapArea); }
/** * Zoom out by the currently set increment, with the map centred at the location (in world * coords) of the mouse click * * @param ev the mouse event */ @Override public void onMouseClicked(MapMouseEvent ev) { Rectangle paneArea = ((JComponent) getMapPane()).getVisibleRect(); DirectPosition2D mapPos = ev.getWorldPos(); double scale = getMapPane().getWorldToScreenTransform().getScaleX(); double newScale = scale / zoom; DirectPosition2D corner = new DirectPosition2D( mapPos.getX() - 0.5d * paneArea.getWidth() / newScale, mapPos.getY() + 0.5d * paneArea.getHeight() / newScale); Envelope2D newMapArea = new Envelope2D(); newMapArea.setFrameFromCenter(mapPos, corner); getMapPane().setDisplayArea(newMapArea); }
@Test public void testSetBounds() { Envelope2D testEnvelope = new Envelope2D(); testEnvelope.setBounds(envelope2D); assertNotNull("envelope2d is null", testEnvelope); assertEquals("setbounds envelopes do not match", envelope2D, testEnvelope); }
public void testTransformLambertAzimuthalEqualAreaWgs84NonPolar() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3035", true); // a bbox that does _not_ include the pole Envelope2D envelope = new Envelope2D(crs); envelope.setFrameFromDiagonal(4029000, 2676000, 4696500, 3567700); Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); // check we did _not_ get the whole range of longitudes assertEquals(5.42, transformed.getMinimum(0), 1e-2); assertEquals(15.88, transformed.getMaximum(0), 1e-2); }
public void testTransformPolarStereographicToOther() throws Exception { CoordinateReferenceSystem antarcticPs = CRS.decode("EPSG:3031", true); CoordinateReferenceSystem australianPs = CRS.decode("EPSG:3032", true); Envelope2D envelope = new Envelope2D(antarcticPs); envelope.add(-4223632.8125, -559082.03125); envelope.add(5053710.9375, 3347167.96875); Envelope transformed = CRS.transform(envelope, australianPs); // has a false easting and northing, we can only check the spans are equal assertEquals(transformed.getSpan(0), transformed.getSpan(1), 1d); assertEquals(transformed.getMaximum(0), 1.2309982175378662E7, 1d); }
public void testTransformLambertAzimuthalEqualAreaWgs84() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3574", true); Envelope2D envelope = new Envelope2D(crs); // random bbox that does include the pole envelope.add(-3142000, -3142000); envelope.add(3142000, 3142000); Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); // check we got the whole range of longitudes, since the original bbox contains the pole assertEquals(-180d, transformed.getMinimum(0), 0d); assertEquals(180d, transformed.getMaximum(0), 0d); }
Envelope2D newMapArea = new Envelope2D(); newMapArea.setFrameFromCenter(mapPos, corner); getMapPane().setDisplayArea(newMapArea);
/** * Returns a two-dimensional envelope for the given coverage. This method performs a <cite>best * effort</cite>; the returned envelope is not garanteed to be the most appropriate one. * * @param coverage The coverage for which to obtains a two-dimensional envelope. * @return The two-dimensional envelope. * @throws MismatchedDimensionException if the envelope can't be reduced to two dimensions. */ public static Envelope2D getEnvelope2D(final Coverage coverage) throws MismatchedDimensionException { if (coverage instanceof GridCoverage2D) { return ((GridCoverage2D) coverage).getEnvelope2D(); } if (coverage instanceof GridCoverage) { final GridGeometry2D geometry = GridGeometry2D.wrap(((GridCoverage) coverage).getGridGeometry()); if (geometry.isDefined(GridGeometry2D.ENVELOPE_BITMASK)) { return geometry.getEnvelope2D(); } else { return geometry.reduce(coverage.getEnvelope()); } } // Following may thrown MismatchedDimensionException. return new Envelope2D(coverage.getEnvelope()); }
public void testTransformPolarStereographicWgs84FalseOrigin() throws Exception { // this one has false origins at 6000000/6000000 CoordinateReferenceSystem crs = CRS.decode("EPSG:3032", true); Envelope2D envelope = new Envelope2D(crs); envelope.add(5900000, 5900000); envelope.add(6100000, 6100000); Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); // check we got the whole range of longitudes, since the original bbox contains the pole assertEquals(-180d, transformed.getMinimum(0), 0d); assertEquals(180d, transformed.getMaximum(0), 0d); }
public void testTransformPolarStereographicWgs84() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true); Envelope2D envelope = new Envelope2D(crs); // random bbox that does include the pole envelope.add(-4223632.8125, -559082.03125); envelope.add(5053710.9375, 3347167.96875); Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); // check we got the whole range of longitudes, since the original bbox contains the pole assertEquals(-180d, transformed.getMinimum(0), 0d); assertEquals(180d, transformed.getMaximum(0), 0d); // another bbox envelope = new Envelope2D(crs); // random bbox that does not include the pole, but it's really just slightly off it envelope.add(-10718812.640513, -10006238.053703); envelope.add(12228504.561708, -344209.75803081); transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84); assertEquals(-90, transformed.getMinimum(1), 0.1d); }
public void testTransformWgs84PolarStereographic() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true); Envelope2D envelope = new Envelope2D(DefaultGeographicCRS.WGS84); envelope.add(-180, -90); envelope.add(180, 0); Envelope transformed = CRS.transform(envelope, crs); // the result is a square assertEquals(transformed.getMaximum(0), transformed.getMaximum(1), 1d); assertEquals(transformed.getMinimum(0), transformed.getMinimum(1), 1d); assertEquals(Math.abs(transformed.getMinimum(0)), transformed.getMaximum(0), 1d); assertEquals(transformed.getMaximum(0), 1.236739621845986E7, 1d); }