final ParameterValue<String> tileSize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue();
tileSize.setValue("128,128");
//build a relative index and then make it run
CatalogBuilderConfiguration c1 = new CatalogBuilderConfiguration();
c1.setParameter(Prop.INDEX_NAME, "shpindex");
c1.setParameter(Prop.LOCATION_ATTRIBUTE, "location");
c1.setParameter(Prop.ABSOLUTE_PATH, "false");
c1.setParameter(Prop.ROOT_MOSAIC_DIR, TestData.file(this, "/overview/0").toString());
c1.setParameter(Prop.INDEXING_DIRECTORIES, TestData.file(this,"/overview/0").toString());
// c1.setIndexName("shpindex");
// c1.setLocationAttribute("location");
// c1.setAbsolute(false);
// c1.setRootMosaicDirectory(TestData.file(this,"/overview").toString());
// c1.setIndexingDirectories(Arrays.asList(TestData.file(this,"/overview/0").toString()));
assertNotNull(c1.toString());
ImageMosaicEventHandlers eventHandler = new ImageMosaicEventHandlers();
final ImageMosaicConfigHandler catalogHandler = new ImageMosaicConfigHandler(c1,
eventHandler);
// TODO
// build the index
builder = new ImageMosaicDirectoryWalker(catalogHandler, eventHandler);
eventHandler.addProcessingEventListener(new CatalogBuilderListener());
builder.run();
final File relativeMosaic=TestData.file(this,"/overview/"+c1.getIndexName()+".shp");
assertTrue(relativeMosaic.exists());
assertTrue(new ImageMosaicFormat().accepts(relativeMosaic));
reader = (ImageMosaicReader) new ImageMosaicReader(relativeMosaic);
// limit yourself to reading just a bit of it
gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
envelope = reader.getOriginalEnvelope();
dim= new Dimension();
dim.setSize(reader.getOriginalGridRange().getSpan(0)/2.0, reader.getOriginalGridRange().getSpan(1)/2.0);
rasterArea=(( GridEnvelope2D)reader.getOriginalGridRange());
rasterArea.setSize(dim);
range= new GridEnvelope2D(rasterArea);
gg.setValue(new GridGeometry2D(range,envelope));
// use imageio with defined tiles
// Test the output coverage
coverage = (GridCoverage2D) reader.read(new GeneralParameterValue[] {gg,useJai ,tileSize});
Assert.assertNotNull(coverage);
PlanarImage.wrapRenderedImage( coverage.getRenderedImage()).getTiles();
//caching should be false by default
Properties props= new Properties();
InputStream in= null;
try{
in= TestData.openStream(this, "/overview/"+c1.getIndexName()+".properties");
assertNotNull("unable to find mosaic properties file",in);
props.load(in);
assertTrue(props.containsKey("Caching"));
assertTrue(props.getProperty("Caching").equalsIgnoreCase("false"));
} finally {
if(in!=null){
IOUtils.closeQuietly(in);
}
}
// dispose
coverage.dispose(true);
reader.dispose();
//build an absolute index and then make it run
CatalogBuilderConfiguration c2 = new CatalogBuilderConfiguration();
c2.setParameter(Prop.INDEX_NAME, "shpindex_absolute");
c2.setParameter(Prop.LOCATION_ATTRIBUTE, "location");
c2.setParameter(Prop.ABSOLUTE_PATH, "true");
c2.setParameter(Prop.CACHING, "true");
c2.setParameter(Prop.ROOT_MOSAIC_DIR, TestData.file(this, "/overview").toString());
c2.setParameter(Prop.INDEXING_DIRECTORIES, TestData.file(this,"/overview").toString());
// c2.setIndexName("shpindex_absolute");
// c2.setLocationAttribute("location");
// c2.setAbsolute(true);
// c2.setCaching(true);
// c2.setRootMosaicDirectory(TestData.file(this,"/overview").toString());
// c2.setIndexingDirectories(Arrays.asList(TestData.file(this,"/overview/0").toString()));
assertNotNull(c2.toString());
ImageMosaicEventHandlers eventHandler2 = new ImageMosaicEventHandlers();
final ImageMosaicConfigHandler catalogHandler2 = new ImageMosaicConfigHandler(c2,
eventHandler);
// build the index
builder = new ImageMosaicDirectoryWalker(catalogHandler2, eventHandler);
eventHandler2.addProcessingEventListener(new CatalogBuilderListener());
builder.run();
final File absoluteMosaic=TestData.file(this,"/overview/"+c2.getIndexName()+".shp");
assertTrue(absoluteMosaic.exists());
//caching should be false by default
props= new Properties();
in= null;
try{
in= TestData.openStream(this, "/overview/"+c2.getIndexName()+".properties");
assertNotNull("unable to find mosaic properties file",in);
props.load(in);
assertTrue(props.containsKey("Caching"));
assertTrue(props.getProperty("Caching").equalsIgnoreCase("true"));