Package org.geotools.gce.imagemosaic.catalog

Examples of org.geotools.gce.imagemosaic.catalog.CatalogConfigurationBean


      LOGGER.log(Level.FINE,"Trying to load properties file from URL:"+sourceURL);
    }
   
    // ret value
    final MosaicConfigurationBean retValue = new MosaicConfigurationBean();
    final CatalogConfigurationBean catalogConfigurationBean = new CatalogConfigurationBean();
    retValue.setCatalogConfigurationBean(catalogConfigurationBean);
    final boolean ignoreSome = ignorePropertiesSet != null && !ignorePropertiesSet.isEmpty();

        //
        // load the properties file
        //
        URL propsURL = sourceURL;
        if (!sourceURL.toExternalForm().endsWith(".properties")) {
            propsURL = DataUtilities.changeUrlExt(sourceURL, "properties");
            if (propsURL.getProtocol().equals("file")) {
                final File sourceFile = DataUtilities.urlToFile(propsURL);
                if (!sourceFile.exists()) {
                    if (LOGGER.isLoggable(Level.INFO)) {
                        LOGGER.info("properties file doesn't exist");
                    }
                    return null;
                }
            }
        }
   
    final Properties properties = loadPropertiesFromURL(propsURL);
    if (properties == null) {
      if (LOGGER.isLoggable(Level.INFO))
        LOGGER.info("Unable to load mosaic properties file");
      return null;
    }

    String[] pairs = null;
    String pair[] = null;
   
    //
    // imposed bbox is optional
    //             
    if (!ignoreSome || !ignorePropertiesSet.contains(Prop.ENVELOPE2D)) {
      String bboxString = properties.getProperty(Prop.ENVELOPE2D, null);
      if(bboxString!=null){
        bboxString=bboxString.trim();
        try{
          ReferencedEnvelope bbox = parseEnvelope(bboxString);
          if(bbox!=null)
            retValue.setEnvelope(bbox);
          else
            if (LOGGER.isLoggable(Level.INFO))
              LOGGER.info("Cannot parse imposed bbox.");
        }catch (Exception e) {
          if (LOGGER.isLoggable(Level.INFO))
            LOGGER.log(Level.INFO,"Cannot parse imposed bbox.",e);
        }
      }
       
    }
   
    if (!ignoreSome
                        || !ignorePropertiesSet.contains(Prop.AUXILIARY_FILE)) {
                    retValue.setAuxiliaryFilePath(properties.getProperty(Prop.AUXILIARY_FILE));
        }

                if (!ignoreSome || !ignorePropertiesSet.contains(Prop.CHECK_AUXILIARY_METADATA)) {
                    final boolean checkAuxiliaryMetadata = Boolean.valueOf(properties.getProperty(
                            Prop.CHECK_AUXILIARY_METADATA, "false").trim());
                    retValue.setCheckAuxiliaryMetadata(checkAuxiliaryMetadata);
                }
               
   
    //
    // resolutions levels
    //             
    if (!ignoreSome || !ignorePropertiesSet.contains(Prop.LEVELS)) {
      int levelsNumber = Integer.parseInt(properties.getProperty(Prop.LEVELS_NUM, "1").trim());
      retValue.setLevelsNum(levelsNumber);
      if (!properties.containsKey(Prop.LEVELS)) {
        if (LOGGER.isLoggable(Level.INFO))
          LOGGER.info("Required key Levels not found.");
        return null;
      }
      final String levels = properties.getProperty(Prop.LEVELS).trim();
      pairs = levels.split(" ");
      if (pairs == null || pairs.length != levelsNumber) {
        if (LOGGER.isLoggable(Level.INFO))
          LOGGER.info("Levels number is different from the provided number of levels resoltion.");
        return null;
      }
      final double[][] resolutions = new double[levelsNumber][2];
      for (int i = 0; i < levelsNumber; i++) {
        pair = pairs[i].split(",");
        if (pair == null || pair.length != 2) {
          if (LOGGER.isLoggable(Level.INFO))
            LOGGER.info("OverviewLevel number is different from the provided number of levels resoltion.");
          return null;
        }
        resolutions[i][0] = Double.parseDouble(pair[0]);
        resolutions[i][1] = Double.parseDouble(pair[1]);
      }
      retValue.setLevels(resolutions);
    }

    //
    // typename, is mandatory when we don't use shapeiles
    //             
    if (!ignoreSome || !ignorePropertiesSet.contains(Prop.TYPENAME)) {
      String typeName = properties.getProperty(Prop.TYPENAME, null);
      catalogConfigurationBean.setTypeName(typeName);
    }

    //
    // suggested spi is optional
    //
    if (!ignoreSome || !ignorePropertiesSet.contains(Prop.SUGGESTED_SPI)) {
      if (properties.containsKey(Prop.SUGGESTED_SPI)) {
        final String suggestedSPI = properties.getProperty(
            Prop.SUGGESTED_SPI).trim();
        catalogConfigurationBean.setSuggestedSPI(suggestedSPI);
      }
    }

    //
    // time attribute is optional
    //
    if (properties.containsKey(Prop.TIME_ATTRIBUTE)) {
            final String timeAttribute = properties.getProperty("TimeAttribute").trim();
      retValue.setTimeAttribute(timeAttribute);
    }

    //
    // elevation attribute is optional
    //
    if (properties.containsKey(Prop.ELEVATION_ATTRIBUTE)) {
            final String elevationAttribute = properties.getProperty(Prop.ELEVATION_ATTRIBUTE).trim();
      retValue.setElevationAttribute(elevationAttribute);
    }

    //
                // additional domain attribute is optional
                //
                if (properties.containsKey(Prop.ADDITIONAL_DOMAIN_ATTRIBUTES)) {
                        final String additionalDomainAttributes = properties.getProperty(Prop.ADDITIONAL_DOMAIN_ATTRIBUTES).trim();
                        retValue.setAdditionalDomainAttributes(additionalDomainAttributes);
                }

    //
    // caching
    //
    if (properties.containsKey(Prop.CACHING)) {
      String caching = properties.getProperty(Prop.CACHING).trim();
      try {
          catalogConfigurationBean.setCaching(Boolean.valueOf(caching));
      } catch (Throwable e) {
          catalogConfigurationBean.setCaching(Boolean.valueOf(Utils.DEFAULT_CACHING_BEHAVIOR));
      }
    }

    //
    // name is not optional
    //
    if (!ignoreSome || !ignorePropertiesSet.contains(Prop.NAME)){
                    if(!properties.containsKey(Prop.NAME)) {
                            if(LOGGER.isLoggable(Level.SEVERE))
                                    LOGGER.severe("Required key Name not found.");         
                            return null;
                    }                      
                    String coverageName = properties.getProperty(Prop.NAME).trim();
                    retValue.setName(coverageName);
                }

    // need a color expansion?
    // this is a newly added property we have to be ready to the case where
    // we do not find it.
    if (!ignoreSome || !ignorePropertiesSet.contains(Prop.EXP_RGB)) {
      final boolean expandMe = Boolean.valueOf(properties.getProperty(
          Prop.EXP_RGB, "false").trim());
      retValue.setExpandToRGB(expandMe);
    }
   
    //
    // Is heterogeneous granules mosaic
    //
                if (!ignoreSome || !ignorePropertiesSet.contains(Prop.HETEROGENEOUS)) {
                    final boolean heterogeneous = Boolean.valueOf(properties.getProperty(
                            Prop.HETEROGENEOUS, "false").trim());
                    catalogConfigurationBean.setHeterogeneous(heterogeneous);
                }

    //
    // Absolute or relative path
    //
    if (!ignoreSome || !ignorePropertiesSet.contains(Prop.ABSOLUTE_PATH)) {
      final boolean absolutePath = Boolean.valueOf(properties
          .getProperty(Prop.ABSOLUTE_PATH,
              Boolean.toString(Utils.DEFAULT_PATH_BEHAVIOR))
          .trim());
      catalogConfigurationBean.setAbsolutePath(absolutePath);
    }

    //
    // Footprint management
    //
    if (!ignoreSome
        || !ignorePropertiesSet.contains(Prop.FOOTPRINT_MANAGEMENT)) {
      final boolean footprintManagement = Boolean.valueOf(properties
          .getProperty(Prop.FOOTPRINT_MANAGEMENT, "false").trim());
      retValue.setFootprintManagement(footprintManagement);
    }

    //
    // location
    // 
    if (!ignoreSome
        || !ignorePropertiesSet.contains(Prop.LOCATION_ATTRIBUTE)) {
        catalogConfigurationBean.setLocationAttribute(properties.getProperty(
          Prop.LOCATION_ATTRIBUTE, Utils.DEFAULT_LOCATION_ATTRIBUTE).trim());
    }
   
    // return value
    return retValue;
