public CoordinateReferenceSystem getCRS() { return delegate.getCRS(); }
CoordinateReferenceSystem destCRS; try { destCRS = info.getCRS(); } catch (Exception e) { final IOException ioe = new IOException("unable to determine coverage crs");
assertNotNull(cv.getGrid()); assertNotNull(cv.getGrid().getGridRange()); assertNotNull(cv.getCRS()); assertNotNull(cv.getGrid().getGridToCRS()); assertEquals(cv.getGrid().getGridRange().getLow(0), 0);
@Test public void testSingleBandedCoverage() throws Exception { // build a feature type (it's already in the catalog, but we just want to // check it's built as expected // LINES is a feature type with a native SRS, so we want the bounds to be there Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getCoverageStoreByName(MockData.TASMANIA_DEM.getLocalPart())); CoverageInfo ci = cb.buildCoverage(); // perform basic checks assertEquals(CRS.decode("EPSG:4326", true), ci.getCRS()); assertEquals("EPSG:4326", ci.getSRS()); assertNotNull(ci.getNativeCRS()); assertNotNull(ci.getNativeBoundingBox()); assertNotNull(ci.getLatLonBoundingBox()); // check the coverage dimensions List<CoverageDimensionInfo> dimensions = ci.getDimensions(); assertEquals(1, dimensions.size()); CoverageDimensionInfo dimension = dimensions.get(0); assertEquals("GRAY_INDEX", dimension.getName()); assertEquals(1, dimension.getNullValues().size()); assertEquals(-9999, dimension.getNullValues().get(0), 0d); assertEquals(Double.NEGATIVE_INFINITY, dimension.getRange().getMinimum(), 0d); // Huston, we have a problem here... // assertEquals(9999, dimension.getRange().getMaximum(), 0d); assertNull(dimension.getUnit()); }
@Test public void testMultiBandCoverage() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getCoverageStoreByName(MockData.TASMANIA_BM.getLocalPart())); CoverageInfo ci = cb.buildCoverage(); // perform basic checks assertEquals(CRS.decode("EPSG:4326", true), ci.getCRS()); assertEquals("EPSG:4326", ci.getSRS()); assertNotNull(ci.getNativeCRS()); assertNotNull(ci.getNativeBoundingBox()); assertNotNull(ci.getLatLonBoundingBox()); // check the coverage dimensions List<CoverageDimensionInfo> dimensions = ci.getDimensions(); assertEquals(3, dimensions.size()); CoverageDimensionInfo dimension = dimensions.get(0); assertEquals("RED_BAND", dimension.getName()); assertEquals(0, dimension.getNullValues().size()); assertEquals(Double.NEGATIVE_INFINITY, dimension.getRange().getMinimum(), 0d); assertEquals(Double.POSITIVE_INFINITY, dimension.getRange().getMaximum(), 0d); assertEquals("W.m-2.Sr-1", dimension.getUnit()); }
private void encodeDatasetBounds(CoverageInfo ci, GridCoverage2DReader reader) throws IOException { // get the crs and look for an EPSG code final CoordinateReferenceSystem crs = ci.getCRS(); GeneralEnvelope envelope = reader.getOriginalEnvelope(); List<String> axesNames = envelopeAxisMapper.getAxesNames(envelope, true); // lookup EPSG code Integer EPSGCode = null; try { EPSGCode = CRS.lookupEpsgCode(crs, false); } catch (FactoryException e) { throw new IllegalStateException( "Unable to lookup epsg code for this CRS:" + crs, e); } if (EPSGCode == null) { throw new IllegalStateException("Unable to lookup epsg code for this CRS:" + crs); } final String srsName = GetCoverage.SRS_STARTER + EPSGCode; // handle axes swap for geographic crs final boolean axisSwap = CRS.getAxisOrder(crs).equals(AxisOrder.EAST_NORTH); final StringBuilder builder = new StringBuilder(); for (String axisName : axesNames) { builder.append(axisName).append(" "); } String axesLabel = builder.substring(0, builder.length() - 1); dcTranslator.handleBoundedBy(envelope, axisSwap, srsName, axesLabel, null); }
GridEnvelope2D guessGridLimits() { try { String coverageName = coverage.getModelObject(); Catalog catalog = GeoServerApplication.get().getCatalog(); CoverageInfo ci = catalog.getCoverageByName(coverageName); ReferencedEnvelope boundsNative = getCoverage.bounds.transform(ci.getCRS(), true); MathTransform w2g = ci.getGrid().getGridToCRS().inverse(); Envelope ge = JTS.transform(boundsNative, w2g); GridEnvelope2D grid = new GridEnvelope2D(new Rectangle(0, 0, (int) ge.getWidth(), (int) ge.getHeight())); return grid; } catch(Exception e) { LOGGER.log(Level.SEVERE, "Failed to guess native grid", e); error("Failed to guess native grid: " + e.getMessage()); return null; } }
for (int dn = 0; dn < ci.getCRS().getCoordinateSystem().getDimension(); dn++) { String axisName = ci.getCRS().getCoordinateSystem().getAxis(dn).getAbbreviation(); axisName = axisName.toLowerCase().startsWith("lon") ? "x" : axisName; axisName = axisName.toLowerCase().startsWith("lat") ? "y" : axisName;
GridEnvelope2D guessGridLimits() { try { String coverageName = coverage.getModelObject(); Catalog catalog = GeoServerApplication.get().getCatalog(); CoverageInfo ci = catalog.getCoverageByName(coverageName); ReferencedEnvelope boundsNative = getCoverage.bounds.transform(ci.getCRS(), true); MathTransform w2g = ci.getGrid().getGridToCRS().inverse(); Envelope ge = JTS.transform(boundsNative, w2g); GridEnvelope2D grid = new GridEnvelope2D( new Rectangle(0, 0, (int) ge.getWidth(), (int) ge.getHeight())); return grid; } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to guess native grid", e); error("Failed to guess native grid: " + e.getMessage()); return null; } }
protected void handleGridCRS(CoverageInfo ci) throws Exception { start("wcs:GridCRS"); element("wcs:GridBaseCRS", urnIdentifier(ci.getCRS())); element("wcs:GridType", GridType.GT2dGridIn2dCrs.getXmlConstant()); // TODO: go back to using the metadata once they can be trusted final LinearTransform tx = (LinearTransform) ci.getGrid().getGridToCRS(); final Matrix matrix = tx.getMatrix(); // origin StringBuffer origins = new StringBuffer(); for (int i = 0; i < matrix.getNumRow() - 1; i++) { origins.append(matrix.getElement(i, matrix.getNumCol() - 1)); if (i < matrix.getNumRow() - 2) origins.append(" "); } element("wcs:GridOrigin", origins.toString()); // offsets StringBuffer offsets = new StringBuffer(); for (int i = 0; i < matrix.getNumRow() - 1; i++) { for (int j = 0; j < matrix.getNumCol() - 1; j++) { offsets.append(matrix.getElement(i, j)); if (j < matrix.getNumCol() - 2) offsets.append(" "); } if (i < matrix.getNumRow() - 2) offsets.append(" "); } element("wcs:GridOffsets", offsets.toString()); element("wcs:GridCS", "urn:ogc:def:cs:OGC:0.0:Grid2dSquareCS"); end("wcs:GridCRS"); }
AffineTransform guessGridToWorld(boolean resolutionMode) { try { String coverageName = coverage.getModelObject(); Catalog catalog = GeoServerApplication.get().getCatalog(); CoverageInfo ci = catalog.getCoverageByName(coverageName); ReferencedEnvelope nativeBounds = getCoverage.bounds.transform(ci.getCRS(), true); ReferencedEnvelope targetBounds = nativeBounds.transform(getCoverage.targetCRS, true); GridEnvelope2D gridLimits = guessGridLimits(); GridGeometry2D gg = new GridGeometry2D(gridLimits, targetBounds); AffineTransform at = (AffineTransform) gg.getGridToCRS(PixelInCell.CELL_CORNER); if(resolutionMode) { return AffineTransform.getScaleInstance(at.getScaleX(), at.getScaleY()); } else { return at; } } catch(Exception e) { LOGGER.log(Level.SEVERE, "Failed to guess target affine transform", e); error("Failed to guess native grid: " + e.getMessage()); return null; } }
AffineTransform guessGridToWorld(boolean resolutionMode) { try { String coverageName = coverage.getModelObject(); Catalog catalog = GeoServerApplication.get().getCatalog(); CoverageInfo ci = catalog.getCoverageByName(coverageName); ReferencedEnvelope nativeBounds = getCoverage.bounds.transform(ci.getCRS(), true); ReferencedEnvelope targetBounds = nativeBounds.transform(getCoverage.targetCRS, true); GridEnvelope2D gridLimits = guessGridLimits(); GridGeometry2D gg = new GridGeometry2D(gridLimits, targetBounds); AffineTransform at = (AffineTransform) gg.getGridToCRS(PixelInCell.CELL_CORNER); if (resolutionMode) { return AffineTransform.getScaleInstance(at.getScaleX(), at.getScaleY()); } else { return at; } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to guess target affine transform", e); error("Failed to guess native grid: " + e.getMessage()); return null; } }
targetCRS = cinfo.getNativeCRS(); } else { targetCRS = cinfo.getCRS();
CoordinateReferenceSystem gridCrs = coverage.getCRS(); for (int dn = 0; dn < gridCrs.getCoordinateSystem().getDimension(); dn++) { String axisName = gridCrs.getCoordinateSystem().getAxis(dn).getAbbreviation();
CoordinateReferenceSystem gridCrs = coverage.getCRS(); for (int dn = 0; dn < gridCrs.getCoordinateSystem().getDimension(); dn++) { String axisName = gridCrs.getCoordinateSystem().getAxis(dn).getAbbreviation();
gridCRS.setGridBaseCRS(gridBaseCrs); } else { String code = GML2EncodingUtils.epsgCode(meta.getCRS()); gridCRS.setGridBaseCRS("urn:x-ogc:def:crs:EPSG:" + code);
/** * This method returns {@code true} in case we have POSTed a Coverage object with the name only, * as an instance when configuring a new coverage which has just been harvested. * * @param coverage */ private boolean isNewCoverage(CoverageInfo coverage) { return coverage.getName() != null && (coverage.isAdvertised()) && (!coverage.isEnabled()) && (coverage.getAlias() == null) && (coverage.getCRS() == null) && (coverage.getDefaultInterpolationMethod() == null) && (coverage.getDescription() == null) && (coverage.getDimensions() == null) && (coverage.getGrid() == null) && (coverage.getInterpolationMethods() == null) && (coverage.getKeywords() == null) && (coverage.getLatLonBoundingBox() == null) && (coverage.getMetadata() == null) && (coverage.getNativeBoundingBox() == null) && (coverage.getNativeCRS() == null) && (coverage.getNativeFormat() == null) && (coverage.getProjectionPolicy() == null) && (coverage.getSRS() == null) && (coverage.getResponseSRS() == null) && (coverage.getRequestSRS() == null); }