@Override public ReferencedEnvelope getBounds() { try { ReferencedEnvelope bounds = featureSource.getBounds(); if (bounds != null) { FeatureType schema = featureSource.getSchema(); CoordinateReferenceSystem schemaCrs = schema.getCoordinateReferenceSystem(); CoordinateReferenceSystem boundsCrs = bounds.getCoordinateReferenceSystem(); if (boundsCrs == null && schemaCrs != null) { LOGGER.warning( "Bounds crs not defined; assuming bounds from schema are correct for " + featureSource); bounds = new ReferencedEnvelope( bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY(), schemaCrs); } if (boundsCrs != null && schemaCrs != null && !CRS.equalsIgnoreMetadata(boundsCrs, schemaCrs)) { LOGGER.warning( "Bounds crs and schema crs are not consistent; forcing the use of the schema crs so they are consistent"); // bounds = bounds.transform(schemaCrs, true ); bounds = new ReferencedEnvelope( bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY(), schemaCrs); } return bounds; } } catch (IOException e) { // feature bounds unavailable } CoordinateReferenceSystem crs = featureSource.getSchema().getCoordinateReferenceSystem(); if (crs != null) { // returns the envelope based on the CoordinateReferenceSystem Envelope envelope = CRS.getEnvelope(crs); if (envelope != null) { return new ReferencedEnvelope(envelope); // nice! } else { return new ReferencedEnvelope(crs); // empty bounds } } else { return null; // unknown } }
public void update(Object updatedObject) { if (updatedObject instanceof List) { String text = null; List layers = (List) updatedObject; for (Object layer : layers) { if (layer instanceof JGrassMapGeoResource) { JGrassMapGeoResource rasterMapResource = (JGrassMapGeoResource) layer; try { text = rasterMapResource.getInfo(null).getName(); JGrassRegion fileWindow = rasterMapResource.getFileWindow(); if (fileWindow != null) { setWidgetsToWindow(fileWindow); } } catch (IOException e1) { return; } } else if (layer instanceof DataStore || layer instanceof UDIGFeatureStore) { try { DataStore store = ((DataStore) layer); FeatureSource featureStore = store.getFeatureSource(store.getTypeNames()[0]); Envelope envelope = featureStore.getBounds(); ActiveRegionStyle style = getActiveRegionStyle(); JGrassRegion activeWindow = new JGrassRegion( style.west, style.east, style.south, style.north, style.rows, style.cols); JGrassRegion newWindow = JGrassRegion.adaptActiveRegionToEnvelope(envelope, activeWindow); northText.setText(String.valueOf(newWindow.getNorth())); southText.setText(String.valueOf(newWindow.getSouth())); eastText.setText(String.valueOf(newWindow.getEast())); westText.setText(String.valueOf(newWindow.getWest())); textModified(bound_type); } catch (IOException e1) { e1.printStackTrace(); return; } } else { return; } } if (text == null) { return; } } }