forked from geoserver/geoserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEOS-11595] CoverageRATs check for PAM Resource is failing when chec…
…king CoverageViews pieces in place fixed indexing issue cleanup added test transitioning to creating ResourceInfo more cleanup cleanup cleanup pmd missing copyright cleanup style PR Changes
- Loading branch information
1 parent
47cf819
commit e9b06e1
Showing
5 changed files
with
486 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/extension/rat/src/test/java/org/geoserver/rat/RATViewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* (c) 2024 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.rat; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import it.geosolutions.imageio.pam.PAMDataset; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import javax.xml.namespace.QName; | ||
import org.geoserver.catalog.Catalog; | ||
import org.geoserver.catalog.CatalogBuilder; | ||
import org.geoserver.catalog.CoverageInfo; | ||
import org.geoserver.catalog.CoverageStoreInfo; | ||
import org.geoserver.catalog.CoverageView; | ||
import org.geoserver.data.test.MockData; | ||
import org.geoserver.data.test.SystemTestData; | ||
import org.geoserver.data.test.TestData; | ||
import org.geoserver.test.GeoServerSystemTestSupport; | ||
import org.geotools.api.referencing.crs.CoordinateReferenceSystem; | ||
import org.geotools.referencing.CRS; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** Test for the {@link CoverageView} and {@link PAMDataset} integration */ | ||
public class RATViewTest extends GeoServerSystemTestSupport { | ||
protected static QName IR_RGB = new QName(MockData.SF_URI, "ir-rgb", MockData.SF_PREFIX); | ||
private static final String RGB_IR_VIEW = "RgbIrView"; | ||
|
||
static CoordinateReferenceSystem UTM32N; | ||
|
||
@Before | ||
public void cleanupCatalog() { | ||
// attempt to solve intermittent build failure | ||
getGeoServer().reset(); | ||
} | ||
|
||
@Override | ||
protected void setUpTestData(SystemTestData testData) throws Exception { | ||
testData.setUpRasterLayer(IR_RGB, "ir-rgb-rat.zip", null, null, TestData.class); | ||
|
||
UTM32N = CRS.decode("EPSG:32632", true); | ||
} | ||
|
||
@Override | ||
protected void onSetUp(SystemTestData testData) throws Exception { | ||
super.onSetUp(testData); | ||
|
||
// setup the coverage view | ||
final Catalog cat = getCatalog(); | ||
configureIROnCatalog(cat); | ||
} | ||
|
||
private void configureIROnCatalog(Catalog cat) throws Exception { | ||
final CoverageStoreInfo storeInfo = cat.getCoverageStoreByName("ir-rgb"); | ||
final CoverageView coverageView = buildRgbIRView(); | ||
final CatalogBuilder builder = new CatalogBuilder(cat); | ||
builder.setStore(storeInfo); | ||
|
||
final CoverageInfo coverageInfo = | ||
coverageView.createCoverageInfo(RGB_IR_VIEW, storeInfo, builder); | ||
coverageInfo.getParameters().put("USE_JAI_IMAGEREAD", "false"); | ||
coverageInfo.getDimensions().get(0).setName("Red"); | ||
coverageInfo.getDimensions().get(1).setName("Green"); | ||
coverageInfo.getDimensions().get(2).setName("Blue"); | ||
coverageInfo.getDimensions().get(3).setName("Infrared"); | ||
cat.add(coverageInfo); | ||
} | ||
|
||
private CoverageView buildRgbIRView() { | ||
final CoverageView.CoverageBand rBand = | ||
new CoverageView.CoverageBand( | ||
Arrays.asList(new CoverageView.InputCoverageBand("rgb", "0")), | ||
"rband", | ||
0, | ||
CoverageView.CompositionType.BAND_SELECT); | ||
final CoverageView.CoverageBand gBand = | ||
new CoverageView.CoverageBand( | ||
Arrays.asList(new CoverageView.InputCoverageBand("rgb", "1")), | ||
"gband", | ||
1, | ||
CoverageView.CompositionType.BAND_SELECT); | ||
final CoverageView.CoverageBand bBand = | ||
new CoverageView.CoverageBand( | ||
Arrays.asList(new CoverageView.InputCoverageBand("rgb", "2")), | ||
"bband", | ||
2, | ||
CoverageView.CompositionType.BAND_SELECT); | ||
final CoverageView.CoverageBand irBand = | ||
new CoverageView.CoverageBand( | ||
Collections.singletonList(new CoverageView.InputCoverageBand("ir", "0")), | ||
"irband", | ||
3, | ||
CoverageView.CompositionType.BAND_SELECT); | ||
final CoverageView coverageView = | ||
new CoverageView(RGB_IR_VIEW, Arrays.asList(rBand, gBand, bBand, irBand)); | ||
// old coverage views deserialize with null in these fields, force it to test backwards | ||
// compatibility | ||
coverageView.setEnvelopeCompositionType(null); | ||
coverageView.setSelectedResolution(null); | ||
return coverageView; | ||
} | ||
|
||
@Test | ||
public void testGetPAMFromCoverageView() throws Exception { | ||
final Catalog cat = getCatalog(); | ||
final CoverageStoreInfo storeInfo = cat.getCoverageStoreByName("ir-rgb"); | ||
final CoverageView coverageView = buildRgbIRView(); | ||
final CatalogBuilder builder = new CatalogBuilder(cat); | ||
builder.setStore(storeInfo); | ||
|
||
final CoverageInfo coverageInfo = | ||
coverageView.createCoverageInfo(RGB_IR_VIEW, storeInfo, builder); | ||
CoverageRATs coverageRATs = new CoverageRATs(cat, coverageInfo); | ||
PAMDataset pamDataset = coverageRATs.getPAMDataset(); | ||
assertNotNull(pamDataset); | ||
assertEquals( | ||
String.valueOf(-1257.032451250814), | ||
pamDataset | ||
.getPAMRasterBand() | ||
.get(0) | ||
.getHistograms() | ||
.getHistItem() | ||
.getHistMin() | ||
.toString()); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/main/src/main/java/org/geoserver/catalog/CoverageViewPamResourceInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* (c) 2024 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.catalog; | ||
|
||
import it.geosolutions.imageio.pam.PAMDataset; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.geotools.api.coverage.grid.GridCoverageReader; | ||
import org.geotools.api.data.ResourceInfo; | ||
import org.geotools.coverage.grid.io.GridCoverage2DReader; | ||
import org.geotools.coverage.grid.io.PAMResourceInfo; | ||
import org.geotools.data.DefaultResourceInfo; | ||
|
||
/** A ResourceInfo wrapper for CoverageViews that provides access to the PAMDataset */ | ||
public class CoverageViewPamResourceInfo extends DefaultResourceInfo implements PAMResourceInfo { | ||
private final PAMDataset viewPam; | ||
|
||
/** | ||
* Constructor that populates the PAM dataset from the view bands | ||
* | ||
* @param viewInputs input alpha non-null coverages | ||
*/ | ||
public CoverageViewPamResourceInfo(CoverageViewReader.ViewInputs viewInputs) { | ||
viewPam = new PAMDataset(); | ||
populatePAMFromViewBands(viewInputs, viewPam); | ||
} | ||
|
||
@Override | ||
public PAMDataset getPAMDataset() { | ||
return viewPam; | ||
} | ||
|
||
@Override | ||
public boolean reloadPAMDataset() throws IOException { | ||
return PAMResourceInfo.super.reloadPAMDataset(); | ||
} | ||
|
||
/** | ||
* Populates the PAM dataset from the view bands | ||
* | ||
* @param info convenience object to access the coverage view input readers | ||
* @param viewPam the PAM dataset to populate | ||
*/ | ||
private void populatePAMFromViewBands(CoverageViewReader.ViewInputs info, PAMDataset viewPam) { | ||
Map<String, GridCoverageReader> readers = info.getInputReaders(); | ||
// iterate over the view bands and populate the PAM dataset | ||
for (CoverageView.CoverageBand band : info.getBands()) { | ||
for (CoverageView.InputCoverageBand inputCoverageBand : band.getInputCoverageBands()) { | ||
// get the reader for the coverage associated with this input coverage band | ||
GridCoverageReader reader = readers.get(inputCoverageBand.getCoverageName()); | ||
if (reader instanceof GridCoverage2DReader) { | ||
GridCoverage2DReader bandReader = (GridCoverage2DReader) reader; | ||
ResourceInfo resourceInfoBand = | ||
bandReader.getInfo(inputCoverageBand.getCoverageName()); | ||
// reader is associated with a PAM | ||
if (resourceInfoBand instanceof PAMResourceInfo) { | ||
PAMDataset bandPam = ((PAMResourceInfo) resourceInfoBand).getPAMDataset(); | ||
if (bandPam != null) { | ||
List<PAMDataset.PAMRasterBand> pamRasterBands = | ||
bandPam.getPAMRasterBand(); | ||
// find the PAMRasterBand for the given band index and put in the output | ||
Optional<PAMDataset.PAMRasterBand> pamRasterBandOptional = | ||
getPAMRasterBandByBandIndex( | ||
pamRasterBands, inputCoverageBand.getBand()); | ||
pamRasterBandOptional.ifPresent( | ||
pamRasterBand -> viewPam.getPAMRasterBand().add(pamRasterBand)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns the PAMRasterBand for the given band index, or {@code null} if not found | ||
* | ||
* @param pamRasterBands PAM raster bands | ||
* @param band band index to search for | ||
* @return PAMRasterBand for the given band index, or {@code null} if not found | ||
*/ | ||
private Optional<PAMDataset.PAMRasterBand> getPAMRasterBandByBandIndex( | ||
List<PAMDataset.PAMRasterBand> pamRasterBands, String band) { | ||
for (PAMDataset.PAMRasterBand pamRasterBand : pamRasterBands) { | ||
// PAM bands are 1-based, so we need to adjust the band index | ||
Integer adjustedBand = pamRasterBand.getBand() - 1; | ||
if (adjustedBand.toString().equals(band)) { | ||
return Optional.of(pamRasterBand); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
Oops, something went wrong.