/** * This utility method can be used to read a small sample {@link GridCoverage2D} for inspection * from the specified {@link CoverageInfo}. * * @param ci the {@link CoverageInfo} that contains the description of the GeoServer coverage to * read from. */ public static GridCoverage2D readSampleGridCoverage(CoverageInfo ci) throws Exception { final GridCoverage2DReader reader = getCoverageReader(ci); return readSampleGridCoverage(reader); }
/** Builds the identifier for a granule inside a coverage */ public String getGranuleId(CoverageInfo coverage, String featureId) { return NCNameResourceCodec.encode(coverage) + GRANULE_SEPARATOR + featureId; }
public static String merge(List<String> list) { return merge(list, ","); }
@Override public WCS20DescribeCoverageTransformer describeCoverage(DescribeCoverageType request) { checkService(request.getService()); checkVersion(request.getVersion()); newCoverageID = ext.handleCoverageId(newCoverageID); LayerInfo layer = NCNameResourceCodec.getCoverage(catalog, newCoverageID); if (layer == null) { badCoverageIds.add(encodedCoverageId); String mergedIds = StringUtils.merge(badCoverageIds); throw new WCS20Exception( "Could not find the requested coverage(s): " + mergedIds,
/** * Returns the coverage containing the specified coverage, or null if the syntax is incorrect, * the coverage does not exist, or it's not a dataset */ public CoverageInfo getGranuleCoverage(String granuleId) { // does it have the expected lexical structure? if (!granuleId.contains(GRANULE_SEPARATOR)) { return null; } String[] splitted = granuleId.split(GRANULE_SEPARATOR); if (splitted.length != 2) { return null; } // do we have the coverage? LayerInfo li = NCNameResourceCodec.getCoverage(catalog, splitted[0]); if (li == null) { return null; } // is it a EO dataset? CoverageInfo ci = (CoverageInfo) li.getResource(); if (isValidDataset(ci)) { return ci; } else { return null; } }
@Override public GridCoverage getCoverage(GetCoverageType request) { checkService(request.getService()); checkVersion(request.getVersion()); if (request.getCoverageId() == null || "".equals(request.getCoverageId())) { throw new OWS20Exception( "Required parameter coverageId missing", WCS20Exception.WCS20ExceptionCode.EmptyCoverageIdList, "coverageId"); } return new GetCoverage(getServiceInfo(), catalog, envelopeAxesMapper, mimeMapper) .run(request); }
@Test public void testDecode01() { String qualifiedName = "ws__name"; List<MapEntry<String, String>> decode = NCNameResourceCodec.decode(qualifiedName); assertEquals(1, decode.size()); assertEquals("ws", decode.get(0).getKey()); assertEquals("name", decode.get(0).getValue()); }
public static LayerInfo getCoverage(Catalog catalog, String encodedCoverageId) throws WCS20Exception { List<LayerInfo> layers = NCNameResourceCodec.getLayers(catalog, encodedCoverageId); if (layers == null) return null; LayerInfo ret = null; for (LayerInfo layer : layers) { if (layer != null && layer.getType() == PublishedType.RASTER) { if (ret == null) { ret = layer; } else { LOGGER.warning( "Multiple coverages found for NSName '" + encodedCoverageId + "': " + ret.prefixedName() + " is selected, " + layer.prefixedName() + " will be ignored"); } } } return ret; }
@Override public TransformerBase getCapabilities(GetCapabilitiesType request) { checkService(request.getService()); return new GetCapabilities(getServiceInfo(), responseFactory).run(request); }
public int getAxisIndex(final Envelope envelope, final String axisAbbreviation) { final int[] val = getAxesIndexes(envelope, Arrays.asList(axisAbbreviation)); return (val == null ? -1 : val[0]); }
private GridSampleDimension[] getSampleDimensions(GridCoverage2DReader reader) throws Exception { GridCoverage2D coverage = null; try { coverage = RequestUtils.readSampleGridCoverage(reader); return coverage.getSampleDimensions(); } finally { if (coverage != null) { CoverageCleanerCallback.addCoverages(coverage); } } }
/** * This method is responsible for extracting the spatial interpolation from the provided {@link * GetCoverageType} request. * * <p>We don't support mixed interpolation at this time and we will never support it for grid * axes. * * @param axesInterpolations the association between axes URIs and the requested interpolations. * @param envelope the original envelope for the source {@link GridCoverage}. * @return the requested {@link Interpolation} */ private Interpolation extractSpatialInterpolation( Map<String, InterpolationPolicy> axesInterpolations, Envelope envelope) { // extract interpolation // // we assume that we are going to support the same interpolation ONLY on the i and j axes // therefore we extract the first one of the two we find. We implicitly assume we already // checked that we don't have mixed interpolation types for lat,lon Interpolation interpolation = InterpolationPolicy.getDefaultPolicy().getInterpolation(); for (String axisLabel : axesInterpolations.keySet()) { // check if this is an axis we like final int index = envelopeDimensionsMapper.getAxisIndex(envelope, axisLabel); if (index == 0 || index == 1) { // found it! interpolation = axesInterpolations.get(axisLabel).getInterpolation(); break; } } return interpolation; }
public String getDatasetName(CoverageInfo ci) { if (!isValidDataset(ci)) { throw new IllegalArgumentException( "Specified covearge " + ci.prefixedName() + " is not a valid EO dataset"); } return NCNameResourceCodec.encode(ci) + DATASET_SUFFIX; }
/** * Returns the coverage backed by the provided datasetId * * @param datasetId * @return the coverage, or null if not found, or if not a coverage */ public CoverageInfo getDatasetCoverage(String datasetId) { if (!datasetId.endsWith(DATASET_SUFFIX)) { LOGGER.fine( "Invalid dataset id " + datasetId + " it does not end with " + DATASET_SUFFIX); return null; } String coverageName = datasetId.substring(0, datasetId.length() - DATASET_SUFFIX.length()); LayerInfo layer = NCNameResourceCodec.getCoverage(catalog, coverageName); if (layer == null) { LOGGER.fine( "Invalid dataset id " + datasetId + " does not match any published dataset"); return null; } CoverageInfo ci = (CoverageInfo) layer.getResource(); if (!isValidDataset(ci)) { LOGGER.fine( "Invalid dataset id " + datasetId + " does not match any published dataset"); return null; } return ci; }
@Test // (expected=IllegalArgumentException.class) public void testDecodeBad() { String qualifiedName = "bad_qualified_name"; List<MapEntry<String, String>> decode = NCNameResourceCodec.decode(qualifiedName); assertEquals(1, decode.size()); assertNull(decode.get(0).getKey()); assertEquals("bad_qualified_name", decode.get(0).getValue()); } }
public static String encode(ResourceInfo resource) { return encode(resource.getNamespace().getPrefix(), resource.getName()); }
@Test public void testDecode03() { String qualifiedName = "s1___s2"; List<MapEntry<String, String>> decode = NCNameResourceCodec.decode(qualifiedName); assertEquals(2, decode.size()); assertEquals("s1_", decode.get(0).getKey()); assertEquals("s2", decode.get(0).getValue()); assertEquals("s1", decode.get(1).getKey()); assertEquals("_s2", decode.get(1).getValue()); }
/** Test of encode method, of class CoverageIdConverter. */ @Test public void testEncode() { String result = NCNameResourceCodec.encode("ws", "name"); assertEquals("ws__name", result); }
@Test public void testDecode02() { String qualifiedName = "s1__s2__s3"; List<MapEntry<String, String>> decode = NCNameResourceCodec.decode(qualifiedName); assertEquals(2, decode.size()); assertEquals("s1__s2", decode.get(0).getKey()); assertEquals("s3", decode.get(0).getValue()); assertEquals("s1", decode.get(1).getKey()); assertEquals("s2__s3", decode.get(1).getValue()); }
private void handleCoverageSummary(CoverageInfo cv) throws Exception { start("wcs:CoverageSummary"); String covId = NCNameResourceCodec.encode(cv); element("wcs:CoverageId", covId); element("wcs:CoverageSubtype", "RectifiedGridCoverage"); // TODO make this parametric handleWGS84BoundingBox(cv.getLatLonBoundingBox()); handleBoundingBox(cv.boundingBox()); end("wcs:CoverageSummary"); }