Package org.geotools.gce.imagemosaic.catalogbuilder

Examples of org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilderConfiguration


      final String wildcard,
      final boolean absolutePath,
      final Hints hints) {

    // create a mosaic index builder and set the relevant elements
    final CatalogBuilderConfiguration configuration = new CatalogBuilderConfiguration();
    configuration.setHints(hints);// retain hints as this may contain an instance of an ImageMosaicReader
    List<Parameter> parameterList = configuration.getIndexer().getParameters().getParameter();
              
               IndexerUtils.setParam(parameterList, Prop.ABSOLUTE_PATH, Boolean.toString(absolutePath));
               IndexerUtils.setParam(parameterList, Prop.ROOT_MOSAIC_DIR, location);
               IndexerUtils.setParam(parameterList, Prop.INDEX_NAME, indexName);
               IndexerUtils.setParam(parameterList, Prop.WILDCARD, wildcard);
View Full Code Here


                IndexerUtils.getParam(params, Prop.ROOT_MOSAIC_DIR));

        // check config
        configuration.check();

        this.runConfiguration = new CatalogBuilderConfiguration(configuration);
    }
View Full Code Here

        SampleModel sm = null;
        ColorModel cm = null;
        int numberOfLevels = 1;
        double[][] resolutionLevels = null;
        CatalogBuilderConfiguration catalogConfig;
        if (mosaicConfiguration == null) {
            catalogConfig = getRunConfiguration();
            // We don't have a configuration for this configuration

            // Get the type specifier for this image and the check that the
            // image has the correct sample model and color model.
            // If this is the first cycle of the loop we initialize everything.
            //
            ImageLayout layout = coverageReader.getImageLayout(inputCoverageName);
            cm = layout.getColorModel(null);
            sm = layout.getSampleModel(null);
            numberOfLevels = coverageReader.getNumOverviews(inputCoverageName) + 1;
            resolutionLevels = coverageReader.getResolutionLevels(inputCoverageName);

            // at the first step we initialize everything that we will
            // reuse afterwards starting with color models, sample
            // models, crs, etc....

            configBuilder.setSampleModel(sm);
            configBuilder.setColorModel(cm);
            ColorModel defaultCM = cm;

            // Checking palette
            if (defaultCM instanceof IndexColorModel) {
                IndexColorModel icm = (IndexColorModel) defaultCM;
                int numBands = defaultCM.getNumColorComponents();
                byte[][] defaultPalette = new byte[3][icm.getMapSize()];
                icm.getReds(defaultPalette[0]);
                icm.getGreens(defaultPalette[0]);
                icm.getBlues(defaultPalette[0]);
                if (numBands == 4) {
                    icm.getAlphas(defaultPalette[0]);
                }
                configBuilder.setPalette(defaultPalette);
            }

            // STEP 2.A
            // Preparing configuration
            configBuilder.setCrs(actualCRS);
            configBuilder.setLevels(resolutionLevels);
            configBuilder.setLevelsNum(numberOfLevels);
            configBuilder.setName(coverageName);
            configBuilder.setTimeAttribute(IndexerUtils.getAttribute(coverageName,
                    Utils.TIME_DOMAIN, indexer));
            configBuilder.setElevationAttribute(IndexerUtils.getAttribute(coverageName,
                    Utils.ELEVATION_DOMAIN, indexer));
            configBuilder.setAdditionalDomainAttributes(IndexerUtils.getAttribute(coverageName,
                    Utils.ADDITIONAL_DOMAIN, indexer));

            final Hints runHints = getRunConfiguration().getHints();
            if (runHints != null && runHints.containsKey(Utils.AUXILIARY_FILES_PATH)) {
                String auxiliaryFilePath = (String) runHints.get(Utils.AUXILIARY_FILES_PATH);
                if (auxiliaryFilePath != null && auxiliaryFilePath.trim().length() > 0) {
                    configBuilder.setAuxiliaryFilePath(auxiliaryFilePath);
                }
            }

            final CatalogConfigurationBean catalogConfigurationBean = new CatalogConfigurationBean();
            catalogConfigurationBean.setCaching(IndexerUtils.getParameterAsBoolean(Prop.CACHING,
                    indexer));
            catalogConfigurationBean.setAbsolutePath(IndexerUtils.getParameterAsBoolean(
                    Prop.ABSOLUTE_PATH, indexer));

            catalogConfigurationBean.setLocationAttribute(IndexerUtils.getParameter(
                    Prop.LOCATION_ATTRIBUTE, indexer));
           
            catalogConfigurationBean.setTypeName(coverageName);
           
            configBuilder.setCatalogConfigurationBean(catalogConfigurationBean);
            configBuilder.setCheckAuxiliaryMetadata(IndexerUtils.getParameterAsBoolean(Prop.CHECK_AUXILIARY_METADATA, indexer));

            currentConfigurationBean = configBuilder.getMosaicConfigurationBean();

            // Creating a rasterManager which will be initialized after populating the catalog
            rasterManager = getParentReader().addRasterManager(currentConfigurationBean, false);

            // Creating a granuleStore
            if (!useExistingSchema) {
                // creating the schema
                SimpleFeatureType indexSchema = CatalogManager.createSchema(getRunConfiguration(),
                        currentConfigurationBean.getName(), actualCRS);
                getParentReader().createCoverage(coverageName, indexSchema);
//            } else {
//                rasterManager.typeName = coverageName;
            }
            getConfigurations().put(currentConfigurationBean.getName(), currentConfigurationBean);

        } else {
            catalogConfig = new CatalogBuilderConfiguration();
            CatalogConfigurationBean bean = mosaicConfiguration.getCatalogConfigurationBean();
            catalogConfig.setParameter(Prop.LOCATION_ATTRIBUTE, (bean.getLocationAttribute()));
            catalogConfig.setParameter(Prop.ABSOLUTE_PATH, Boolean.toString(bean.isAbsolutePath()));
            catalogConfig.setParameter(Prop.ROOT_MOSAIC_DIR/* setRootMosaicDirectory( */,
                    getRunConfiguration().getParameter(Prop.ROOT_MOSAIC_DIR));

            // We already have a Configuration for this coverage.
            // Check its properties are compatible with the existing coverage.

View Full Code Here

  }

  @Test
  public void catalogBuilderConfiguration() throws Exception{
    // create a stub configuration
        final CatalogBuilderConfiguration c1 = new CatalogBuilderConfiguration();
        c1.setParameter(Prop.INDEX_NAME, "index");
        c1.setParameter(Prop.LOCATION_ATTRIBUTE, "location");
        c1.setParameter(Prop.ABSOLUTE_PATH, "true");
        c1.setParameter(Prop.ROOT_MOSAIC_DIR, TestData.file(this, "/rgb").toString());
        c1.setParameter(Prop.INDEXING_DIRECTORIES, TestData.file(this,"/rgb").toString());
//        c1.setIndexName("index");
        // c1.setLocationAttribute("location");
//    c1.setAbsolute(true);
//    c1.setRootMosaicDirectory(TestData.file(this,"/rgb").toString());
//    c1.setIndexingDirectories(Arrays.asList(TestData.file(this,"/rgb").toString()));
    assertNotNull(c1.toString());
   
    // create a second stub configuration
        final CatalogBuilderConfiguration c2 = new CatalogBuilderConfiguration();
        c2.setParameter(Prop.INDEX_NAME, "index");
        c2.setParameter(Prop.LOCATION_ATTRIBUTE, "location");
        c2.setParameter(Prop.ABSOLUTE_PATH, "true");
        c2.setParameter(Prop.ROOT_MOSAIC_DIR, TestData.file(this, "/rgb").toString());
        c2.setParameter(Prop.INDEXING_DIRECTORIES, TestData.file(this,"/rgb").toString())
//    c2.setIndexName("index");
//    c2.setLocationAttribute("location");
//    c2.setAbsolute(true);
//    c2.setRootMosaicDirectory(TestData.file(this,"/rgb").toString());
//    c2.setIndexingDirectories(Arrays.asList(TestData.file(this,"/rgb").toString()));
//   
    assertTrue(c1.equals(c2));
    assertEquals(c1.hashCode(), c2.hashCode());
   
    CatalogBuilderConfiguration c3 = c2.clone();
    assertTrue(c3.equals(c2));
    assertEquals(c3.hashCode(), c2.hashCode());
   
    //check errors
    final CatalogBuilderConfiguration c4= new CatalogBuilderConfiguration();
    assertNotNull(c4.toString());
   
  }
