private LayerGroupInfo addLayerGroup( String name, Mode mode, WorkspaceInfo ws, PublishedInfo... layers) throws Exception { CatalogBuilder cb = new CatalogBuilder(catalog); LayerGroupInfo group = catalog.getFactory().createLayerGroup(); group.setName(name); group.setMode(mode); if (ws != null) { group.setWorkspace(ws); } if (layers != null) { for (PublishedInfo layer : layers) { group.getLayers().add(layer); group.getStyles().add(null); } } cb.calculateLayerGroupBounds(group); catalog.add(group); if (ws != null) { return catalog.getLayerGroupByName(ws.getName(), name); } else { return catalog.getLayerGroupByName(name); } }
@Test public void testEmptyLayerGroupBounds() throws Exception { Catalog cat = getCatalog(); LayerGroupInfo group = cat.getFactory().createLayerGroup(); group.setName("empty_group"); assertNull(group.getBounds()); // force bounds computation CatalogBuilder cb = new CatalogBuilder(cat); cb.calculateLayerGroupBounds(group); assertNull(group.getBounds()); }
lg.getStyles().add(null); lg.getStyles().add(null); cb.calculateLayerGroupBounds(lg); lg.setName("test-lg"); lg.setWorkspace(ws);
@Test public void testReprojectLayerGroup() throws NoSuchAuthorityCodeException, FactoryException, Exception { Catalog catalog = getCatalog(); CatalogBuilder cb = new CatalogBuilder(catalog); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); LayerInfo l = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS)); lg.getLayers().add(l); lg.getStyles().add(null); lg.setName("test-reproject"); // EPSG:4901 "equivalent" but different uom String wkt = "GEOGCS[\"GCS_ATF_Paris\",DATUM[\"D_ATF\",SPHEROID[\"Plessis_1817\",6376523.0,308.64]],PRIMEM[\"Paris\",2.337229166666667],UNIT[\"Grad\",0.01570796326794897]]"; CoordinateReferenceSystem lCrs = CRS.parseWKT(wkt); ((FeatureTypeInfo) l.getResource()).setSRS(null); ((FeatureTypeInfo) l.getResource()).setNativeCRS(lCrs); assertNull(CRS.lookupEpsgCode(lCrs, false)); // Use the real thing now CoordinateReferenceSystem lgCrs = CRS.decode("EPSG:4901"); assertNotNull(CRS.lookupEpsgCode(lgCrs, false)); // Reproject our layer group to EPSG:4901. We expect it to have an EPSG code. cb.calculateLayerGroupBounds(lg, lgCrs); assertNotNull(CRS.lookupEpsgCode(lg.getBounds().getCoordinateReferenceSystem(), false)); }
@Test public void testLayerGroupBounds() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); cb.setupBounds(fti); LayerInfo layer = cat.getFactory().createLayer(); layer.setResource(fti); layer.setName(fti.getName()); layer.setEnabled(true); layer.setType(PublishedType.VECTOR); LayerGroupInfo group = cat.getFactory().createLayerGroup(); group.setName("group"); group.getLayers().add(layer); group.getStyles().add(null); assertNull(group.getBounds()); // force bounds computation cb.calculateLayerGroupBounds(group); assertNotNull(group.getBounds()); assertEquals(fti.getNativeBoundingBox(), group.getBounds()); }
@Test public void testLayerGroupEoBounds() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); cb.setupBounds(fti); LayerInfo layer = cat.getFactory().createLayer(); layer.setResource(fti); layer.setName(fti.getName()); layer.setEnabled(true); layer.setType(PublishedType.VECTOR); LayerGroupInfo group = cat.getFactory().createLayerGroup(); group.setMode(LayerGroupInfo.Mode.EO); group.setName("group_EO"); group.setRootLayer(layer); assertNull(group.getBounds()); // force bounds computation cb.calculateLayerGroupBounds(group); assertNotNull(group.getBounds()); assertEquals(fti.getNativeBoundingBox(), group.getBounds()); }
lg.getStyles().add(null); lg.getStyles().add(null); cb.calculateLayerGroupBounds(lg); lg.setName("test-lg"); catalog.add(lg);
@Override protected String handleObjectPost(Object object) throws Exception { String ws = getAttribute("workspace"); LayerGroupInfo lg = (LayerGroupInfo) object; LOGGER.info( "POST layer group " + lg.getName() + ws != null ? " to workspace " + ws : ""); if ( lg.getLayers().isEmpty() ) { throw new RestletException( "layer group must not be empty", Status.CLIENT_ERROR_BAD_REQUEST ); } if ( lg.getBounds() == null ) { LOGGER.fine( "Auto calculating layer group bounds"); new CatalogBuilder( catalog ).calculateLayerGroupBounds(lg); } if (ws != null) { lg.setWorkspace(catalog.getWorkspaceByName(ws)); } catalog.add( lg ); return lg.getName(); }
@Override public void onClick(AjaxRequestTarget target, Form<?> form) { // build a layer group with the current contents of the group LayerGroupInfo lg = getCatalog().getFactory().createLayerGroup(); for (LayerGroupEntry entry : lgEntryPanel.getEntries()) { lg.getLayers().add(entry.getLayer()); lg.getStyles().add(entry.getStyle()); } try { // grab the eventually manually inserted CoordinateReferenceSystem crs = envelopePanel.getCoordinateReferenceSystem(); if (crs != null) { // ensure the bounds calculated in terms of the user specified // crs new CatalogBuilder(getCatalog()) .calculateLayerGroupBounds(lg, crs); } else { // calculate from scratch new CatalogBuilder(getCatalog()).calculateLayerGroupBounds(lg); } envelopePanel.setModelObject(lg.getBounds()); target.add(envelopePanel); } catch (Exception e) { throw new WicketRuntimeException(e); } } });
LayerGroupInfo createLayerGroup(Catalog cat, String name, String title, PublishedInfo... layers) throws Exception { LayerGroupInfo group = cat.getFactory().createLayerGroup(); group.setName(name); group.setTitle("title for layer group " + title); group.setAbstract("abstract for layer group " + title); for (PublishedInfo layer : layers) { group.getLayers().add(layer); group.getStyles().add(null); } new CatalogBuilder(cat).calculateLayerGroupBounds(group); return group; }
LayerGroupInfo createLayerGroup(Catalog cat, String name, String title, PublishedInfo... layers) throws Exception { LayerGroupInfo group = cat.getFactory().createLayerGroup(); group.setName(name); group.setTitle("title for layer group " + title); group.setAbstract("abstract for layer group " + title); for (PublishedInfo layer : layers) { group.getLayers().add(layer); group.getStyles().add(null); } new CatalogBuilder(cat).calculateLayerGroupBounds(group); return group; }
protected void setupOpaqueGroup(Catalog catalog) throws Exception { // setup an opaque group too LayerGroupInfo opaqueGroup = catalog.getFactory().createLayerGroup(); LayerInfo roadSegments = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS)); LayerInfo neatline = catalog.getLayerByName(getLayerId(MockData.MAP_NEATLINE)); if (roadSegments != null && neatline != null) { opaqueGroup.setName(OPAQUE_GROUP); opaqueGroup.setMode(Mode.OPAQUE_CONTAINER); opaqueGroup.getLayers().add(roadSegments); opaqueGroup.getLayers().add(neatline); opaqueGroup.getStyles().add(null); opaqueGroup.getStyles().add(null); CatalogBuilder cb = new CatalogBuilder(catalog); cb.calculateLayerGroupBounds(opaqueGroup); catalog.add(opaqueGroup); } }
@Override protected void onSetUp(SystemTestData testData) throws Exception { super.onSetUp(testData); Catalog catalog = getCatalog(); String lakes = MockData.LAKES.getLocalPart(); String forests = MockData.FORESTS.getLocalPart(); String bridges = MockData.BRIDGES.getLocalPart(); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.setName("lakesGroup"); lg.getLayers().add(catalog.getLayerByName(lakes)); lg.getStyles().add(catalog.getStyleByName(lakes)); lg.getLayers().add(catalog.getLayerByName(forests)); lg.getStyles().add(catalog.getStyleByName(forests)); lg.getLayers().add(catalog.getLayerByName(bridges)); lg.getStyles().add(catalog.getStyleByName(bridges)); CatalogBuilder builder = new CatalogBuilder(catalog); builder.calculateLayerGroupBounds(lg); catalog.add(lg); // makes the lakes layer a multi-style one LayerInfo lakesLayer = catalog.getLayerByName(getLayerId(MockData.LAKES)); lakesLayer.getStyles().add(catalog.getStyleByName(MockData.FORESTS.getLocalPart())); catalog.save(lakesLayer); }
@Override protected void oneTimeSetUp() throws Exception { super.oneTimeSetUp(); CatalogFactory cf = getCatalog().getFactory(); CatalogBuilder cb = new CatalogBuilder(getCatalog()); LayerGroupInfo gi = cf.createLayerGroup(); gi.setName("testGroup"); gi.getLayers().add(getCatalog().getLayerByName(MockData.BASIC_POLYGONS.getLocalPart())); gi.getStyles().add(getCatalog().getStyleByName("polygon")); cb.calculateLayerGroupBounds(gi); getCatalog().add(gi); LayerGroupInfo gi2 = cf.createLayerGroup(); gi2.setName("testGroup2"); gi2.getLayers().add(getCatalog().getLayerByName(MockData.BASIC_POLYGONS.getLocalPart())); gi2.getStyles().add(getCatalog().getStyleByName("raster")); gi2.getLayers().add(getCatalog().getLayerByName(MockData.BUILDINGS.getLocalPart())); gi2.getStyles().add(getCatalog().getStyleByName("raster")); cb.calculateLayerGroupBounds(gi2); getCatalog().add(gi2); }
@Override protected void oneTimeSetUp() throws Exception { super.oneTimeSetUp(); CatalogFactory cf = getCatalog().getFactory(); CatalogBuilder cb = new CatalogBuilder(getCatalog()); LayerGroupInfo gi = cf.createLayerGroup(); gi.setName("testGroup"); gi.getLayers().add(getCatalog().getLayerByName(MockData.BASIC_POLYGONS.getLocalPart())); gi.getStyles().add(getCatalog().getStyleByName("polygon")); cb.calculateLayerGroupBounds(gi); getCatalog().add(gi); }
@Override protected void oneTimeSetUp() throws Exception { super.oneTimeSetUp(); CatalogFactory cf = getCatalog().getFactory(); CatalogBuilder cb = new CatalogBuilder(getCatalog()); LayerGroupInfo gi = cf.createLayerGroup(); gi.setName("testGroup"); gi.getLayers().add(getCatalog().getLayerByName(MockData.BASIC_POLYGONS.getLocalPart())); gi.getStyles().add(getCatalog().getStyleByName("polygon")); cb.calculateLayerGroupBounds(gi); getCatalog().add(gi); LayerGroupInfo gi2 = cf.createLayerGroup(); gi2.setName("testGroup2"); gi2.getLayers().add(getCatalog().getLayerByName(MockData.BASIC_POLYGONS.getLocalPart())); gi2.getStyles().add(getCatalog().getStyleByName("raster")); gi2.getLayers().add(getCatalog().getLayerByName(MockData.BUILDINGS.getLocalPart())); gi2.getStyles().add(getCatalog().getStyleByName("raster")); cb.calculateLayerGroupBounds(gi2); getCatalog().add(gi2); }
protected LayerGroupInfo createLakesPlacesLayerGroup( Catalog catalog, String name, LayerGroupInfo.Mode mode, LayerInfo rootLayer) throws Exception { LayerInfo lakes = catalog.getLayerByName(getLayerId(MockData.LAKES)); LayerInfo places = catalog.getLayerByName(getLayerId(MockData.NAMED_PLACES)); LayerGroupInfo group = catalog.getFactory().createLayerGroup(); group.setName(name); group.setMode(mode); if (rootLayer != null) { group.setRootLayer(rootLayer); group.setRootLayerStyle(rootLayer.getDefaultStyle()); } group.getLayers().add(lakes); group.getLayers().add(places); group.getStyles().add(null); group.getStyles().add(null); CatalogBuilder cb = new CatalogBuilder(catalog); cb.calculateLayerGroupBounds(group); catalog.add(group); return group; }
public void testLayerGroupNamesPrefixed() throws Exception { Catalog cat = getCatalog(); LayerGroupInfo lg = cat.getFactory().createLayerGroup(); lg.setName("foo"); lg.setWorkspace(cat.getWorkspaceByName("sf")); lg.getLayers().add(cat.getLayerByName(getLayerId(MockData.PRIMITIVEGEOFEATURE))); new CatalogBuilder(cat).calculateLayerGroupBounds(lg); cat.add(lg); tester.startPage(MapPreviewPage.class); tester.assertRenderedPage(MapPreviewPage.class); //move to next page tester.clickLink("table:navigatorBottom:navigator:next", true); DataView data = (DataView) tester.getComponentFromLastRenderedPage("table:listContainer:items"); boolean exists = false; for (Iterator it = data.iterator(); it.hasNext(); ) { MarkupContainer c = (MarkupContainer) it.next(); Label l = (Label) c.get("itemProperties:1:component"); if ("sf:foo".equals(l.getDefaultModelObjectAsString())) { exists = true; } } assertTrue(exists); }
@Test public void testLayerGroupNamesPrefixed() throws Exception { Catalog cat = getCatalog(); LayerGroupInfo lg = cat.getFactory().createLayerGroup(); lg.setName("foo"); lg.setWorkspace(cat.getWorkspaceByName("sf")); lg.getLayers().add(cat.getLayerByName(getLayerId(MockData.PRIMITIVEGEOFEATURE))); new CatalogBuilder(cat).calculateLayerGroupBounds(lg); cat.add(lg); tester.startPage(MapPreviewPage.class); tester.assertRenderedPage(MapPreviewPage.class); // move to next page GeoServerTablePanel table = (GeoServerTablePanel) tester.getComponentFromLastRenderedPage("table"); System.out.println(table.getDataProvider().size()); tester.clickLink("table:navigatorBottom:navigator:next", true); DataView data = (DataView) tester.getComponentFromLastRenderedPage("table:listContainer:items"); boolean exists = false; for (Iterator it = data.iterator(); it.hasNext(); ) { MarkupContainer c = (MarkupContainer) it.next(); Label l = (Label) c.get("itemProperties:2:component"); String model = l.getDefaultModelObjectAsString(); if ("sf:foo".equals(model)) { exists = true; } } assertTrue(exists); }
/** Helper method that creates a layer group using the provided name, workspace and layers. */ private LayerGroupInfo createLayerGroup( WorkspaceInfo workspace, String layerGroupName, LayerInfo... layers) throws Exception { // create a new layer group using the provided name LayerGroupInfo layerGroup = getCatalog().getFactory().createLayerGroup(); layerGroup.setName(layerGroupName); // set workspace layerGroup.setWorkspace(workspace); // add the provided layers for (LayerInfo layerInfo : layers) { layerGroup.getLayers().add(layerInfo); layerGroup.getStyles().add(null); } // set the layer group bounds by merging all layers bounds CatalogBuilder catalogBuilder = new CatalogBuilder(getCatalog()); catalogBuilder.calculateLayerGroupBounds(layerGroup); getCatalog().add(layerGroup); // retrieve the created layer group by name if (workspace == null) { return getCatalog().getLayerGroupByName(layerGroupName); } return getCatalog().getLayerGroupByName(workspace, layerGroupName); } }