Refine search
private void configureBandsFlagsOnCatalog(Catalog cat) throws Exception { final CoverageStoreInfo storeInfo = cat.getCoverageStoreByName("bands-flags"); final CoverageView coverageView = buildBandsFlagsView(); final CatalogBuilder builder = new CatalogBuilder(cat); builder.setStore(storeInfo); final CoverageInfo coverageInfo = coverageView.createCoverageInfo(BANDS_FLAGS_VIEW, storeInfo, builder); coverageInfo.getParameters().put("USE_JAI_IMAGEREAD", "false"); cat.add(coverageInfo); }
private void configureIROnCatalog(Catalog cat) throws Exception { final CoverageStoreInfo storeInfo = cat.getCoverageStoreByName("ir-rgb"); final CoverageView coverageView = buildRgbIRView(); final CatalogBuilder builder = new CatalogBuilder(cat); builder.setStore(storeInfo); final CoverageInfo coverageInfo = coverageView.createCoverageInfo(RGB_IR_VIEW, storeInfo, builder); coverageInfo.getParameters().put("USE_JAI_IMAGEREAD", "false"); coverageInfo.getDimensions().get(0).setName("Red"); coverageInfo.getDimensions().get(1).setName("Green"); coverageInfo.getDimensions().get(2).setName("Blue"); coverageInfo.getDimensions().get(3).setName("Infrared"); cat.add(coverageInfo); }
/** Keys for overriding default layer properties */ public static class StyleProperty<T> { T get(Map<StyleProperty, Object> map, T def) { return map != null && map.containsKey(this) ? (T) map.get(this) : def; } public static StyleProperty<String> FORMAT = new StyleProperty<String>(); public static StyleProperty<Version> FORMAT_VERSION = new StyleProperty<Version>(); public static StyleProperty<LegendInfo> LEGEND_INFO = new StyleProperty<LegendInfo>(); }
@Test public void testGenericStyle() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.GENERICENTITY.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.GENERICENTITY)); LayerInfo li = cb.buildLayer(fti); // check we assigned the generic style assertEquals("generic", li.getDefaultStyle().getName()); }
@Test public void testLargeNDMosaic() throws Exception { // build a mosaic with 1025 files (the standard ulimit is 1024) File mosaic = new File("./target/largeMosaic"); try { createTimeMosaic(mosaic, 1025); // now configure a new store based on it Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); CoverageStoreInfo store = cb.buildCoverageStore("largeMosaic"); store.setURL(mosaic.getAbsolutePath()); store.setType("ImageMosaic"); cat.add(store); // and configure also the coverage cb.setStore(store); CoverageInfo ci = cb.buildCoverage(); cat.add(ci); cat.getResourcePool().dispose(); } finally { if (mosaic.exists() && mosaic.isDirectory()) { FileUtils.deleteDirectory(mosaic); } } }
@Test public void testMetadataFromFeatueSource() throws Exception { CatalogBuilder cb = new CatalogBuilder(getCatalog()); cb.setStore(cb.buildDataStore("fooStore")); FeatureType ft = createMock(FeatureType.class); expect(ft.getName()).andReturn(new NameImpl("foo")).anyTimes(); expect(ft.getCoordinateReferenceSystem()).andReturn(null).anyTimes(); expect(ft.getGeometryDescriptor()).andReturn(null).anyTimes(); replay(ft); ResourceInfo rInfo = createMock(ResourceInfo.class); expect(rInfo.getTitle()).andReturn("foo title"); expect(rInfo.getDescription()).andReturn("foo description"); expect(rInfo.getKeywords()) .andReturn(new LinkedHashSet<String>(Arrays.asList("foo", "bar", "baz", ""))) .anyTimes(); replay(rInfo); FeatureSource fs = createMock(FeatureSource.class); expect(fs.getSchema()).andReturn(ft).anyTimes(); expect(fs.getInfo()).andReturn(rInfo).anyTimes(); expect(fs.getName()).andReturn(ft.getName()).anyTimes(); replay(fs); FeatureTypeInfo ftInfo = cb.buildFeatureType(fs); assertEquals("foo title", ftInfo.getTitle()); assertEquals("foo description", ftInfo.getDescription()); assertTrue(ftInfo.getKeywords().contains(new Keyword("foo"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("bar"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("baz"))); }
@Test public void testPreserveCoverageBandNames() throws Exception { final Catalog cat = getCatalog(); final CoverageStoreInfo storeInfo = cat.getCoverageStoreByName("ir-rgb"); final CoverageView coverageView = buildRgbIRView(); final CatalogBuilder builder = new CatalogBuilder(cat); builder.setStore(storeInfo); final CoverageInfo coverageInfo = coverageView.createCoverageInfo(RGB_IR_VIEW, storeInfo, builder); List<CoverageDimensionInfo> dimensions = coverageInfo.getDimensions(); assertEquals("rband", dimensions.get(0).getName()); assertEquals("gband", dimensions.get(1).getName()); assertEquals("bband", dimensions.get(2).getName()); assertEquals("irband", dimensions.get(3).getName()); }
private CoverageInfo buildHeterogeneousResolutionView( String name, Consumer<CoverageView> viewCustomizer, String... coverageNames) throws Exception { List<CoverageBand> bands = new ArrayList<>(); int bandIdx = 0; for (String coverageName : coverageNames) { CoverageBand band = new CoverageBand( Arrays.asList(new InputCoverageBand(coverageName, "0")), coverageName, bandIdx++, CompositionType.BAND_SELECT); bands.add(band); } final CoverageView coverageView = new CoverageView(name, bands); viewCustomizer.accept(coverageView); final Catalog cat = getCatalog(); final CoverageStoreInfo storeInfo = cat.getCoverageStoreByName("s2reduced"); final CatalogBuilder builder = new CatalogBuilder(cat); builder.setStore(storeInfo); final CoverageInfo coverageInfo = coverageView.createCoverageInfo(name, storeInfo, builder); coverageInfo.getParameters().put("USE_JAI_IMAGEREAD", "false"); cat.add(coverageInfo); return cat.getCoverage(coverageInfo.getId()); }
@Test public void testNativeBoundsDefensiveCopy() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getCoverageStoreByName(MockData.TASMANIA_DEM.getLocalPart())); CoverageInfo ci = cb.buildCoverage(); // setup the reproject to declared policy, the issue happens only under this condition ReferencedEnvelope nativeBounds = ci.getNativeBoundingBox(); for (ProjectionPolicy pp : ProjectionPolicy.values()) { ci.setProjectionPolicy(pp); ReferencedEnvelope bbox = ci.boundingBox(); assertNotSame(nativeBounds, bbox); } }
@Test public void testMosaicParameters() throws Exception { // build a mosaic with 1025 files (the standard ulimit is 1024) File mosaic = new File("./target/smallMosaic"); try { createTimeMosaic(mosaic, 4); // now configure a new store based on it Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); CoverageStoreInfo store = cb.buildCoverageStore("smallMosaic"); store.setURL(mosaic.getAbsolutePath()); store.setType("ImageMosaic"); cat.add(store); // and configure also the coverage cb.setStore(store); CoverageInfo ci = cb.buildCoverage(); cat.add(ci); // check the parameters have the default values assertEquals( String.valueOf(-1), ci.getParameters() .get(ImageMosaicFormat.MAX_ALLOWED_TILES.getName().toString())); assertEquals("", ci.getParameters().get(ImageMosaicFormat.FILTER.getName().toString())); cat.getResourcePool().dispose(); } finally { if (mosaic.exists() && mosaic.isDirectory()) { FileUtils.deleteDirectory(mosaic); } } }
CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(csi); CoverageInfo ci = cb.buildCoverage();
@Test public void testInitCoverageSRSLookup_GEOS8973() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getCoverageStoreByName(MockData.WORLD.getLocalPart())); CoverageInfo cinfo = cb.buildCoverage(); cinfo.setSRS(null); String wkt = "GEOGCS[\"ED50\",\n" + " DATUM[\"European Datum 1950\",\n" + " SPHEROID[\"International 1924\", 6378388.0, 297.0]],\n" + "PRIMEM[\"Greenwich\", 0.0],\n" + "UNIT[\"degree\", 0.017453292519943295]]"; CoordinateReferenceSystem testCRS = CRS.parseWKT(wkt); cinfo.setNativeCRS(testCRS); cb.initCoverage(cinfo, "srs lookup"); assertEquals("EPSG:4230", cinfo.getSRS()); }
private LayerInfo buildLayer(QName resourceName) throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); StoreInfo store = cat.getDataStoreByName(resourceName.getPrefix()); cb.setStore(store); ResourceInfo ri = cb.buildFeatureType(toName(resourceName)); ri.setSRS("EPSG:4326"); cb.setupBounds(ri); LayerInfo layer = cat.getFactory().createLayer(); layer.setResource(ri); layer.setName(ri.getName()); layer.setEnabled(true); layer.setType(PublishedType.VECTOR); return layer; }
@Test public void testGetBoundsFromCRS() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); CoordinateReferenceSystem resourceCRS = fti.getCRS(); assertNotNull(resourceCRS); // make sure the srs is as expected, otherwise the rest of the tests don't make sense assertEquals("EPSG:32615", fti.getSRS()); ReferencedEnvelope crsBounds = cb.getBoundsFromCRS(fti); assertNotNull(crsBounds); CoordinateReferenceSystem exptectedCRS = CRS.decode("EPSG:32615"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we change the srs when there's no reproject policy, should still be the same bounding // box fti.setSRS("EPSG:4326"); fti.setProjectionPolicy(ProjectionPolicy.NONE); crsBounds = cb.getBoundsFromCRS(fti); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we use reproject policy, bounds should now be different fti.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); crsBounds = cb.getBoundsFromCRS(fti); assertNotEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // should now be 4326 bounds CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); fti.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); }
@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()); }
CatalogBuilder cb = new CatalogBuilder(new CatalogImpl()); cb.setStore(cs);
CatalogBuilder builder = new CatalogBuilder(catalog); builder.setStore( catalog.getStoreByName( MockData.CITE_PREFIX, MockData.CITE_PREFIX, DataStoreInfo.class));
@Test public void testWMSLayer130crs84() throws Exception { TestHttpClientProvider.startTest(); try { String baseURL = TestHttpClientProvider.MOCKSERVER + "/wms13"; MockHttpClient client = new MockHttpClient(); URL capsURL = new URL(baseURL + "?service=WMS&request=GetCapabilities&version=1.3.0"); client.expectGet( capsURL, new MockHttpResponse(getClass().getResource("caps130_crs84.xml"), "text/xml")); TestHttpClientProvider.bind(client, capsURL); CatalogBuilder cb = new CatalogBuilder(getCatalog()); WMSStoreInfo store = cb.buildWMSStore("test-store"); store.setCapabilitiesURL(capsURL.toExternalForm()); cb.setStore(store); WMSLayerInfo layer = cb.buildWMSLayer("world4326"); // check the bbox has the proper axis order assertEquals("EPSG:4326", layer.getSRS()); ReferencedEnvelope bbox = layer.getLatLonBoundingBox(); assertEquals(-180, bbox.getMinX(), 0d); assertEquals(-90, bbox.getMinY(), 0d); assertEquals(180, bbox.getMaxX(), 0d); assertEquals(90, bbox.getMaxY(), 0d); } finally { TestHttpClientProvider.endTest(); } }
@Test public void testDropCoverageStore() throws Exception { // build the store Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); CoverageStoreInfo store = cb.buildCoverageStore("dem"); store.setURL(MockData.class.getResource("tazdem.tiff").toExternalForm()); store.setType("GeoTIFF"); cat.add(store); // build the coverage cb.setStore(store); CoverageInfo ci = cb.buildCoverage(); cat.add(ci); // build the layer LayerInfo layer = cb.buildLayer(ci); cat.add(layer); // grab a reader just to inizialize the code ci.getGridCoverage(null, null); ci.getGridCoverageReader(null, GeoTools.getDefaultHints()); // now drop the store CascadeDeleteVisitor visitor = new CascadeDeleteVisitor(cat); visitor.visit(store); // and reload (GEOS-4782 -> BOOM!) getGeoServer().reload(); }
@Test public void testWMSLayer130() throws Exception { TestHttpClientProvider.startTest(); try { String baseURL = TestHttpClientProvider.MOCKSERVER + "/wms13"; MockHttpClient client = new MockHttpClient(); URL capsURL = new URL(baseURL + "?service=WMS&request=GetCapabilities&version=1.3.0"); client.expectGet( capsURL, new MockHttpResponse(getClass().getResource("caps130.xml"), "text/xml")); TestHttpClientProvider.bind(client, capsURL); CatalogBuilder cb = new CatalogBuilder(getCatalog()); WMSStoreInfo store = cb.buildWMSStore("test-store"); store.setCapabilitiesURL(capsURL.toExternalForm()); cb.setStore(store); WMSLayerInfo layer = cb.buildWMSLayer("world4326"); // check the bbox has the proper axis order assertEquals("EPSG:4326", layer.getSRS()); ReferencedEnvelope bbox = layer.getLatLonBoundingBox(); assertEquals(-180, bbox.getMinX(), 0d); assertEquals(-90, bbox.getMinY(), 0d); assertEquals(180, bbox.getMaxX(), 0d); assertEquals(90, bbox.getMaxY(), 0d); } finally { TestHttpClientProvider.endTest(); } }