public AbstractGridFormat getFormat() { return delegate.getFormat(); }
/** Builds the default coverage contained in the current store */ public CoverageInfo buildCoverage(String coverageName) throws Exception { if (store == null || !(store instanceof CoverageStoreInfo)) { throw new IllegalStateException("Coverage store not set."); } CoverageStoreInfo csinfo = (CoverageStoreInfo) store; GridCoverage2DReader reader = (GridCoverage2DReader) catalog.getResourcePool() .getGridCoverageReader(csinfo, GeoTools.getDefaultHints()); if (reader == null) throw new Exception( "Unable to acquire a reader for this coverage with format: " + csinfo.getFormat().getName()); return buildCoverage(reader, coverageName, null); }
/** * Builds the default coverage contained in the current store * * @param nativeCoverageName the native name for the coverage * @param specifiedName the published name for the coverage. If null, the name will be * determined from the coverage store. * @return coverage for the specified name * @throws Exception if the coverage store was not found or could not be read, or if the * coverage could not be created. */ public CoverageInfo buildCoverageByName(String nativeCoverageName, String specifiedName) throws Exception { if (store == null || !(store instanceof CoverageStoreInfo)) { throw new IllegalStateException("Coverage store not set."); } CoverageStoreInfo csinfo = (CoverageStoreInfo) store; GridCoverage2DReader reader = (GridCoverage2DReader) catalog.getResourcePool() .getGridCoverageReader(csinfo, GeoTools.getDefaultHints()); if (reader == null) throw new Exception( "Unable to acquire a reader for this coverage with format: " + csinfo.getFormat().getName()); return buildCoverageInternal(reader, nativeCoverageName, null, specifiedName); }
final AbstractGridFormat gridFormat = info.getFormat(); if (gridFormat == null) { throw new IOException("Could not find the raster plugin for format " + info.getType());
Format format = csinfo.getFormat(); final ParameterValueGroup readParams = format.getReadParameters();
expect(cs.getFormat()) .andAnswer( new IAnswer<AbstractGridFormat>() {
expect(csi.getFormat()).andReturn(format).anyTimes(); expect(csi.getId()).andReturn("ThisIsMe").anyTimes(); expect(csi.getName()).andReturn("ThisIsMe").anyTimes();
CoverageStoreInfo storeInfo = createNiceMock("storeInfo", CoverageStoreInfo.class); expect(storeInfo.getURL()).andReturn(url).anyTimes(); expect(storeInfo.getFormat()).andReturn(format).anyTimes(); replay(storeInfo);
throw new Exception( "Unable to acquire a reader for this coverage with format: " + csinfo.getFormat().getName());
cb.setStore(cs); GridCoverage2DReader reader = cs.getFormat().getReader(cs.getURL()); if (reader == null) { throw new RuntimeException("No reader for " + cs.getURL());
/** * Adds into the keySet any read parameter key that's missing (due to reader growing new * parameters over time/releases */ private void addMissingParameters(TreeSet<String> keySet, CoverageInfo coverage) { AbstractGridFormat format = coverage.getStore().getFormat(); ParameterValueGroup readParameters = format.getReadParameters(); List<GeneralParameterValue> parameterValues = readParameters.values(); List<String> paramNames = parameterValues .stream() .map(p -> p.getDescriptor()) .filter(p -> p instanceof DefaultParameterDescriptor) .map(p -> p.getName().getCode()) .collect(Collectors.toList()); keySet.addAll(paramNames); }
private void initParameterDescriptors() { try { final CoverageInfo coverage = (CoverageInfo) getResourceInfo(); AbstractGridFormat format = coverage.getStore().getFormat(); ParameterValueGroup readParameters = format.getReadParameters(); List<GeneralParameterValue> parameterValues = readParameters.values(); parameterDescriptorMap = parameterValues .stream() .map(p -> p.getDescriptor()) .filter(p -> p instanceof DefaultParameterDescriptor) .map(p -> (DefaultParameterDescriptor) p) .collect( Collectors.toMap( p -> p.getName().getCode(), Function.identity())); } catch (Exception e) { LOGGER.log( Level.INFO, "Failed to initialize parameter descriptors, the UI will use generic text " + "editors", e); } }
/** * Grabs the reader from the specified coverage * * @param ci * @throws IOException */ public static GridCoverage2DReader getCoverageReader(CoverageInfo ci) throws IOException, Exception { // get a reader for this coverage final CoverageStoreInfo store = (CoverageStoreInfo) ci.getStore(); final GridCoverageReader reader_ = ci.getGridCoverageReader(new DefaultProgressListener(), GeoTools.getDefaultHints()); if (reader_ == null) { throw new Exception( "Unable to acquire a reader for this coverage with format: " + store.getFormat().getName()); } final GridCoverage2DReader reader = (GridCoverage2DReader) reader_; return reader; }
@Override public void visit(CoverageStoreInfo coverageStore) { CoverageStoreInfo otherCoverageStore = otherCatalog.getCoverageStore(coverageStore.getId()); if (!(Objects.equals(coverageStore, otherCoverageStore) && Objects.equals(coverageStore.getType(), otherCoverageStore.getType()) && Objects.equals(coverageStore.getFormat(), otherCoverageStore.getFormat()) && Objects.equals(coverageStore.getURL(), otherCoverageStore.getURL()) && checkEquals(coverageStore.getMetadata(), otherCoverageStore.getMetadata()) && checkEquals( coverageStore.getConnectionParameters(), otherCoverageStore.getConnectionParameters()))) { differences.add(new InfoDiff(coverageStore, otherCoverageStore)); } }
private LayerInfo validateBasicLayerStructure( String workspace, String layerName, String[] expectedNames) { // check the configuration elements are there too Catalog catalog = getCatalog(); // ... the store CoverageStoreInfo store = catalog.getCoverageStoreByName(workspace, "test123"); assertNotNull(store); assertThat(store.getFormat(), instanceOf(ImageMosaicFormat.class)); // ... the layer LayerInfo layer = catalog.getLayerByName(layerName); assertNotNull(layer); final CoverageInfo coverageInfo = (CoverageInfo) layer.getResource(); assertThat(coverageInfo.getStore(), equalTo(store)); // ... the resource is time enabled DimensionInfo dimension = coverageInfo.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class); assertThat(dimension.getAttribute(), equalTo("timeStart")); assertThat(dimension.getDefaultValue().getStrategyType(), equalTo(Strategy.MAXIMUM)); // ... has the expected bands String[] names = coverageInfo .getDimensions() .stream() .map(cd -> cd.getName()) .toArray(String[]::new); assertThat(expectedNames, equalTo(names)); return layer; }
@Test public void testPostAsJSON() throws Exception { removeStore("wcs", "newCoverageStore"); File f = setupNewCoverageStore(); String json = "{'coverageStore':{" + "'name':'newCoverageStore'," + "'type': 'WorldImage'," + "'url':'" + f.getAbsolutePath().replace('\\', '/') + "'," + "'workspace':'wcs'," + "}" + "}"; MockHttpServletResponse response = postAsServletResponse( RestBaseController.ROOT_PATH + "/workspaces/wcs/coveragestores", json, "text/json"); assertEquals(201, response.getStatus()); assertNotNull(response.getHeader("Location")); assertTrue( response.getHeader("Location") .endsWith("/workspaces/wcs/coveragestores/newCoverageStore")); CoverageStoreInfo newCoverageStore = catalog.getCoverageStoreByName("newCoverageStore"); assertNotNull(newCoverageStore); assertNotNull(newCoverageStore.getFormat()); }
@Test public void testPostAsXML() throws Exception { removeStore("wcs", "newCoverageStore"); File f = setupNewCoverageStore(); String xml = "<coverageStore>" + "<name>newCoverageStore</name>" + "<type>WorldImage</type>" + "<url>file://" + f.getAbsolutePath() + "</url>" + "<workspace>wcs</workspace>" + "</coverageStore>"; MockHttpServletResponse response = postAsServletResponse( RestBaseController.ROOT_PATH + "/workspaces/wcs/coveragestores", xml, "text/xml"); assertEquals(201, response.getStatus()); assertNotNull(response.getHeader("Location")); assertTrue( response.getHeader("Location") .endsWith("/workspaces/wcs/coveragestores/newCoverageStore")); CoverageStoreInfo newCoverageStore = catalog.getCoverageStoreByName("newCoverageStore"); assertNotNull(newCoverageStore); assertNotNull(newCoverageStore.getFormat()); }
assertEquals("GeoTIFF", store.getFormat().getName());