@Override public ReferencedEnvelope getBounds() { return delegate.getBounds(); }
private static void allStyles(LayerGroupInfo group, List<StyleInfo> styles) { if (LayerGroupInfo.Mode.EO.equals(group.getMode())) { styles.add(group.getRootLayerStyle()); } int size = group.getLayers().size(); for (int i = 0; i < size; i++) { PublishedInfo p = group.getLayers().get(i); StyleInfo s = group.getStyles().get(i); if (p instanceof LayerInfo) { styles.add(group.getStyles().get(i)); } else if (p instanceof LayerGroupInfo) { allStyles((LayerGroupInfo) p, styles); } else if (p == null && s != null) { expandStyleGroup( s, group.getBounds() == null ? null : group.getBounds().getCoordinateReferenceSystem(), null, styles); } } }
private static void allLayers(LayerGroupInfo group, List<LayerInfo> layers) { if (LayerGroupInfo.Mode.EO.equals(group.getMode())) { layers.add(group.getRootLayer()); } int size = group.getLayers().size(); for (int i = 0; i < size; i++) { PublishedInfo p = group.getLayers().get(i); StyleInfo s; // Handle incomplete layer groups, especially those constructed by the XStreamPersister if (group.getStyles() == null || group.getStyles().size() == 0) { s = null; } else { s = group.getStyles().get(i); } if (p instanceof LayerInfo) { LayerInfo l = (LayerInfo) p; layers.add(l); } else if (p instanceof LayerGroupInfo) { allLayers((LayerGroupInfo) p, layers); } else if (p == null && s != null) { expandStyleGroup( s, group.getBounds() == null ? null : group.getBounds().getCoordinateReferenceSystem(), layers, null); } } }
@Test public void testUseCRSBounds() throws NoSuchAuthorityCodeException, FactoryException { // this test is almost trivial since the code itself is trivial CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); LayerGroupHelper helper = new LayerGroupHelper(nested); helper.calculateBoundsFromCRS(targetCRS); // layer group bounds should now match target CRS bounds assertEquals(nested.getBounds(), new ReferencedEnvelope(CRS.getEnvelope(targetCRS))); // null CRS should get null bounds helper.calculateBoundsFromCRS(null); assertEquals(nested.getBounds(), null); }
@Test public void testBounds() throws Exception { // plain group new LayerGroupHelper(ponds).calculateBounds(); assertEquals(ponds.getBounds(), ponds.getBounds()); // EO group ReferencedEnvelope eoExpected = aggregateEnvelopes(roadSegmentsLayer, lakesLayer, neatlineLayer); new LayerGroupHelper(lakesNeatline).calculateBounds(); ReferencedEnvelope eoActual = lakesNeatline.getBounds(); assertEquals(eoExpected, eoActual); // nested group ReferencedEnvelope nestedExpected = aggregateEnvelopes( forestLayer, roadSegmentsLayer, lakesLayer, neatlineLayer, buildingsLayer, pondsLayer); new LayerGroupHelper(nested).calculateBounds(); assertEquals(nestedExpected, nested.getBounds()); }
@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()); }
@Test public void testBoundsCRS() throws Exception { CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:32628", true); ReferencedEnvelope nestedExpected = aggregateEnvelopes( forestLayer, roadSegmentsLayer, lakesLayer, neatlineLayer, buildingsLayer, pondsLayer); nestedExpected = nestedExpected.transform(targetCRS, true); new LayerGroupHelper(nested).calculateBounds(targetCRS); assertEquals(nestedExpected, nested.getBounds()); }
if (!(obj instanceof LayerGroupInfo)) return false; LayerGroupInfo other = (LayerGroupInfo) obj; if (lg.getBounds() == null) { if (other.getBounds() != null) return false; } else if (!lg.getBounds().equals(other.getBounds())) return false; if (lg.getId() == null) { if (other.getId() != null) return 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()); }
@Test public void testSingleStyleGroup() throws Exception { Catalog catalog = getCatalog(); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); StyleInfo s = catalog.getStyleByName("singleStyleGroup"); lg.setWorkspace(null); lg.setName("singleStyleLayerGroup"); lg.getLayers().add(null); lg.getStyles().add(s); catalog.add(lg); LayerGroupInfo resolved = catalog.getLayerGroupByName("singleStyleLayerGroup"); assertEquals(1, resolved.layers().size()); assertEquals(1, resolved.styles().size()); assertEquals(s.getStyle(), resolved.styles().get(0).getStyle()); // Test bounds calculation new LayerGroupHelper(lg).calculateBounds(); assertEquals( catalog.getLayerByName((getLayerId(MockData.STREAMS))) .getResource() .getLatLonBoundingBox(), lg.getBounds()); }
assertEquals( new ReferencedEnvelope(-180, 180, -90, 90, DefaultGeographicCRS.WGS84), lg.getBounds());
@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)); }
public Map getBaseMapEnvelopes() { HashMap baseMapEnvelopes = new HashMap(); for ( LayerGroupInfo map : gs.getCatalog().getLayerGroups() ) { baseMapEnvelopes.put( map.getName(), new GeneralEnvelope( map.getBounds() ) ); } return baseMapEnvelopes; //return baseMapEnvelopes != null ? baseMapEnvelopes : Collections.EMPTY_MAP; }
public CoordinateReferenceSystem getDeclaredCrs(final String geoServerTileLayerName) { GeoServerTileLayer layer = (GeoServerTileLayer) getTileLayerByName(geoServerTileLayerName); LayerInfo layerInfo = layer.getLayerInfo(); if (layerInfo != null) { return layerInfo.getResource().getCRS(); } LayerGroupInfo layerGroupInfo = layer.getLayerGroupInfo(); ReferencedEnvelope bounds = layerGroupInfo.getBounds(); return bounds.getCoordinateReferenceSystem(); }