try {
@SuppressWarnings("unchecked")
FeatureSource<SimpleFeatureType, SimpleFeature> source = owner
.resolve(FeatureSource.class, new NullProgressMonitor());
ReferencedEnvelope temp = source.getBounds();
bounds = temp;
if (bounds == null) {
CoordinateReferenceSystem crs = getCRS();
// try getting an envelope out of the crs
org.opengis.geometry.Envelope envelope = CRS
.getEnvelope(crs);
if (envelope != null) {
bounds = new ReferencedEnvelope(new Envelope(envelope
.getLowerCorner().getOrdinate(0), envelope
.getUpperCorner().getOrdinate(0), envelope
.getLowerCorner().getOrdinate(1), envelope
.getUpperCorner().getOrdinate(1)), crs);
} else {
// TODO: perhaps access a preference which indicates
// whether to do a full table scan
// bounds = new ReferencedEnvelope(new Envelope(),crs);
// as a last resort do the full scan
bounds = new ReferencedEnvelope(new Envelope(), crs);
FeatureIterator<SimpleFeature> iter = source
.getFeatures().features();
try {
while (iter.hasNext()) {
SimpleFeature element = iter.next();
if (bounds.isNull())
bounds.init(element.getBounds());
else
bounds.include(element.getBounds());
}
} finally {
iter.close();
}
}
}
} catch (DataSourceException e) {
Activator.log(
"Exception while generating TeradataGeoResource.", e); //$NON-NLS-1$
} catch (Exception e) {
CatalogPlugin
.getDefault()
.getLog()
.log(new org.eclipse.core.runtime.Status(
IStatus.WARNING,
"org.locationtech.udig.catalog", 0, Messages.TeradataGeoResource_error_layer_bounds, e)); //$NON-NLS-1$
bounds = new ReferencedEnvelope(new Envelope(), null);
}
}
return bounds;
}