public void appendLoggingGeometries(String geomName, GeneralEnvelope env) { if (LOGGER.isLoggable(GEOM_LEVEL)) { StringBuilder sb = getGeom(geomName); sb.append( " ((" + env.getMinimum(0) + " " + env.getMinimum(1) + ", " + env.getMaximum(0) + " " + env.getMinimum(1) + ", " + env.getMaximum(0) + " " + env.getMaximum(1) + ", " + env.getMinimum(0) + " " + env.getMaximum(1) + ", " + env.getMinimum(0) + " " + env.getMinimum(1) + ")),"); } }
private static ReferencedEnvelope toReferencedEnvelope(GeneralEnvelope envelope) { double minx = envelope.getMinimum(0); double maxx = envelope.getMaximum(0); double miny = envelope.getMinimum(1); double maxy = envelope.getMaximum(1); CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); ReferencedEnvelope refEnv = new ReferencedEnvelope(minx, maxx, miny, maxy, crs); return refEnv; }
@Test public void testDomainSubsetRxRy() throws Exception { // get base coverage final GridCoverage baseCoverage = catalog.getCoverageByName(TASMANIA_BM.getLocalPart()).getGridCoverage(null, null); final AffineTransform2D expectedTx = (AffineTransform2D) baseCoverage.getGridGeometry().getGridToCRS(); final GeneralEnvelope originalEnvelope = (GeneralEnvelope) baseCoverage.getEnvelope(); final GeneralEnvelope newEnvelope = new GeneralEnvelope(originalEnvelope); newEnvelope.setEnvelope( originalEnvelope.getMinimum(0), originalEnvelope.getMaximum(1) - originalEnvelope.getSpan(1) / 2, originalEnvelope.getMinimum(0) + originalEnvelope.getSpan(0) / 2, originalEnvelope.getMaximum(1)); final MathTransform cornerWorldToGrid = PixelTranslation.translate(expectedTx, PixelInCell.CELL_CENTER, PixelInCell.CELL_CORNER); final GeneralGridEnvelope expectedGridEnvelope = new GeneralGridEnvelope( CRS.transform(cornerWorldToGrid.inverse(), newEnvelope), PixelInCell.CELL_CORNER, false); final StringBuilder envelopeBuilder = new StringBuilder(); envelopeBuilder.append(newEnvelope.getMinimum(0)).append(","); envelopeBuilder.append(newEnvelope.getMinimum(1)).append(","); envelopeBuilder.append(newEnvelope.getMaximum(0)).append(","); envelopeBuilder.append(newEnvelope.getMaximum(1)); Map<String, Object> raw = baseMap(); final String layerID = getLayerId(TASMANIA_BM); raw.put("sourcecoverage", layerID); raw.put("version", "1.0.0"); raw.put("format", "image/geotiff"); raw.put("BBox", envelopeBuilder.toString()); raw.put("crs", "EPSG:4326"); raw.put("resx", Double.toString(expectedTx.getScaleX())); raw.put("resy", Double.toString(Math.abs(expectedTx.getScaleY()))); final GridCoverage[] coverages = executeGetCoverageKvp(raw); final GridCoverage2D result = (GridCoverage2D) coverages[0]; assertTrue(coverages.length == 1); final AffineTransform2D tx = (AffineTransform2D) result.getGridGeometry().getGridToCRS(); assertEquals("resx", expectedTx.getScaleX(), tx.getScaleX(), 1E-6); assertEquals("resx", Math.abs(expectedTx.getScaleY()), Math.abs(tx.getScaleY()), 1E-6); final GridEnvelope gridEnvelope = result.getGridGeometry().getGridRange(); assertEquals("w", 180, gridEnvelope.getSpan(0)); assertEquals("h", 180, gridEnvelope.getSpan(1)); assertEquals("grid envelope", expectedGridEnvelope, gridEnvelope); // dispose CoverageCleanerCallback.disposeCoverage(baseCoverage); CoverageCleanerCallback.disposeCoverage(coverages[0]); }
/** * @param env GeneralEnvelope * @return Polygon object with the same boundary as env */ protected Polygon polyFromEnvelope(GeneralEnvelope env) { GeometryFactory factory = new GeometryFactory(); Coordinate[] coords = new Coordinate[] { new Coordinate(env.getMinimum(0), env.getMinimum(1)), new Coordinate(env.getMinimum(0), env.getMaximum(1)), new Coordinate(env.getMaximum(0), env.getMaximum(1)), new Coordinate(env.getMaximum(0), env.getMinimum(1)), new Coordinate(env.getMinimum(0), env.getMinimum(1)) }; return factory.createPolygon(factory.createLinearRing(coords), new LinearRing[0]); }
private GeneralEnvelope toPixelCenter(double[] resolution, GeneralEnvelope pixelCornerEnv) { double deltaX = resolution[0] / 2; double deltaY = resolution[1] / 2; GeneralEnvelope env = new GeneralEnvelope(pixelCornerEnv.getCoordinateReferenceSystem()); env.setEnvelope( pixelCornerEnv.getMinimum(0) + deltaX, pixelCornerEnv.getMinimum(1) + deltaY, pixelCornerEnv.getMaximum(0) - deltaX, pixelCornerEnv.getMaximum(1) - deltaY); return env; }
/** * Tests the transformations of an envelope when the two CRS have identify transforms but * different datum names */ @Test public void testEnvelopeTransformation2() throws FactoryException, TransformException { final CoordinateReferenceSystem WGS84Altered = CRS.parseWKT(WKT.WGS84_ALTERED); final CoordinateReferenceSystem WGS84 = DefaultGeographicCRS.WGS84; final MathTransform crsTransform = CRS.findMathTransform(WGS84, WGS84Altered, true); assertTrue(crsTransform.isIdentity()); final GeneralEnvelope firstEnvelope; firstEnvelope = new GeneralEnvelope(new double[] {-124, 42}, new double[] {-122, 43}); firstEnvelope.setCoordinateReferenceSystem(WGS84); // this triggered a assertion error in GEOT-2934 Envelope transformed = CRS.transform(firstEnvelope, WGS84Altered); // check the envelope is what we expect assertEquals(transformed.getCoordinateReferenceSystem(), WGS84Altered); double EPS = 1e-9; assertEquals(transformed.getMinimum(0), firstEnvelope.getMinimum(0), EPS); assertEquals(transformed.getMinimum(1), firstEnvelope.getMinimum(1), EPS); assertEquals(transformed.getMaximum(0), firstEnvelope.getMaximum(0), EPS); assertEquals(transformed.getMaximum(1), firstEnvelope.getMaximum(1), EPS); }
private ArcSDEGridCoverage2DReaderJAI.ReadParameters parseReadParams( final GeneralParameterValue[] params) throws IllegalArgumentException { if (params == null) { throw new IllegalArgumentException("No GeneralParameterValue given to read operation"); } GeneralEnvelope reqEnvelope = null; GridEnvelope dim = null; OverviewPolicy overviewPolicy = null; // ///////////////////////////////////////////////////////////////////// // // Checking params // // ///////////////////////////////////////////////////////////////////// for (int i = 0; i < params.length; i++) { final ParameterValue<?> param = (ParameterValue<?>) params[i]; final String name = param.getDescriptor().getName().getCode(); if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString())) { final GridGeometry2D gg = (GridGeometry2D) param.getValue(); reqEnvelope = new GeneralEnvelope((Envelope) gg.getEnvelope2D()); final GeneralEnvelope coverageEnvelope = getOriginalEnvelope(); CoordinateReferenceSystem nativeCrs = coverageEnvelope.getCoordinateReferenceSystem(); CoordinateReferenceSystem requestCrs = reqEnvelope.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(nativeCrs, requestCrs)) { LOGGER.fine( "Request CRS and native CRS differ, " + "reprojecting request envelope to native CRS"); ReferencedEnvelope nativeCrsEnv; nativeCrsEnv = toNativeCrs(reqEnvelope, nativeCrs); reqEnvelope = new GeneralEnvelope(nativeCrsEnv); } dim = gg.getGridRange2D(); continue; } if (name.equals(AbstractGridFormat.OVERVIEW_POLICY.getName().toString())) { overviewPolicy = (OverviewPolicy) param.getValue(); continue; } } if (reqEnvelope == null && dim == null) { reqEnvelope = getOriginalEnvelope(); dim = getOriginalGridRange(); } if (reqEnvelope == null) { reqEnvelope = getOriginalEnvelope(); } if (dim == null) { final GeneralEnvelope adjustedGRange; try { MathTransform gridToWorld = getOriginalGridToWorld(PixelInCell.CELL_CENTER); MathTransform worldToGrid = gridToWorld.inverse(); adjustedGRange = CRS.transform(worldToGrid, reqEnvelope); } catch (Exception e) { throw new RuntimeException(e); } int xmin = (int) Math.floor(adjustedGRange.getMinimum(0)); int ymin = (int) Math.floor(adjustedGRange.getMinimum(1)); int xmax = (int) Math.ceil(adjustedGRange.getMaximum(0)); int ymax = (int) Math.ceil(adjustedGRange.getMaximum(1)); dim = new GridEnvelope2D(xmin, ymin, xmax - xmin, ymax - ymin); } if (!reqEnvelope.intersects(getOriginalEnvelope(), true)) { throw new IllegalArgumentException( "The requested extend does not overlap the coverage extent: " + getOriginalEnvelope()); } if (dim.getSpan(0) <= 0 || dim.getSpan(1) <= 0) { throw new IllegalArgumentException("The requested coverage dimension can't be null: " + dim); } if (overviewPolicy == null) { overviewPolicy = OverviewPolicy.NEAREST; LOGGER.finer("No overview policy requested, defaulting to " + overviewPolicy); } LOGGER.fine("Overview policy is " + overviewPolicy); ArcSDEGridCoverage2DReaderJAI.ReadParameters parsedParams = new ArcSDEGridCoverage2DReaderJAI.ReadParameters(); parsedParams.requestedEnvelope = reqEnvelope; parsedParams.dim = dim; parsedParams.overviewPolicy = overviewPolicy; return parsedParams; }