Skip to content

Commit

Permalink
added the option to set tile merge strategy for raster ingest cli and…
Browse files Browse the repository at this point in the history
… changed default to none
  • Loading branch information
rfecher committed Jul 22, 2016
1 parent 37af37b commit f4d8740
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 57 deletions.
5 changes: 5 additions & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<artifactId>geowave-adapter-vector</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>mil.nga.giat</groupId>
<artifactId>geowave-adapter-raster</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.sakserv</groupId>
<artifactId>hadoop-mini-clusters-hbase</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,21 @@ private static BufferedImage rescaleImageViaPlanarImage(
0.0f,
interpolation);
final RenderedOp result = w.getRenderedOperation();
Raster raster = result.getData();
final WritableRaster scaledImageRaster;
if (raster instanceof WritableRaster) {
scaledImageRaster = (WritableRaster) raster;
}
else {
scaledImageRaster = raster.createCompatibleWritableRaster();

final WritableRaster scaledImageRaster = (WritableRaster) result.getData();

scaledImageRaster.setDataElements(
0,
0,
raster.getWidth(),
raster.getHeight(),
raster.getDataBuffer());
}
final ColorModel colorModel = image.getColorModel();
try {
final BufferedImage scaledImage = new BufferedImage(
Expand Down
1 change: 0 additions & 1 deletion extensions/adapters/vector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs2</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
public class GeoToolsRasterDataStoreIngestPlugin implements
LocalFileIngestPlugin<GridCoverage>
{
private final static Logger LOGGER = Logger.getLogger(
GeoToolsRasterDataStoreIngestPlugin.class);
private final static Logger LOGGER = Logger.getLogger(GeoToolsRasterDataStoreIngestPlugin.class);
private final RasterOptionProvider optionProvider;

public GeoToolsRasterDataStoreIngestPlugin() {
Expand All @@ -71,8 +70,7 @@ public boolean supportsFile(
final File file ) {
AbstractGridFormat format = null;
try {
format = GridFormatFinder.findFormat(
file);
format = GridFormatFinder.findFormat(file);
}
catch (final Exception e) {
LOGGER.info(
Expand All @@ -89,24 +87,20 @@ private static AbstractGridFormat prioritizedFindFormat(
final File input ) {
final AbstractGridFormat format = null;
try {
final Set<AbstractGridFormat> formats = GridFormatFinder.findFormats(
input);
final Set<AbstractGridFormat> formats = GridFormatFinder.findFormats(input);
if ((formats == null) || formats.isEmpty()) {
LOGGER.warn(
"Unable to support raster file " + input.getAbsolutePath());
LOGGER.warn("Unable to support raster file " + input.getAbsolutePath());
return null;
}
// world image and geotiff can both open tif files, give
// priority to gdalgeotiff, followed by geotiff
for (final AbstractGridFormat f : formats) {
if ("GDALGeoTiff".equals(
f.getName())) {
if ("GDALGeoTiff".equals(f.getName())) {
return f;
}
}
for (final AbstractGridFormat f : formats) {
if ("GeoTIFF".equals(
f.getName())) {
if ("GeoTIFF".equals(f.getName())) {
return f;
}
}
Expand All @@ -131,17 +125,15 @@ public CloseableIterator<GeoWaveData<GridCoverage>> toGeoWaveData(
final File input,
final Collection<ByteArrayId> primaryIndexIds,
final String globalVisibility ) {
final AbstractGridFormat format = prioritizedFindFormat(
input);
final AbstractGridFormat format = prioritizedFindFormat(input);
if (format == null) {
return new Wrapper(
Collections.emptyIterator());
}
Hints hints = null;
if ((optionProvider.getCrs() != null) && !optionProvider.getCrs().trim().isEmpty()) {
try {
final CoordinateReferenceSystem crs = CRS.decode(
optionProvider.getCrs());
final CoordinateReferenceSystem crs = CRS.decode(optionProvider.getCrs());
if (crs != null) {
hints = new Hints();
hints.put(
Expand All @@ -156,25 +148,23 @@ public CloseableIterator<GeoWaveData<GridCoverage>> toGeoWaveData(
}
}
final GridCoverage2DReader reader = format.getReader(
input, hints);
input,
hints);
if (reader == null) {
LOGGER.error(
"Unable to get reader instance, getReader returned null");
LOGGER.error("Unable to get reader instance, getReader returned null");
return new Wrapper(
Collections.emptyIterator());
}
try {
final GridCoverage2D coverage = reader.read(
null);
final GridCoverage2D coverage = reader.read(null);
if (coverage != null) {
final Map<String, String> metadata = new HashMap<String, String>();
final String coverageName = coverage.getName().toString();
try {
// wrapping with try-catch block because often the reader
// does not support operations on coverage name
// if not, we just don't have metadata, and continue
final String[] mdNames = reader.getMetadataNames(
coverageName);
final String[] mdNames = reader.getMetadataNames(coverageName);
if ((mdNames != null) && (mdNames.length > 0)) {
for (final String mdName : mdNames) {
metadata.put(
Expand All @@ -195,8 +185,7 @@ public CloseableIterator<GeoWaveData<GridCoverage>> toGeoWaveData(
if (optionProvider.isSeparateBands() && (coverage.getNumSampleDimensions() > 1)) {
final String baseName = optionProvider.getCoverageName() != null ? optionProvider.getCoverageName()
: input.getName();
final double[][] nodata = optionProvider.getNodata(
coverage.getNumSampleDimensions());
final double[][] nodata = optionProvider.getNodata(coverage.getNumSampleDimensions());
for (int b = 0; b < coverage.getNumSampleDimensions(); b++) {
final RasterDataAdapter adapter = new RasterDataAdapter(
baseName + "_B" + b,
Expand All @@ -212,11 +201,10 @@ public CloseableIterator<GeoWaveData<GridCoverage>> toGeoWaveData(
new double[][] {
nodata[b]
});
coverages.add(
new GeoWaveData<GridCoverage>(
adapter,
primaryIndexIds,
coverage));
coverages.add(new GeoWaveData<GridCoverage>(
adapter,
primaryIndexIds,
coverage));
}
}
else {
Expand All @@ -228,13 +216,11 @@ public CloseableIterator<GeoWaveData<GridCoverage>> toGeoWaveData(
optionProvider.getTileSize(),
optionProvider.isBuildPyramid(),
optionProvider.isBuildHistogream(),
optionProvider.getNodata(
coverage.getNumSampleDimensions()));
coverages.add(
new GeoWaveData<GridCoverage>(
adapter,
primaryIndexIds,
coverage));
optionProvider.getNodata(coverage.getNumSampleDimensions()));
coverages.add(new GeoWaveData<GridCoverage>(
adapter,
primaryIndexIds,
coverage));
}
return new Wrapper(
coverages.iterator()) {
Expand All @@ -247,9 +233,8 @@ public void close()
};
}
else {
LOGGER.warn(
"Null grid coverage from file '" + input.getAbsolutePath()
+ "' for discovered geotools format '" + format.getName() + "'");
LOGGER.warn("Null grid coverage from file '" + input.getAbsolutePath()
+ "' for discovered geotools format '" + format.getName() + "'");
}
}
catch (final IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mil.nga.giat.geowave.format.geotools.raster;

import mil.nga.giat.geowave.adapter.raster.adapter.merge.RasterTileMergeStrategy;
import mil.nga.giat.geowave.adapter.raster.adapter.merge.nodata.NoDataMergeStrategy;

public class NoDataMergeStrategyProvider implements
RasterMergeStrategyProviderSpi
{
public static String NAME = "no-data";

@Override
public String getName() {
return NAME;
}

@Override
public RasterTileMergeStrategy<?> getStrategy() {
return new NoDataMergeStrategy();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mil.nga.giat.geowave.format.geotools.raster;

import mil.nga.giat.geowave.adapter.raster.adapter.merge.RasterTileMergeStrategy;

public class NoMergeStrategyProvider implements
RasterMergeStrategyProviderSpi
{
public static String NAME = "none";

@Override
public String getName() {
return NAME;
}

@Override
public RasterTileMergeStrategy<?> getStrategy() {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package mil.nga.giat.geowave.format.geotools.raster;

import mil.nga.giat.geowave.adapter.raster.adapter.merge.RasterTileMergeStrategy;

public interface RasterMergeStrategyProviderSpi
{
public String getName();

public RasterTileMergeStrategy<?> getStrategy();
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
package mil.nga.giat.geowave.format.geotools.raster;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.converters.DoubleConverter;

import mil.nga.giat.geowave.adapter.raster.adapter.RasterDataAdapter;
import mil.nga.giat.geowave.adapter.raster.adapter.merge.RasterTileMergeStrategy;
import mil.nga.giat.geowave.core.ingest.spi.IngestFormatOptionProvider;

public class RasterOptionProvider implements
IngestFormatOptionProvider
{

// for now, default to no merging
private static final RasterTileMergeStrategy DEFAULT_MERGE_STRATEGY = null;
private final static Logger LOGGER = LoggerFactory.getLogger(RasterOptionProvider.class);
private static Map<String, RasterMergeStrategyProviderSpi> registeredMergeStrategies = null;
@Parameter(names = "--pyramid", description = "Build an image pyramid on ingest for quick reduced resolution query")
private boolean buildPyramid = false;
private final boolean buildPyramid = false;

@Parameter(names = "--crs", description = "A CRS override for the provided raster file")
private String crs = null;
private final String crs = null;

@Parameter(names = "--histogram", description = "Build a histogram of samples per band on ingest for performing band equalization")
private boolean buildHistogream = false;
private final boolean buildHistogream = false;

@Parameter(names = "--tileSize", description = "Optional parameter to set the tile size stored (default is 256)")
private int tileSize = RasterDataAdapter.DEFAULT_TILE_SIZE;
private final int tileSize = RasterDataAdapter.DEFAULT_TILE_SIZE;

@Parameter(names = "--coverage", description = "Optional parameter to set the coverage name (default is the file name)")
private String coverageName = null;
private final String coverageName = null;

@Parameter(names = "--nodata", variableArity = true, description = "Optional parameter to set 'no data' values, if 1 value is giving it is applied for each band, if multiple are given then the first totalNoDataValues/totalBands are applied to the first band and so on, so each band can have multiple differing 'no data' values if needed", converter = DoubleConverter.class)
private List<Double> nodata = new ArrayList<>();
private final List<Double> nodata = new ArrayList<>();

@Parameter(names = "--separateBands", description = "Optional parameter to separate each band into its own coverage name. By default the coverage name will have '_Bn' appended to it where `n` is the band's index.")
private boolean separateBands = false;
private final boolean separateBands = false;

@Parameter(names = "--mergeStrategy", description = "Optional parameter to choose a tile merge strategy used for mosaic. Default behavior will be `none`. Alternatively 'no-data' will mosaic the most recent tile over previous tiles, except where there are no data values.")
private final String mergeStrategy = NoMergeStrategyProvider.NAME;

public RasterOptionProvider() {}

Expand Down Expand Up @@ -89,4 +103,34 @@ public double[][] getNodata(
}
return retVal;
}

public RasterTileMergeStrategy<?> getMergeStrategy() {
final Map<String, RasterMergeStrategyProviderSpi> internalMergeStrategies = getRegisteredMergeStrategies();
if ((mergeStrategy == null) || mergeStrategy.trim().isEmpty()) {
LOGGER.warn("Merge Strategy not found");
return DEFAULT_MERGE_STRATEGY;
}
final RasterMergeStrategyProviderSpi provider = internalMergeStrategies.get(mergeStrategy);
if (provider == null) {
LOGGER.warn("Merge Strategy Provider not found for '" + mergeStrategy + "'");
return DEFAULT_MERGE_STRATEGY;
}
return provider.getStrategy();
}

private synchronized Map<String, RasterMergeStrategyProviderSpi> getRegisteredMergeStrategies() {
if (registeredMergeStrategies == null) {
registeredMergeStrategies = new HashMap<String, RasterMergeStrategyProviderSpi>();
final ServiceLoader<RasterMergeStrategyProviderSpi> converters = ServiceLoader
.load(RasterMergeStrategyProviderSpi.class);
final Iterator<RasterMergeStrategyProviderSpi> it = converters.iterator();
while (it.hasNext()) {
final RasterMergeStrategyProviderSpi converter = it.next();
registeredMergeStrategies.put(
converter.getName(),
converter);
}
}
return registeredMergeStrategies;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mil.nga.giat.geowave.format.geotools.raster.NoDataMergeStrategyProvider
mil.nga.giat.geowave.format.geotools.raster.NoMergeStrategyProvider
Loading

0 comments on commit f4d8740

Please sign in to comment.