View Full Code Here

            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"));
View Full Code Here

  public void buildCachingIndex() throws FileNotFoundException, IOException {
      if (hostnameDefined){
    ImageMosaicDirectoryWalker builder = null;
    ImageMosaicReader reader = null;
    FileInputStream inStream = null;
    CatalogBuilderConfiguration c1 = new CatalogBuilderConfiguration();
//    c1.setIndexName("shpindex");
//    c1.setLocationAttribute("location");
//    c1.setAbsolute(false);
//    c1.setRootMosaicDirectory(TestData.file(this, "/caching").toString());
//    c1.setIndexingDirectories(Arrays.asList(TestData.file(this,"/caching").toString()));
            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, "/caching").toString());
            c1.setParameter(Prop.INDEXING_DIRECTORIES, TestData.file(this,"/caching").toString());
               
    Properties prop = new Properties();
   
   
    try {
     
//      c1.setCaching(false);
        c1.setParameter(Prop.CACHING, "false");

              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, "/caching/" + c1.getIndexName() + ".shp");
      final File propertiesFile = TestData.file(this, "/caching/" + c1.getIndexName() + ".properties");
      assertTrue(relativeMosaic.exists());
      inStream = new FileInputStream(propertiesFile);
      prop.load(inStream);
      String value = prop.getProperty("Caching");
      assertNotNull(value);
      assertTrue (value.toLowerCase().equals("false"));
     
 
      assertTrue(new ImageMosaicFormat().accepts(relativeMosaic));
      reader = (ImageMosaicReader) new ImageMosaicReader(relativeMosaic);
     
      GranuleCatalog catalog = reader.getRasterManager(reader.defaultName).granuleCatalog;
      assertTrue(catalog.getClass().toString().endsWith("GTDataStoreGranuleCatalog"));
    } finally {
        if (inStream != null){
                        IOUtils.closeQuietly(inStream);
                    }
     
      try {
        if (reader != null){
          reader.dispose();
        }
      } catch (Throwable t){
        //Eat exception
      }
    }
   
    try {
     
//      c1.setCaching(true);
      c1.setParameter(Prop.CACHING, "true");

                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, "/caching/" + c1.getIndexName() + ".shp");
      final File propertiesFile = TestData.file(this, "/caching/" + c1.getIndexName() + ".properties");
      inStream = new FileInputStream(propertiesFile);
      prop.load(inStream);
     
      String value = prop.getProperty("Caching");
      assertNotNull(value);
