Skip to content

Commit

Permalink
[GEOT-5237] ImageMosaic does not skip missing granules anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Oct 2, 2015
1 parent 2cb9440 commit 82f9306
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 24 deletions.
Expand Up @@ -642,8 +642,7 @@ public GranuleDescriptor(
// If the granuleDescriptor is not there, dump a message and continue
final URL rasterFile = pathType.resolvePath(parentLocation, granuleLocation);
if (rasterFile == null) {
throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2,"granuleLocation",granuleLocation));

throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2,"granuleLocation",granuleLocation));
}
if (LOGGER.isLoggable(Level.FINE))
LOGGER.fine("File found "+granuleLocation);
Expand Down
Expand Up @@ -2,7 +2,7 @@
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2007-2008, Open Source Geospatial Foundation (OSGeo)
* (C) 2007-2015, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -167,22 +167,27 @@ public void visit(Feature feature) {
String featureId = sf.getID();
if(descriptorsCache.containsKey(featureId)){
granule = descriptorsCache.get(featureId);
} else{
// create the granule descriptor
MultiLevelROI footprint = getGranuleFootprint(sf);
if(footprint == null || !footprint.isEmpty()) {
// caching only if the footprint is eithery absent or present and NON-empty
granule = new GranuleDescriptor(
sf,
adaptee.suggestedRasterSPI,
adaptee.pathType,
adaptee.locationAttribute,
adaptee.parentLocation,
footprint,
adaptee.heterogeneous,
adaptee.hints); // retain hints since this may contain a reader or anything
descriptorsCache.put(featureId, granule);
} else {
try {
// create the granule descriptor
MultiLevelROI footprint = getGranuleFootprint(sf);
if(footprint == null || !footprint.isEmpty()) {
// caching only if the footprint is either absent or present and NON-empty
granule = new GranuleDescriptor(
sf,
adaptee.suggestedRasterSPI,
adaptee.pathType,
adaptee.locationAttribute,
adaptee.parentLocation,
footprint,
adaptee.heterogeneous,
adaptee.hints); // retain hints since this may contain a reader or anything
descriptorsCache.put(featureId, granule);
}
} catch(Exception e) {
LOGGER.log(Level.FINE, "Skipping invalid granule", e);
}

}

if(granule != null) {
Expand Down
Expand Up @@ -496,12 +496,16 @@ public void visit(Feature feature) {
final SimpleFeature sf = (SimpleFeature) feature;
MultiLevelROI footprint = getGranuleFootprint(sf);
if(footprint == null || !footprint.isEmpty()) {
final GranuleDescriptor granule = new GranuleDescriptor(sf,
suggestedRasterSPI, pathType, locationAttribute, parentLocation,
footprint,
heterogeneous, q.getHints());

visitor.visit(granule, null);
try {
final GranuleDescriptor granule = new GranuleDescriptor(sf,
suggestedRasterSPI, pathType, locationAttribute, parentLocation,
footprint,
heterogeneous, q.getHints());

visitor.visit(granule, null);
} catch(Exception e) {
LOGGER.log(Level.FINE, "Skipping invalid granule", e);
}
}

// check if something bad occurred
Expand Down
Expand Up @@ -81,6 +81,7 @@
import org.geotools.coverage.grid.io.UnknownFormat;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.DataUtilities;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.Query;
import org.geotools.data.Transaction;
import org.geotools.data.simple.SimpleFeatureIterator;
Expand Down Expand Up @@ -4000,6 +4001,26 @@ public void testEmptyShapefileMosaicWithCaching() throws Exception

reader.dispose();
}

@Test
public void testIgnoreInvalidGranule() throws Exception {
// Get the resources as needed.
final AbstractGridFormat format = TestUtils.getFormat(rgbURL);
final ImageMosaicReader reader = TestUtils.getReader(rgbURL, format);

GranuleStore granules = (GranuleStore) reader.getGranules(reader.getGridCoverageNames()[0], false);
SimpleFeature first = DataUtilities.first(granules.getGranules(Query.ALL));
// poison it
first.setAttribute("location", "global_mosaic_11-invalid.png");
Transaction t = new DefaultTransaction();
granules.setTransaction(t);
granules.addGranules(DataUtilities.collection(first));
t.commit();
t.close();

// Test the output coverage
TestUtils.checkCoverage(reader, new GeneralParameterValue[0], "Ignore invalid granule");
}


}

0 comments on commit 82f9306

Please sign in to comment.