public boolean equals(Object other) { if (other instanceof TileRequest) { TileRequest that = (TileRequest) other; return this.bbox.equals(that.bbox) && this.width == that.width && this.height == that.height; } return false; }
public int hashCode() { return bbox.hashCode() * 42677 + width + height * 1307; }
@Override public void visit(GridCoverage2DReader reader) { GeneralEnvelope envelope = reader.getOriginalEnvelope(); if (env == null) { env = envelope; } else { env.intersect(envelope); } } }
envelope = new GeneralEnvelope(coverageBounds); } else { envelope = new GeneralEnvelope(env); final CoordinateReferenceSystem sourceCRS = envelope.getCoordinateReferenceSystem(); CoordinateReferenceSystem destCRS; try { envelope.intersect(coverageBounds); if (envelope.isEmpty()) { return null; envelope.setCoordinateReferenceSystem(destCRS);
final CoordinateReferenceSystem sourceCRS = envelope.getCoordinateReferenceSystem(); return new GeneralEnvelope(envelope); targetEnvelope = CRS.transform(envelope, targetCRS); } else { targetEnvelope = new GeneralEnvelope(envelope); targetEnvelope.setCoordinateReferenceSystem(targetCRS);
new GeneralEnvelope( new double[] {coords[0], coords[1]}, new double[] {coords[2], coords[3]});
assertEquals(399960, envelope.getMinimum(0), 1); assertEquals(5190240, envelope.getMinimum(1), 1); assertEquals(509760, envelope.getMaximum(0), 1); assertEquals(5300040, envelope.getMaximum(1), 1);
DirectPosition2D orig = new DirectPosition2D(x, y); DirectPosition2D transformed = new DirectPosition2D(); mathTransform.transform(orig, transformed); lon = transformed.getY(); lat = transformed.getX(); lon = transformed.getX(); lat = transformed.getY();
/** * 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; }
GridEnvelope2D targetRange = new GridEnvelope2D( (int) Math.round(padRange.getMinimum(0)), (int) Math.round(padRange.getMinimum(1)), (int) Math.round(padRange.getSpan(0)), (int) Math.round(padRange.getSpan(1))); GridEnvelope2D sourceRange = gg.getGridRange2D(); if (sourceRange.x == targetRange.x
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)); } }
public GridEnvelope getOriginalGridRange() { if (homogeneousCoverages) { return delegate.getOriginalGridRange(referenceName); } // Due to mixed combinations, let's take the envelope and divide the span // by the resolution GeneralEnvelope envelope = getOriginalEnvelope(); double[] res; try { res = getResolutionLevels()[0]; return new GridEnvelope2D( new Rectangle( (int) (envelope.getSpan(0) / res[0]), (int) (envelope.getSpan(1) / res[1]))); } catch (IOException e) { throw new IllegalArgumentException(e); } }
if (env.contains(point)) { double[] result; double x = point.getOrdinate(0);
/** Returns the original source file, is present in the metadata, and if the coverage */ private File getSourceFile(GridCoverage2D coverage) { final Object fileSource = coverage.getProperty(AbstractGridCoverage2DReader.FILE_SOURCE_PROPERTY); if (fileSource != null && fileSource instanceof String) { File file = new File((String) fileSource); if (file.exists()) { GeoTiffReader reader = null; try { reader = new GeoTiffReader(file); GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope(); Envelope envelope = coverage.getEnvelope(); if (originalEnvelope.equals(envelope, 1e-9, false)) { GridCoverage2D test = reader.read(null); ImageUtilities.disposeImage(test.getRenderedImage()); return file; } } catch (Exception e) { // ok, not a geotiff! } finally { if (reader != null) { reader.dispose(); } } } } return null; }
@Override public void visit(GridCoverage2DReader reader) { GeneralEnvelope envelope = reader.getOriginalEnvelope(); if (env == null) { env = envelope; } else { env.add(envelope); } } }
/** * Computes the difference between the ellipsoid and geoid at a specified lat/lon using Geotools EarthGravitationalModel * * @param lat * @param lon * @return difference in meters * @throws FactoryException * @throws TransformException */ public static double computeEllipsoidToGeoidDifference(double lat, double lon) throws FactoryException, TransformException { // Set up a MathTransform based on the EarthGravitationalModel EarthGravitationalModel.Provider provider = new EarthGravitationalModel.Provider(); DefaultMathTransformFactory factory = new DefaultMathTransformFactory(); MathTransform mt = factory.createParameterizedTransform(provider.getParameters().createValue()); // Compute the offset DirectPosition3D dest = new DirectPosition3D(); mt.transform(new DirectPosition3D(lon, lat, 0), dest); return dest.z; } }
/** * Test GridCoverage unwrapping * * @throws IOException */ @Test public void testGridCoverageUnwrapping() throws IOException { GridCoverageFactory gcFactory = new GridCoverageFactory(); RenderedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY); GridCoverage2D original = gcFactory.create( "original", image, new GeneralEnvelope(new Rectangle2D.Double(0, 0, 64, 64))); GridSampleDimension[] gsd = new GridSampleDimension[] {new GridSampleDimension("wrappedSampleDimension")}; GridCoverageWrapper wrapper = new GridCoverageWrapper("wrapped", original, gsd, null); assertNotSame(original.getSampleDimensions(), wrapper.getSampleDimensions()); assertNotSame(wrapper, original); assertSame(original, wrapper.unwrap(original.getClass())); } }
assertEquals(399960, envelope.getMinimum(0), 1); assertEquals(5192273, envelope.getMinimum(1), 1); assertEquals(507726, envelope.getMaximum(0), 1); assertEquals(5300040, envelope.getMaximum(1), 1);
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); }
/** * 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); }