Skip to content

Commit

Permalink
minor refactor for proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
Simone Giannecchini committed Jun 22, 2016
1 parent affa7b0 commit 51dcc6e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 65 deletions.
Expand Up @@ -87,10 +87,10 @@
import org.geotools.gce.imagemosaic.catalog.index.SchemasType;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilderConfiguration;
import org.geotools.gce.imagemosaic.catalogbuilder.MosaicBeanBuilder;
import org.geotools.gce.imagemosaic.geomhandler.DefaultGranuleGeometryHandler;
import org.geotools.gce.imagemosaic.geomhandler.GranuleGeometryHandler;
import org.geotools.gce.imagemosaic.geomhandler.GranuleGeometryHandlerFactoryFinder;
import org.geotools.gce.imagemosaic.geomhandler.GranuleGeometryHandlerFactorySPI;
import org.geotools.gce.imagemosaic.geomhandler.DefaultGranuleHandler;
import org.geotools.gce.imagemosaic.geomhandler.GranuleHandler;
import org.geotools.gce.imagemosaic.geomhandler.GranuleHandlerFactoryFinder;
import org.geotools.gce.imagemosaic.geomhandler.GranuleHandlerFactorySPI;
import org.geotools.gce.imagemosaic.properties.DefaultPropertiesCollectorSPI;
import org.geotools.gce.imagemosaic.properties.PropertiesCollector;
import org.geotools.gce.imagemosaic.properties.PropertiesCollectorFinder;
Expand Down Expand Up @@ -161,7 +161,7 @@ public class ImageMosaicConfigHandler {

private List<GranuleAcceptor> granuleAcceptors;

private GranuleGeometryHandler granuleGeomHandler;
private GranuleHandler granuleGeomHandler;

/**
* Default constructor
Expand Down Expand Up @@ -271,21 +271,21 @@ private List<GranuleAcceptor> initializeGranuleAcceptors(Indexer indexer) {
return finalGranuleAcceptors;
}

private GranuleGeometryHandler initializeGeometryHandler(Indexer indexer) {
private GranuleHandler initializeGeometryHandler(Indexer indexer) {

GranuleGeometryHandler geomHandler = null;
GranuleHandler geomHandler = null;
if (indexer != null) {
String geometryHandlerString = IndexerUtils.getParameter(Prop.GEOMETRY_HANDLER, indexer);
GranuleGeometryHandlerFactorySPI factory =
GranuleGeometryHandlerFactoryFinder.getGeometryHandlersSPI()
GranuleHandlerFactorySPI factory =
GranuleHandlerFactoryFinder.getGeometryHandlersSPI()
.get(geometryHandlerString);
if (factory != null) {
geomHandler = factory.create();
}
}

if (geomHandler == null) {
geomHandler = new DefaultGranuleGeometryHandler();
geomHandler = new DefaultGranuleHandler();
}


Expand Down Expand Up @@ -530,7 +530,7 @@ private void updateCatalog(
final String fileLocation = prepareLocation(configuration, fileBeingProcessed);
final String locationAttribute = configuration.getParameter(Prop.LOCATION_ATTRIBUTE);
MosaicConfigurationBean mosaicConfiguration = this.getConfigurations().get(coverageName);
GranuleGeometryHandler geometryHandler = this.getGeometryHandler();
GranuleHandler geometryHandler = this.getGeometryHandler();

// getting input granules
if (inputReader instanceof StructuredGridCoverage2DReader) {
Expand All @@ -540,15 +540,14 @@ private void updateCatalog(
handleStructuredGridCoverage(
((StructuredGridCoverage2DReader) inputReader).getGranules(coverageName, true),
fileBeingProcessed, inputReader, propertiesCollectors, indexSchema, feature,
collection, fileLocation, locationAttribute, mosaicConfiguration,
geometryHandler);
collection, fileLocation, locationAttribute, mosaicConfiguration);

} else {
//
// Case B: old style reader, proceed with classic way, using properties collectors
//
geometryHandler.handleGeometry(
inputReader, feature, indexSchema, mosaicConfiguration);
inputReader, feature, indexSchema,null,null, mosaicConfiguration);
feature.setAttribute(locationAttribute, fileLocation);

updateAttributesFromCollectors(feature, fileBeingProcessed, inputReader, propertiesCollectors);
Expand All @@ -569,8 +568,7 @@ private void handleStructuredGridCoverage(GranuleSource granules, final File fil
final List<PropertiesCollector> propertiesCollectors,
final SimpleFeatureType indexSchema, SimpleFeature feature,
final ListFeatureCollection collection, final String fileLocation,
final String locationAttribute, final MosaicConfigurationBean mosaicConfiguration,
final GranuleGeometryHandler geometryHandler) throws IOException
final String locationAttribute, final MosaicConfigurationBean mosaicConfiguration) throws IOException
{

// Getting granule source and its input granules
Expand All @@ -586,6 +584,7 @@ private void handleStructuredGridCoverage(GranuleSource granules, final File fil
}

// Collecting granules
final GranuleHandler geometryHandler=this.granuleGeomHandler;
originCollection.accepts( new AbstractFeatureVisitor(){
public void visit( Feature feature ) {
if(feature instanceof SimpleFeature)
Expand Down Expand Up @@ -640,7 +639,7 @@ public void visit( Feature feature ) {
}, listener);
}

private GranuleGeometryHandler getGeometryHandler() {
private GranuleHandler getGeometryHandler() {
return this.granuleGeomHandler;
}

Expand Down
Expand Up @@ -20,15 +20,12 @@
import java.awt.image.ColorModel;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;

import org.geotools.coverage.grid.io.GridCoverage2DReader;
import org.geotools.gce.imagemosaic.ImageMosaicConfigHandler;
import org.geotools.gce.imagemosaic.ImageMosaicEventHandlers;
import org.geotools.gce.imagemosaic.MosaicConfigurationBean;
import org.geotools.gce.imagemosaic.RasterManager;
import org.geotools.gce.imagemosaic.Utils;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilderConfiguration;
import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

Expand Down
Expand Up @@ -22,10 +22,6 @@

import org.geotools.coverage.grid.io.GridCoverage2DReader;
import org.geotools.gce.imagemosaic.ImageMosaicConfigHandler;
import org.geotools.gce.imagemosaic.ImageMosaicEventHandlers;
import org.geotools.gce.imagemosaic.MosaicConfigurationBean;
import org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilderConfiguration;
import org.opengis.coverage.grid.GridCoverageReader;

/**
* Class responsible for determining whether a given coverage should or should not be part of the
Expand Down
Expand Up @@ -29,28 +29,27 @@
import com.vividsolutions.jts.geom.PrecisionModel;

/**
* Default granule geometry handling
* Default granule handling
*/
public class DefaultGranuleGeometryHandler implements GranuleGeometryHandler {
public class DefaultGranuleHandler implements GranuleHandler {

private final static PrecisionModel PRECISION_MODEL = new PrecisionModel(PrecisionModel.FLOATING);
private final static GeometryFactory GEOM_FACTORY = new GeometryFactory(PRECISION_MODEL);

@Override
public void handleGeometry(GridCoverage2DReader inputReader, SimpleFeature feature,
SimpleFeatureType indexSchema, MosaicConfigurationBean mosaicConfigurationBean) {
Envelope coverageEnvelope = inputReader.getOriginalEnvelope();
feature.setAttribute(indexSchema.getGeometryDescriptor().getLocalName(),
GEOM_FACTORY.toGeometry(new ReferencedEnvelope(coverageEnvelope)));
}

@Override
public void handleGeometry(StructuredGridCoverage2DReader inputReader,
public void handleGeometry(GridCoverage2DReader inputReader,
SimpleFeature targetFeature, SimpleFeatureType targetFeatureType,
SimpleFeature inputFeature, SimpleFeatureType inputFeatureType,
SimpleFeature feature, SimpleFeatureType inputFeatureType,
MosaicConfigurationBean mosaicConfiguration) {

Object geometryAttribute = inputFeature.getAttribute(inputFeatureType.getGeometryDescriptor().getName());
targetFeature.setAttribute(targetFeatureType.getGeometryDescriptor().getName(), geometryAttribute);
if(inputReader instanceof StructuredGridCoverage2DReader){
Object geometryAttribute = feature.getAttribute(inputFeatureType.getGeometryDescriptor().getName());
targetFeature.setAttribute(targetFeatureType.getGeometryDescriptor().getName(), geometryAttribute);
}else {
Envelope coverageEnvelope = inputReader.getOriginalEnvelope();
feature.setAttribute(inputFeatureType.getGeometryDescriptor().getLocalName(),
GEOM_FACTORY.toGeometry(new ReferencedEnvelope(coverageEnvelope)));
}

}
}
Expand Up @@ -20,9 +20,9 @@
/**
* Default factory for geometry handler
*/
public class DefaultGeometryHandlerFactory implements GranuleGeometryHandlerFactorySPI {
public class DefaultGranuleHandlerFactory implements GranuleHandlerFactorySPI {
@Override
public GranuleGeometryHandler create() {
return new DefaultGranuleGeometryHandler();
public GranuleHandler create() {
return new DefaultGranuleHandler();
}
}
Expand Up @@ -18,27 +18,17 @@
package org.geotools.gce.imagemosaic.geomhandler;

import org.geotools.coverage.grid.io.GridCoverage2DReader;
import org.geotools.coverage.grid.io.StructuredGridCoverage2DReader;
import org.geotools.gce.imagemosaic.MosaicConfigurationBean;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;

/**
* Handle setting the geometry of the index feature for incoming granules
*/
public interface GranuleGeometryHandler {
public interface GranuleHandler {



/**
* Handle the case of a regular grid coverage being added to the mosaic. In the default case
* this is generally just taking the envelope from the coverage and adding it to the target
* feature.
* @param inputReader input reader of the incoming granule
* @param feature target index feature
* @param indexSchema schema of the index
* @param mosaicConfigurationBean the mosaic configuration
*/
void handleGeometry(GridCoverage2DReader inputReader, SimpleFeature feature,
SimpleFeatureType indexSchema, MosaicConfigurationBean mosaicConfigurationBean);

/**
* Handle the case of a structured grid coverage being added to the mosaic. In the default case
Expand All @@ -52,7 +42,7 @@ void handleGeometry(GridCoverage2DReader inputReader, SimpleFeature feature,
* @param mosaicConfiguration the mosaic configuration
*/
void handleGeometry(
StructuredGridCoverage2DReader inputReader,
GridCoverage2DReader inputReader,
SimpleFeature targetFeature,
SimpleFeatureType targetFeatureType,
SimpleFeature inputFeature,
Expand Down
Expand Up @@ -26,17 +26,17 @@
import org.geotools.factory.FactoryRegistry;

/**
* Access the granule geometry handler factories
* Access the granule handler factories
*/
public class GranuleGeometryHandlerFactoryFinder {
public class GranuleHandlerFactoryFinder {
private static FactoryCreator registry;

public static synchronized Map<String, GranuleGeometryHandlerFactorySPI> getGeometryHandlersSPI() {
public static synchronized Map<String, GranuleHandlerFactorySPI> getGeometryHandlersSPI() {
// get all GridFormatFactorySpi implementations
final Iterator<GranuleGeometryHandlerFactorySPI> it = getServiceRegistry().getServiceProviders(GranuleGeometryHandlerFactorySPI.class, true);
Map<String, GranuleGeometryHandlerFactorySPI> acceptorFactorySPIMap = new HashMap<>();
final Iterator<GranuleHandlerFactorySPI> it = getServiceRegistry().getServiceProviders(GranuleHandlerFactorySPI.class, true);
Map<String, GranuleHandlerFactorySPI> acceptorFactorySPIMap = new HashMap<>();
while (it.hasNext()) {
GranuleGeometryHandlerFactorySPI GranuleGeometryHandlerFactorySPI = it.next();
GranuleHandlerFactorySPI GranuleGeometryHandlerFactorySPI = it.next();
acceptorFactorySPIMap.put(GranuleGeometryHandlerFactorySPI.getClass().getName(),
GranuleGeometryHandlerFactorySPI);
}
Expand All @@ -49,7 +49,7 @@ public static synchronized Map<String, GranuleGeometryHandlerFactorySPI> getGeom
*/
private static FactoryRegistry getServiceRegistry() {
if (registry == null) {
registry = new FactoryCreator(Arrays.asList(new Class<?>[] { GranuleGeometryHandlerFactorySPI.class }));
registry = new FactoryCreator(Arrays.asList(new Class<?>[] { GranuleHandlerFactorySPI.class }));
}
return registry;
}
Expand Down
Expand Up @@ -20,6 +20,6 @@
/**
* Simple factory for GranuleGeometryHandlers
*/
public interface GranuleGeometryHandlerFactorySPI {
GranuleGeometryHandler create();
public interface GranuleHandlerFactorySPI {
GranuleHandler create();
}

This file was deleted.

@@ -0,0 +1 @@
org.geotools.gce.imagemosaic.geomhandler.DefaultHandlerFactory

0 comments on commit 51dcc6e

Please sign in to comment.