Index: main/src/main/java/org/geoserver/catalog/CatalogBuilder.java
===================================================================
--- main/src/main/java/org/geoserver/catalog/CatalogBuilder.java (revision 16153)
+++ main/src/main/java/org/geoserver/catalog/CatalogBuilder.java (working copy)
@@ -531,18 +531,28 @@
}
/**
+ * Initializes basic resource info.
+ */
+ private void initResourceInfo(ResourceInfo resInfo) throws Exception {
+ // set the name
+ if (resInfo.getNativeName() == null && resInfo.getName() != null) {
+ resInfo.setNativeName(resInfo.getName());
+ }
+ if (resInfo.getNativeName() != null && resInfo.getName() == null) {
+ resInfo.setName(resInfo.getNativeName());
+ }
+ }
+
+ /**
* Initializes a feature type object setting any info that has not been set.
*/
public void initFeatureType(FeatureTypeInfo featureType) throws Exception {
if (featureType.getCatalog() == null) {
featureType.setCatalog(catalog);
}
- if (featureType.getNativeName() == null && featureType.getName() != null) {
- featureType.setNativeName(featureType.getName());
- }
- if (featureType.getNativeName() != null && featureType.getName() == null) {
- featureType.setName(featureType.getNativeName());
- }
+
+ initResourceInfo(featureType);
+
// setup the srs if missing
if (featureType.getSRS() == null) {
lookupSRS(featureType, true);
@@ -572,15 +582,9 @@
*/
public void initWMSLayer(WMSLayerInfo wmsLayer) throws Exception {
wmsLayer.setCatalog(catalog);
+
+ initResourceInfo(wmsLayer);
- // set the name
- if (wmsLayer.getNativeName() == null && wmsLayer.getName() != null) {
- wmsLayer.setNativeName(wmsLayer.getName());
- }
- if (wmsLayer.getNativeName() != null && wmsLayer.getName() == null) {
- wmsLayer.setName(wmsLayer.getNativeName());
- }
-
// get a fully initialized version we can copy from
WMSLayerInfo full = buildWMSLayer(wmsLayer.getNativeName());
@@ -609,6 +613,53 @@
}
/**
+ * Initialize a coverage object and set any unset info.
+ */
+ public void initCoverage(CoverageInfo cinfo) throws Exception {
+ CoverageStoreInfo csinfo = (CoverageStoreInfo) store;
+ AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) catalog
+ .getResourcePool().getGridCoverageReader(csinfo, GeoTools.getDefaultHints());
+
+ initResourceInfo(cinfo);
+
+ if (reader == null)
+ throw new Exception("Unable to acquire a reader for this coverage with format: "
+ + csinfo.getFormat().getName());
+
+ if (cinfo.getNativeCRS() == null) {
+ cinfo.setNativeCRS(reader.getCrs());
+ }
+
+ CoordinateReferenceSystem nativeCRS = cinfo.getNativeCRS();
+
+ if (cinfo.getSRS() == null) {
+ cinfo.setSRS(nativeCRS.getIdentifiers().toArray()[0].toString());
+ }
+
+ if (cinfo.getProjectionPolicy() == null) {
+ if (nativeCRS != null && !nativeCRS.getIdentifiers().isEmpty()) {
+ cinfo.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
+ }
+ if (nativeCRS == null) {
+ cinfo.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
+ }
+ }
+
+ if (cinfo.getLatLonBoundingBox() == null
+ && cinfo.getNativeBoundingBox() == null) {
+ GeneralEnvelope envelope = reader.getOriginalEnvelope();
+
+ cinfo.setNativeBoundingBox(new ReferencedEnvelope(envelope));
+ cinfo.setLatLonBoundingBox(new ReferencedEnvelope(CoverageStoreUtils.getWGS84LonLatEnvelope(envelope)));
+ } else if (cinfo.getLatLonBoundingBox() == null) {
+ setupBounds(cinfo);
+ } else if (cinfo.getNativeBoundingBox() == null && cinfo.getNativeCRS() != null) {
+ ReferencedEnvelope boundsLatLon = cinfo.getLatLonBoundingBox();
+ cinfo.setNativeBoundingBox(boundsLatLon.transform(cinfo.getNativeCRS(), true));
+ }
+ }
+
+ /**
* Builds the default coverage contained in the current store
*
* @return
Index: restconfig/src/test/java/org/geoserver/catalog/rest/CoverageTest.java
===================================================================
--- restconfig/src/test/java/org/geoserver/catalog/rest/CoverageTest.java (revision 16153)
+++ restconfig/src/test/java/org/geoserver/catalog/rest/CoverageTest.java (working copy)
@@ -102,8 +102,8 @@
"