コード例 #1
0
ファイル: RapidEyeL1Reader.java プロジェクト: stevefoga/s2tbx
 private void parseAdditionalMetadataFiles() {
   String[] fileNames = getMetadataFileNames(RapidEyeConstants.METADATA_FILE_SUFFIX);
   if (fileNames != null && fileNames.length > 0) {
     for (String fileName : fileNames) {
       try {
         logger.info(String.format("Reading metadata file %s", fileName));
         RapidEyeMetadata metadataFile =
             XmlMetadata.create(RapidEyeMetadata.class, productDirectory.getFile(fileName));
         if (metadataFile == null) {
           logger.warning(String.format("Error while reading metadata file %s", fileName));
         } else {
           metadataFile.setFileName(fileName);
           MetadataElement newNode = null;
           if (fileName.endsWith("_rpc.xml")) {
             newNode = new MetadataElement("Rational Polynomial Coefficients");
             XmlMetadata.CopyChildElements(metadataFile.getRootElement(), newNode);
           } else if (fileName.endsWith("_sci.xml")) {
             newNode = new MetadataElement("Spacecraft Information");
             XmlMetadata.CopyChildElements(metadataFile.getRootElement(), newNode);
           }
           if (newNode != null) metadata.getRootElement().addElement(newNode);
         }
       } catch (IOException e) {
         logger.warning(String.format("Error encountered while opening file %s", fileName));
       }
     }
   }
 }
コード例 #2
0
ファイル: RapidEyeL1Reader.java プロジェクト: stevefoga/s2tbx
  @Override
  protected Product readProductNodesImpl() throws IOException {
    productDirectory = RapidEyeReader.getInput(getInput());
    // String dirName =
    // productDirectory.getBasePath().substring(productDirectory.getBasePath().lastIndexOf(File.separator) + 1);
    String metadataFileName = productDirectory.findFirst(RapidEyeConstants.METADATA_FILE_SUFFIX);
    File metadataFile = productDirectory.getFile(metadataFileName);
    // First parse *_metadata.xml
    if (metadataFile.exists()) {
      logger.info("Reading product metadata");
      metadata = XmlMetadata.create(RapidEyeMetadata.class, metadataFile);
      if (metadata == null) {
        logger.warning(
            String.format("Error while reading metadata file %s", metadataFile.getName()));
      } else {
        metadata.setFileName(metadataFile.getName());
        String metadataProfile = metadata.getMetadataProfile();
        if (metadataProfile == null || !metadataProfile.startsWith(RapidEyeConstants.PROFILE_L1)) {
          IOException ex =
              new IOException(
                  "The selected product is not a RapidEye L1 product. Please use the appropriate filter");
          logger.log(Level.SEVERE, ex.getMessage(), ex);
          throw ex;
        }
      }
    } else {
      logger.info("No metadata file found");
    }
    // Second, parse other *.xml if exist
    parseAdditionalMetadataFiles();

    try {
      String[] nitfFiles = getRasterFileNames();
      for (int i = 0; i < nitfFiles.length; i++) {
        NITFReaderWrapper reader = new NITFReaderWrapper(productDirectory.getFile(nitfFiles[i]));
        if (product == null) {
          product =
              new Product(
                  metadata != null
                      ? metadata.getProductName()
                      : RapidEyeConstants.PRODUCT_GENERIC_NAME,
                  RapidEyeConstants.L1_FORMAT_NAMES[0],
                  metadata != null ? metadata.getRasterWidth() : reader.getWidth(),
                  metadata != null ? metadata.getRasterHeight() : reader.getHeight(),
                  this);
          if (metadata != null) {
            product.setProductType(metadata.getMetadataProfile());
            product.setStartTime(metadata.getProductStartTime());
            product.setEndTime(metadata.getProductEndTime());
            product.getMetadataRoot().addElement(metadata.getRootElement());
            NITFMetadata nitfMetadata = reader.getMetadata();
            if (nitfMetadata != null)
              product.getMetadataRoot().addElement(nitfMetadata.getMetadataRoot());
          }
          product.setPreferredTileSize(getPreferredTileSize());
        }
        addBandToProduct(product, reader, i);
      }
      if (product != null) {
        readMasks();
        initGeoCoding(product);
        product.setModified(false);
      }
    } catch (IIOException e) {
      logger.severe("Product is not a valid RapidEye L1 data product!");
    }
    product.setFileLocation(new File(productDirectory.getBasePath()));
    return product;
  }