01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.feature;
06:
07: import com.vividsolutions.jts.geom.Envelope;
08: import org.geotools.data.FeatureSource;
09: import java.io.IOException;
10: import java.util.logging.Level;
11: import java.util.logging.Logger;
12:
13: /**
14: * Set of utility methods for {@link org.geotools.data.FeatureSource}.
15: *
16: * @author Justin Deoliveira, The Open Planning Project, jdeolive@openplans.org
17: *
18: */
19: public class FeatureSourceUtils {
20: protected static final Logger LOGGER = org.geotools.util.logging.Logging
21: .getLogger("org.vfny.geoserver.feature");
22:
23: /**
24: * Retreives the bounds for a feature source.
25: * <p>
26: * If the feautre source can calculate the bounds directly, those bounds
27: * are returned. Otherwise, the underlying feature collection is retreived
28: * and asked to calculate bounds. If that fails, an empty envelope is
29: * returned.
30: * </p>
31: *
32: * @param fs The feature source.
33: *
34: * @return The bounds.
35: *
36: * @throws IOException Execption calculating bounds on feature source.
37: */
38: public static Envelope getBoundingBoxEnvelope(FeatureSource fs)
39: throws IOException {
40: Envelope ev = fs.getBounds();
41:
42: if ((ev == null) || ev.isNull()) {
43: try {
44: ev = fs.getFeatures().getBounds();
45: } catch (Throwable t) {
46: LOGGER
47: .log(
48: Level.FINE,
49: "Could not compute the data bounding box. Returning an empty envelope",
50: t);
51: ev = new Envelope();
52: }
53: }
54:
55: return ev;
56: }
57: }
|