View Full Code Here


        // load defaultSM and defaultCM by using the sample_image if it was provided
        loadSampleImage(configuration);

        if (configuration != null) {
            CatalogConfigurationBean catalogBean = configuration.getCatalogConfigurationBean();
            typeName = catalogBean != null ? catalogBean.getTypeName() : null;
            initDomains(configuration);
            if (defaultSM == null) {
                defaultSM = configuration.getSampleModel();
            }
View Full Code Here

        // FINAL STEP
        //
        // CREATING GENERAL INFO FILE
        //

        CatalogConfigurationBean catalogConfigurationBean = mosaicConfiguration
                .getCatalogConfigurationBean();

        // envelope
        final Properties properties = new Properties();
        properties.setProperty(Utils.Prop.ABSOLUTE_PATH,
                Boolean.toString(catalogConfigurationBean.isAbsolutePath()));
        properties.setProperty(Utils.Prop.LOCATION_ATTRIBUTE,
                catalogConfigurationBean.getLocationAttribute());

        // Time
        final String timeAttribute = mosaicConfiguration.getTimeAttribute();
        if (timeAttribute != null) {
            properties.setProperty(Utils.Prop.TIME_ATTRIBUTE,
                    mosaicConfiguration.getTimeAttribute());
        }

        // Elevation
        final String elevationAttribute = mosaicConfiguration.getElevationAttribute();
        if (elevationAttribute != null) {
            properties.setProperty(Utils.Prop.ELEVATION_ATTRIBUTE,
                    mosaicConfiguration.getElevationAttribute());
        }

        // Additional domains
        final String additionalDomainAttribute = mosaicConfiguration
                .getAdditionalDomainAttributes();
        if (additionalDomainAttribute != null) {
            properties.setProperty(Utils.Prop.ADDITIONAL_DOMAIN_ATTRIBUTES,
                    mosaicConfiguration.getAdditionalDomainAttributes());
        }

        final int numberOfLevels = mosaicConfiguration.getLevelsNum();
        final double[][] resolutionLevels = mosaicConfiguration.getLevels();
        properties.setProperty(Utils.Prop.LEVELS_NUM, Integer.toString(numberOfLevels));
        final StringBuilder levels = new StringBuilder();
        for (int k = 0; k < numberOfLevels; k++) {
            levels.append(Double.toString(resolutionLevels[k][0])).append(",")
                    .append(Double.toString(resolutionLevels[k][1]));
            if (k < numberOfLevels - 1) {
                levels.append(" ");
            }
        }
        properties.setProperty(Utils.Prop.LEVELS, levels.toString());
        properties.setProperty(Utils.Prop.NAME, mosaicConfiguration.getName());
        properties.setProperty(Utils.Prop.TYPENAME, mosaicConfiguration.getName());
        properties.setProperty(Utils.Prop.EXP_RGB,
                Boolean.toString(mosaicConfiguration.isExpandToRGB()));
        properties.setProperty(Utils.Prop.CHECK_AUXILIARY_METADATA,
                Boolean.toString(mosaicConfiguration.isCheckAuxiliaryMetadata()));
        properties.setProperty(Utils.Prop.HETEROGENEOUS,
                Boolean.toString(catalogConfigurationBean.isHeterogeneous()));

        if (cachedReaderSPI != null) {
            // suggested spi
            properties.setProperty(Utils.Prop.SUGGESTED_SPI, cachedReaderSPI.getClass().getName());
        }

        // write down imposed bbox
        if (imposedBBox != null) {
            properties.setProperty(
                    Utils.Prop.ENVELOPE2D,
                    imposedBBox.getMinX() + "," + imposedBBox.getMinY() + " "
                            + imposedBBox.getMaxX() + "," + imposedBBox.getMaxY());
        }
        properties.setProperty(Utils.Prop.CACHING,
                Boolean.toString(catalogConfigurationBean.isCaching()));
        if (mosaicConfiguration.getAuxiliaryFilePath() != null) {
            properties.setProperty(Utils.Prop.AUXILIARY_FILE,
                    mosaicConfiguration.getAuxiliaryFilePath());
        }
View Full Code Here

                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.

            CatalogConfigurationBean catalogConfigurationBean = bean;
            if (!catalogConfigurationBean.isHeterogeneous()) {

                // There is no need to check resolutions if the mosaic
                // has been already marked as heterogeneous

                numberOfLevels = coverageReader.getNumOverviews(inputCoverageName) + 1;
                boolean needUpdate = false;

                //
                // Heterogeneousity check
                //
                if (numberOfLevels != mosaicConfiguration.getLevelsNum()) {
                    catalogConfigurationBean.setHeterogeneous(true);
                    if (numberOfLevels > mosaicConfiguration.getLevelsNum()) {
                        resolutionLevels = coverageReader.getResolutionLevels(inputCoverageName);
                        mosaicConfiguration.setLevels(resolutionLevels);
                        mosaicConfiguration.setLevelsNum(numberOfLevels);
                        needUpdate = true;
                    }
                } else {
                    final double[][] mosaicLevels = mosaicConfiguration.getLevels();
                    resolutionLevels = coverageReader.getResolutionLevels(inputCoverageName);
                    final boolean homogeneousLevels = Utils.homogeneousCheck(numberOfLevels,
                            resolutionLevels, mosaicLevels);
                    if (!homogeneousLevels) {
                        catalogConfigurationBean.setHeterogeneous(true);
                        needUpdate = true;
                    }
                }
                // configuration need to be updated
                if (needUpdate) {
View Full Code Here

     * @param sourceURL
     * @param configuration
     * @throws IOException
     */
    private static void checkTypeName(URL sourceURL, MosaicConfigurationBean configuration) throws IOException {
        CatalogConfigurationBean catalogBean = configuration.getCatalogConfigurationBean();
        if (catalogBean.getTypeName() == null) {
            if (sourceURL.getPath().endsWith("shp")) {
                // In case we didn't find a typeName and we are dealing with a shape index,
                // we set the typeName as the shape name
                final File file = DataUtilities.urlToFile(sourceURL);
                catalogBean.setTypeName(FilenameUtils.getBaseName(file.getCanonicalPath()));
            } else {
                // use the default "mosaic" name
                catalogBean.setTypeName("mosaic");
            }
        }
    }
View Full Code Here

     * @param hints
     * @return
     * @throws IOException
     */
    static GranuleCatalog createCatalog(final URL sourceURL, final MosaicConfigurationBean configuration, Hints hints) throws IOException {
        CatalogConfigurationBean catalogBean = configuration.getCatalogConfigurationBean();
       
        // Check the typeName
        checkTypeName(sourceURL, configuration);
        if (hints != null && hints.containsKey(Hints.MOSAIC_LOCATION_ATTRIBUTE)) {
            final String hintLocation = (String) hints
                    .get(Hints.MOSAIC_LOCATION_ATTRIBUTE);
            if (!catalogBean.getLocationAttribute().equalsIgnoreCase(hintLocation)) {
                throw new DataSourceException("wrong location attribute");
            }
        }
        // Create the catalog
        GranuleCatalog catalog = GranuleCatalogFactory.createGranuleCatalog(sourceURL, catalogBean, null,hints);
View Full Code Here

    // we do not find it.
    expandMe = configuration.isExpandToRGB();
   
    checkAuxiliaryMetadata = configuration.isCheckAuxiliaryMetadata();
   
    CatalogConfigurationBean catalogConfigurationBean = configuration.getCatalogConfigurationBean();
   
    // do we have heterogenous granules
    heterogeneousGranules = catalogConfigurationBean.isHeterogeneous();

    // absolute or relative path
    pathType = catalogConfigurationBean.isAbsolutePath()?PathType.ABSOLUTE:PathType.RELATIVE;
   
    //
    // location attribute
    //
    locationAttributeName = catalogConfigurationBean.getLocationAttribute();
   
    // suggested SPI
    final String suggestedSPIClass = catalogConfigurationBean.getSuggestedSPI();
    if (suggestedSPIClass != null){
      try {
        final Class<?> clazz=Class.forName(suggestedSPIClass);
        if(clazz.newInstance() instanceof ImageReaderSpi)
          suggestedSPI=(ImageReaderSpi)clazz.newInstance();
        else
          suggestedSPI=null;
      } catch (Exception e) {
        if(LOGGER.isLoggable(Level.FINE))
          LOGGER.log(Level.FINE,e.getLocalizedMessage(),e);
        suggestedSPI=null;
      }
    }

    // caching for the index
    cachingIndex = catalogConfigurationBean.isCaching();
   
    // imposed BBOX
                if(configuration.getEnvelope()!=null){
                this.imposedBBox=true;
                // we set the BBOX later to retain also the CRS
                } else {
                  this.imposedBBox=false;
                }
   
    // typeName to be used for reading the mosaic
    this.typeName = catalogConfigurationBean.getTypeName();

  }
View Full Code Here

              //get the properties file
              final MosaicConfigurationBean configuration = Utils.loadMosaicProperties(propsUrl, Utils.DEFAULT_LOCATION_ATTRIBUTE);
              if(configuration==null)
                return false;

          CatalogConfigurationBean catalogBean = configuration.getCatalogConfigurationBean();
              // we need the type name with a DB to pick up the right table
              // for shapefiles this can be null so taht we select the first and ony one
              String typeName = catalogBean.getTypeName();             
              if(typeName==null){
                    final String[] typeNames = tileIndexStore.getTypeNames();
                    if (typeNames.length <= 0)
                        return false;
                    typeName= typeNames[0];               
              }
                if(typeName==null)
            return false;

              // now try to connect to the index
                SimpleFeatureSource featureSource = null;
                try{
                  featureSource=tileIndexStore.getFeatureSource(typeName);              
                }catch (Exception e) {
                  featureSource = tileIndexStore.getFeatureSource(typeName.toUpperCase());
        }
                if(featureSource==null){
                  return false;
                }
               
                final SimpleFeatureType schema = featureSource.getSchema();
                if(schema==null)
            return false;
               
                crs = featureSource.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem();
                if(crs==null)
            return false;             
                // looking for the location attribute
              final String locationAttributeName = catalogBean.getLocationAttribute();
                if (schema.getDescriptor(locationAttributeName) == null&&schema.getDescriptor(locationAttributeName.toUpperCase()) == null)
                    return false;  
               
          return true;
       
View Full Code Here

TOP

Related Classes of org.geotools.gce.imagemosaic.catalog.CatalogConfigurationBean

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.