Skip to content

Commit

Permalink
Merge pull request #1886 from aaime/jp2_gml
Browse files Browse the repository at this point in the history
Support GML in JP2K geofererentiation
  • Loading branch information
aaime committed May 10, 2018
2 parents 6d8db96 + 85d61a0 commit 7211a0c
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 55 deletions.
Expand Up @@ -163,14 +163,12 @@ protected void handleFile(final File fileBeingProcessed) throws IOException {
if (cachedFormat == null) {
// When looking for formats which may parse this file, make sure to exclude the
// ImageMosaicFormat as return
format =
(AbstractGridFormat)
GridFormatFinder.findFormat(fileBeingProcessed, excludeMosaicHints);
format = GridFormatFinder.findFormat(fileBeingProcessed, excludeMosaicHints);
} else {
if (cachedFormat.accepts(fileBeingProcessed)) {
format = cachedFormat;
} else {
format = new UnknownFormat();
format = GridFormatFinder.findFormat(fileBeingProcessed, excludeMosaicHints);
}
}
if ((format instanceof UnknownFormat) || format == null) {
Expand All @@ -186,7 +184,6 @@ protected void handleFile(final File fileBeingProcessed) throws IOException {
}
return;
}
cachedFormat = format;

final Hints configurationHints = configHandler.getRunConfiguration().getHints();
coverageReader =
Expand Down Expand Up @@ -234,21 +231,32 @@ protected void handleFile(final File fileBeingProcessed) throws IOException {

for (String cvName : coverageNames) {
boolean shouldAccept = true;
for (GranuleAcceptor acceptor : this.configHandler.getGranuleAcceptors()) {
if (!acceptor.accepts(
coverageReader, cvName, fileBeingProcessed, configHandler)) {
shouldAccept = false;
eventHandler.fireFileEvent(
Level.FINE,
fileBeingProcessed,
true,
"Granule acceptor "
+ acceptor.getClass().getName()
+ " rejected the granule being processed"
+ fileBeingProcessed,
((fileIndex + 1) * 99.0) / numFiles);
break;
try {
for (GranuleAcceptor acceptor : this.configHandler.getGranuleAcceptors()) {
if (!acceptor.accepts(
coverageReader, cvName, fileBeingProcessed, configHandler)) {
shouldAccept = false;
eventHandler.fireFileEvent(
Level.FINE,
fileBeingProcessed,
true,
"Granule acceptor "
+ acceptor.getClass().getName()
+ " rejected the granule being processed"
+ fileBeingProcessed,
((fileIndex + 1) * 99.0) / numFiles);
break;
}
}
// store the format only if we can accept this file, not before
cachedFormat = format;
} catch (Exception e) {
LOGGER.log(
Level.FINE,
"Failure during potential granule evaluation, skipping it: "
+ fileBeingProcessed,
e);
shouldAccept = false;
}

if (shouldAccept) {
Expand Down
Expand Up @@ -17,6 +17,8 @@
package org.geotools.gce.imagemosaic;

import static org.geotools.util.URLs.fileToUrl;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;

Expand Down Expand Up @@ -110,6 +112,7 @@
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.factory.Hints;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.visitor.UniqueVisitor;
import org.geotools.filter.text.ecql.ECQL;
import org.geotools.gce.imagemosaic.Utils.Prop;
import org.geotools.gce.imagemosaic.catalog.GranuleCatalog;
Expand Down Expand Up @@ -152,6 +155,7 @@
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.NoSuchAuthorityCodeException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.datum.PixelInCell;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.NoninvertibleTransformException;
Expand Down Expand Up @@ -202,6 +206,8 @@ public static junit.framework.Test suite() {

private URL rgbAURLTiff;

private URL rgbaExtraURLTiff;

private URL overviewURL;

static boolean INTERACTIVE;
Expand Down Expand Up @@ -2430,6 +2436,7 @@ public void setUp() throws Exception {

imposedEnvelopeURL = TestData.url(this, "env");
rgbAURLTiff = TestData.url(this, "tiff_rgba/");
rgbaExtraURLTiff = TestData.url(this, "tiff_rgba_extra/");
}

/**
Expand Down Expand Up @@ -5174,4 +5181,45 @@ public void assertNoData(GridCoverage2D coverageDeferred, Double expectedNoData)
assertNull(noDataContainer);
}
}

@Test
public void testHarvestWithExtraNonSpatialFile() throws Exception {
File source = URLs.urlToFile(rgbAURLTiff);
File extras = URLs.urlToFile(rgbaExtraURLTiff);
File testDataDir = TestData.file(this, ".");
File directory = new File(testDataDir, "rgba_tiff_extra_test");
if (directory.exists()) {
FileUtils.deleteDirectory(directory);
}
FileUtils.copyDirectory(source, directory);
FileUtils.copyDirectory(extras, directory);

// ok, let's create a mosaic with a single granule and check its times
URL harvestSingleURL = fileToUrl(directory);
final AbstractGridFormat format = TestUtils.getFormat(harvestSingleURL);
ImageMosaicReader reader = TestUtils.getReader(harvestSingleURL, format);
assertNotNull(reader);
try {
// the coverage name got parsed
String[] names = reader.getGridCoverageNames();
assertEquals(1, names.length);
assertEquals("passA", names[0]);

// the mosaic is referenced
CoordinateReferenceSystem crs = reader.getCoordinateReferenceSystem();
CoordinateReferenceSystem expected = CRS.decode("EPSG:4326", true);
assertTrue(CRS.equalsIgnoreMetadata(expected, crs));

// there are two granules in the mosaic, the tiffs, with the expected locations
GranuleSource passA = reader.getGranules("passA", true);
UniqueVisitor visitor = new UniqueVisitor("location");
passA.getGranules(Query.ALL).accepts(visitor, null);
Set<String> locations = visitor.getUnique();
System.out.println(locations);
assertThat(locations, hasItem(equalTo("passA2006128211927.tiff")));
assertThat(locations, hasItem(equalTo("passA2006128194218.tiff")));
} finally {
reader.dispose();
}
}
}
@@ -0,0 +1,6 @@
SPI=org.geotools.data.h2.H2DataStoreFactory
type=javax.sql.DataSource
driver=org.h2.Driver
database=test
user=usr
password=psw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,2 @@
CoverageNameCollectorSPI=org.geotools.gce.imagemosaic.namecollector.FileNameRegexNameCollectorSPI:regex=(pass[A-Z])
Schema=*the_geom:Polygon,location:String

0 comments on commit 7211a0c

Please sign in to comment.