View Full Code Here

  }

  private double[] mosaicLevel(int level) {
     
          // prepare the configuration
          final CatalogBuilderConfiguration configuration = new CatalogBuilderConfiguration();
          configuration.setParameter(Prop.ROOT_MOSAIC_DIR, new File(outputLocation, String.valueOf(level)).getAbsolutePath());
                configuration.setParameter(Prop.INDEX_NAME, name);
                configuration.setParameter(Prop.INDEXING_DIRECTORIES, configuration.getParameter(Prop.ROOT_MOSAIC_DIR));

          // prepare and run the index builder
                ImageMosaicEventHandlers eventHandler=new ImageMosaicEventHandlers();
                final ImageMosaicConfigHandler catalogHandler = new ImageMosaicConfigHandler(configuration, eventHandler);
                // TODO
View Full Code Here

    public static void main(String args[]) {
      
        final CommandLineCatalogBuilderRunner runner = new CommandLineCatalogBuilderRunner(args);
        // prepare the configuration
        final CatalogBuilderConfiguration configuration = new CatalogBuilderConfiguration();
        configuration.setParameter(Prop.ABSOLUTE_PATH, runner.absolute.toString());
        configuration.setParameter(Prop.INDEX_NAME, runner.indexName);
        configuration.setParameter(Prop.FOOTPRINT_MANAGEMENT, runner.footprintManagement.toString());
        configuration.setParameter(Prop.CACHING, runner.caching.toString());
        configuration.setParameter(Prop.ROOT_MOSAIC_DIR, runner.rootMosaicDirectory);
        configuration.setParameter(Prop.WILDCARD, runner.wildcardString);
        configuration.setParameter(Prop.LOCATION_ATTRIBUTE, runner.locationAttribute);
       
//        configuration.setAbsolute(runner.absolute);
//        configuration.setIndexName(runner.indexName);
//        configuration.setFootprintManagement(runner.footprintManagement);
//        configuration.setCaching(runner.caching);
//        configuration.setRootMosaicDirectory(runner.rootMosaicDirectory);
//        configuration.setWildcard(runner.wildcardString);
//        configuration.setLocationAttribute(runner.locationAttribute);

        final String directories = runner.indexingDirectoriesString;
        final String[] dirs_ = directories.split(",");
        final List<String> dirs = new ArrayList<String>();
        for (String dir : dirs_)
            dirs.add(dir);
//        configuration.setIndexingDirectories(dirs);
        configuration.setParameter(Prop.INDEXING_DIRECTORIES, directories);
       
       
        // prepare and run the index builder
        final ImageMosaicEventHandlers eventHandler=new ImageMosaicEventHandlers();
        final ImageMosaicConfigHandler catalogHandler = new ImageMosaicConfigHandler(configuration, eventHandler);
View Full Code Here

TOP

Related Classes of org.geotools.gce.imagemosaic.catalogbuilder.CatalogBuilderConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.