|
From: <svn...@os...> - 2012-01-22 19:44:37
|
Author: simonegiannecchini
Date: 2012-01-22 11:44:30 -0800 (Sun, 22 Jan 2012)
New Revision: 38514
Added:
branches/2.7.x/modules/plugin/imagemosaic/src/test/resources/org/geotools/gce/imagemosaic/test-data/watertemp.zip
Modified:
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java
branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java
branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java
branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/ImageMosaicReaderTest.java
Log:
GEOT-2867
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/RasterLayerRequest.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -81,7 +81,7 @@
/** The {@link BoundingBox} requested */
private BoundingBox requestedBBox;
-
+
/** The {@link BoundingBox} of the portion of the coverage that intersects the requested bbox */
private BoundingBox cropBBox;
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/Utils.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -1008,7 +1008,7 @@
sampleImageFile));
ooStream = new ObjectOutputStream(outStream);
sri = new SerializableRenderedImage(sampleImage, true);
- ooStream.writeObject(sri);
+ ooStream.writeObject(sri);
} finally {
try {
if (ooStream != null)
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilder.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -51,6 +51,7 @@
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.spi.ImageInputStreamSpi;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
import javax.swing.SwingUtilities;
@@ -86,6 +87,7 @@
import org.geotools.gce.imagemosaic.properties.PropertiesCollectorSPI;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.image.io.ImageIOExt;
import org.geotools.referencing.CRS;
import org.geotools.resources.coverage.CoverageUtilities;
import org.geotools.util.Utilities;
@@ -117,8 +119,6 @@
/** Default Logger * */
final static Logger LOGGER = org.geotools.util.logging.Logging.getLogger(CatalogBuilder.class);
-
-
static abstract public class ProcessingEventListener implements EventListener {
abstract public void getNotification(final ProcessingEvent event);
@@ -327,23 +327,35 @@
// STEP 1
// Getting an ImageIO reader for this coverage.
//
- inStream = ImageIO.createImageInputStream(fileBeingProcessed);
- if(inStream==null) {
- fireEvent(Level.INFO,fileBeingProcessed+" has been skipped since we could not get a stream for it", ((fileIndex * 100.0) / numFiles));
- return;
- }
+ // try to use cache
+ if(cachedStreamSPI!=null ){
+ inStream=cachedStreamSPI.createInputStreamInstance(fileBeingProcessed);
+ }
+ if(inStream==null ){
+ // failed, look for a new SPI
+ cachedStreamSPI= ImageIOExt.getImageInputStreamSPI(fileBeingProcessed);
+ if(cachedStreamSPI!=null){
+ inStream=cachedStreamSPI.createInputStreamInstance(fileBeingProcessed);
+ }
+
+ }
+ if(inStream==null) {
+ // failed again
+ fireEvent(Level.INFO,fileBeingProcessed+" has been skipped since we could not get a stream for it", ((fileIndex * 100.0) / numFiles));
+ return;
+ }
inStream.mark();
- cachedSPITest: {
+ cachedReaderSPITest: {
// there is no cached reader spi, let's look for one
- if(cachedSPI==null){
+ if(cachedReaderSPI==null){
final Iterator<ImageReader> it = ImageIO.getImageReaders(inStream);
if (it.hasNext()) {
imageioReader = it.next();
if(imageioReader!=null){
//cache the SPI
- cachedSPI=imageioReader.getOriginatingProvider();
+ cachedReaderSPI=imageioReader.getOriginatingProvider();
imageioReader.setInput(inStream);
}
} else {
@@ -351,14 +363,14 @@
}
} else {
// we have a cached SPI, let's try to use it
- if(!cachedSPI.canDecodeInput(inStream)){
+ if(!cachedReaderSPI.canDecodeInput(inStream)){
// the SPI is no good for this input
- cachedSPI=null;
+ cachedReaderSPI=null;
//take me to the SPI search
- break cachedSPITest;
+ break cachedReaderSPITest;
}
// the spi is good
- imageioReader=cachedSPI.createReaderInstance();
+ imageioReader=cachedReaderSPI.createReaderInstance();
imageioReader.setInput(inStream);
}
}
@@ -877,8 +889,10 @@
private CatalogBuilderConfiguration runConfiguration;
- private ImageReaderSpi cachedSPI;
+ private ImageReaderSpi cachedReaderSPI;
+ private ImageInputStreamSpi cachedStreamSPI;
+
private List<PropertiesCollector> propertiesCollectors;
private SampleModel defaultSM;
@@ -1497,9 +1511,9 @@
properties.setProperty("ExpandToRGB", Boolean.toString(mustConvertToRGB));
properties.setProperty("Heterogeneous", Boolean.toString(mosaicConfiguration.isHeterogeneous()));
- if (cachedSPI != null){
+ if (cachedReaderSPI != null){
// suggested spi
- properties.setProperty("SuggestedSPI", cachedSPI.getClass().getName());
+ properties.setProperty("SuggestedSPI", cachedReaderSPI.getClass().getName());
}
// write down imposed bbox
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/main/java/org/geotools/gce/imagemosaic/catalogbuilder/CatalogBuilderConfiguration.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -241,6 +241,7 @@
public void setRootMosaicDirectory(final String rootMosaicDirectory) {
Utilities.ensureNonNull("rootMosaicDirectory", rootMosaicDirectory);
String testingDirectory = rootMosaicDirectory;
+ Utils.checkDirectory(testingDirectory,false);
this.rootMosaicDirectory = testingDirectory;
}
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -23,6 +23,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.InetAddress;
import java.util.Arrays;
import java.util.Properties;
@@ -35,13 +36,14 @@
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.gce.imagemosaic.catalog.GranuleCatalog;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder;
-import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilderConfiguration;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.ExceptionEvent;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.ProcessingEvent;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilder.ProcessingEventListener;
+import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilderConfiguration;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.test.TestData;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.opengis.parameter.GeneralParameterValue;
import org.opengis.parameter.ParameterValue;
@@ -55,6 +57,19 @@
* @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/build/maven/javadoc/../../../modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/CatalogBuilderTest.java $
*/
public class CatalogBuilderTest extends Assert {
+
+ /** Used to avoid errors if building on a system where hostname is not defined */
+ private boolean hostnameDefined;
+
+ @Before
+ public void setup() {
+ try {
+ InetAddress.getLocalHost();
+ hostnameDefined = true;
+ } catch (Exception ex) {
+ hostnameDefined = false;
+ }
+ }
private final class CatalogBuilderListener extends ProcessingEventListener{
@@ -72,7 +87,7 @@
}
@Test
- public void catalogBuilderConfiguration() throws FileNotFoundException, IOException, CloneNotSupportedException{
+ public void catalogBuilderConfiguration() throws Exception{
// create a stub configuration
final CatalogBuilderConfiguration c1= new CatalogBuilderConfiguration();
c1.setIndexName("index");
@@ -102,8 +117,9 @@
}
- @Test
- public void buildCatalog() throws FileNotFoundException, IOException{
+ @Test
+ public void buildCatalog() throws FileNotFoundException, IOException{
+ if (hostnameDefined){
CatalogBuilder builder = null;
ImageMosaicReader reader = null;
ParameterValue<GridGeometry2D> gg = null;
@@ -228,14 +244,16 @@
PlanarImage.wrapRenderedImage( coverage.getRenderedImage()).getTiles();
- // dispose
- coverage.dispose(true);
- reader.dispose();
+ // dispose
+ coverage.dispose(true);
+ reader.dispose();
+ }
}
@Test
public void buildCachingIndex() throws FileNotFoundException, IOException {
+ if (hostnameDefined){
CatalogBuilder builder = null;
ImageMosaicReader reader = null;
FileInputStream inStream = null;
@@ -324,6 +342,6 @@
//Eat exception
}
}
-
+ }
}
}
Modified: branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/ImageMosaicReaderTest.java
===================================================================
--- branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/ImageMosaicReaderTest.java 2012-01-22 18:53:14 UTC (rev 38513)
+++ branches/2.7.x/modules/plugin/imagemosaic/src/test/java/org/geotools/gce/imagemosaic/ImageMosaicReaderTest.java 2012-01-22 19:44:30 UTC (rev 38514)
@@ -338,6 +338,44 @@
"Time-Elevation Test");
}
+ /**
+ *
+ * @throws IOException
+ * @throws ParseException
+ * @throws FactoryException
+ * @throws NoSuchAuthorityCodeException
+ * @throws MismatchedDimensionException
+ * @throws NoSuchAuthorityCodeException
+ */
+ @Test
+ public void timeIntegerElevation() throws IOException, ParseException, NoSuchAuthorityCodeException, FactoryException {
+ // Check we can have an integer elevation too
+ TestData.unzipFile(this, "watertemp.zip");
+ final URL timeElevURL = TestData.url(this, "watertemp");
+ System.setProperty("org.geotools.shapefile.datetime", "true");
+ final AbstractGridFormat format = getFormat(timeElevURL);
+ assertNotNull(format);
+ ImageMosaicReader reader = getReader(timeElevURL, format);
+ assertNotNull(format);
+
+ final String[] metadataNames = reader.getMetadataNames();
+ assertNotNull(metadataNames);
+ assertEquals(metadataNames.length,10);
+
+ assertEquals("true", reader.getMetadataValue("HAS_TIME_DOMAIN"));
+ final String timeMetadata = reader.getMetadataValue("TIME_DOMAIN");
+ assertNotNull(timeMetadata);
+ assertEquals(2,timeMetadata.split(",").length);
+ assertEquals(timeMetadata.split(",")[0],reader.getMetadataValue("TIME_DOMAIN_MINIMUM"));
+ assertEquals(timeMetadata.split(",")[1],reader.getMetadataValue("TIME_DOMAIN_MAXIMUM"));
+
+ assertEquals("true", reader.getMetadataValue("HAS_ELEVATION_DOMAIN"));
+ final String elevationMetadata = reader.getMetadataValue("ELEVATION_DOMAIN");
+ assertNotNull(elevationMetadata);
+ assertEquals(2,elevationMetadata.split(",").length);
+ assertEquals("0",reader.getMetadataValue("ELEVATION_DOMAIN_MINIMUM"));
+ assertEquals("100",reader.getMetadataValue("ELEVATION_DOMAIN_MAXIMUM"));
+ }
@Test
// @Ignore
Added: branches/2.7.x/modules/plugin/imagemosaic/src/test/resources/org/geotools/gce/imagemosaic/test-data/watertemp.zip
===================================================================
(Binary files differ)
Property changes on: branches/2.7.x/modules/plugin/imagemosaic/src/test/resources/org/geotools/gce/imagemosaic/test-data/watertemp.zip
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
|