Ejemplo n.º 1
0
  @Override
  public void initialize() throws OperatorException {
    targetProduct = masterProduct;
    validateSourceProducts();
    if (includes == null || includes.length == 0) {
      List<NodeDescriptor> nodeDescriptorList = new ArrayList<NodeDescriptor>();
      for (final Product sourceProduct : sourceProducts) {
        if (sourceProduct != targetProduct) {
          for (String bandName : sourceProduct.getBandNames()) {
            final NodeDescriptor nodeDescriptor = new NodeDescriptor();
            nodeDescriptor.name = bandName;
            nodeDescriptor.productId = getSourceProductId(sourceProduct);
            nodeDescriptorList.add(nodeDescriptor);
          }
        }
      }
      includes = nodeDescriptorList.toArray(new NodeDescriptor[nodeDescriptorList.size()]);
    }

    if (!(excludes == null || excludes.length == 0)) {
      throw new OperatorException("Defining excludes is not supported yet.");
    }
    Set<Product> allSrcProducts = new HashSet<Product>();
    for (NodeDescriptor nodeDescriptor : includes) {
      Product srcProduct = getSourceProduct(nodeDescriptor.productId);
      if (srcProduct == targetProduct) {
        continue;
      }
      if (StringUtils.isNotNullAndNotEmpty(nodeDescriptor.name)) {
        if (StringUtils.isNotNullAndNotEmpty(nodeDescriptor.newName)) {
          copyBandWithFeatures(srcProduct, nodeDescriptor.name, nodeDescriptor.newName);
        } else {
          copyBandWithFeatures(srcProduct, nodeDescriptor.name, nodeDescriptor.name);
        }
        allSrcProducts.add(srcProduct);
      } else if (StringUtils.isNotNullAndNotEmpty(nodeDescriptor.namePattern)) {
        Pattern pattern = Pattern.compile(nodeDescriptor.namePattern);
        for (String bandName : srcProduct.getBandNames()) {
          Matcher matcher = pattern.matcher(bandName);
          if (matcher.matches()) {
            copyBandWithFeatures(srcProduct, bandName, bandName);
            allSrcProducts.add(srcProduct);
          }
        }
      }
    }

    for (Product srcProduct : allSrcProducts) {
      if (srcProduct != targetProduct) {
        mergeAutoGrouping(srcProduct);
        ProductUtils.copyMasks(srcProduct, targetProduct);
        ProductUtils.copyOverlayMasks(srcProduct, targetProduct);
      }
    }
  }
Ejemplo n.º 2
0
  /** Create target product. */
  private void createTargetProduct() {

    targetProduct =
        new Product(
            sourceProduct.getName(),
            sourceProduct.getProductType(),
            sourceImageWidth,
            sourceImageHeight);

    ProductUtils.copyProductNodes(sourceProduct, targetProduct);

    addSelectedBands();

    final MetadataElement absTgt = AbstractMetadata.getAbstractedMetadata(targetProduct);

    if (externalDEMFile != null) { // if external DEM file is specified by user
      AbstractMetadata.setAttribute(absTgt, AbstractMetadata.DEM, externalDEMFile.getPath());
    } else {
      AbstractMetadata.setAttribute(absTgt, AbstractMetadata.DEM, demName);
    }

    absTgt.setAttributeString("DEM resampling method", demResamplingMethod);

    if (externalDEMFile != null) {
      absTgt.setAttributeDouble("external DEM no data value", externalDEMNoDataValue);
    }

    sourceGeoCoding = sourceProduct.getSceneGeoCoding();

    targetProduct.setPreferredTileSize(targetProduct.getSceneRasterWidth(), tileSize);
  }
 @Override
 public boolean validatePage() {
   try {
     crsSelectionPanel.getCrs(
         ProductUtils.getCenterGeoPos(SnapApp.getDefault().getSelectedProduct()));
   } catch (FactoryException ignored) {
     return false;
   }
   return true;
 }
 private ImageInfo createDefaultImageInfo() {
   try {
     return ProductUtils.createImageInfo(getFormModel().getRasters(), false, ProgressMonitor.NULL);
   } catch (IOException e) {
     JOptionPane.showMessageDialog(
         getContentPanel(),
         "Failed to create default image settings:\n" + e.getMessage(),
         "I/O Error",
         JOptionPane.ERROR_MESSAGE);
     return null;
   }
 }
Ejemplo n.º 5
0
  private void copyBandWithFeatures(Product sourceProduct, String oldBandName, String newBandName) {
    Band sourceBand = sourceProduct.getBand(oldBandName);
    if (sourceBand == null) {
      final String msg =
          String.format(
              "Source product [%s] does not contain a band with name [%s]",
              sourceProduct.getName(), oldBandName);
      throw new OperatorException(msg);
    }

    if (targetProduct.containsBand(newBandName)) {
      return;
    }
    ProductUtils.copyBand(oldBandName, sourceProduct, newBandName, targetProduct, true);
  }
 @Override
 public AbstractLayerSourceAssistantPage getNextPage() {
   final LayerSourcePageContext context = getContext();
   try {
     final Product product = SnapApp.getDefault().getSelectedProduct();
     final GeoPos referencePos = ProductUtils.getCenterGeoPos(product);
     final CoordinateReferenceSystem crs = crsSelectionPanel.getCrs(referencePos);
     context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, crs);
     return new ShapefileAssistantPage3();
   } catch (FactoryException e) {
     e.printStackTrace();
     context.showErrorDialog("Could not create CRS:\n" + e.getMessage());
   }
   return null;
 }
Ejemplo n.º 7
0
  private void addSelectedBands() {

    // add selected source bands
    if (sourceBandNames == null || sourceBandNames.length == 0) {
      final Band[] bands = sourceProduct.getBands();
      final List<String> bandNameList = new ArrayList<>(sourceProduct.getNumBands());
      for (Band band : bands) {
        String unit = band.getUnit();
        if (unit == null || unit.contains(Unit.INTENSITY)) {
          bandNameList.add(band.getName());
        }
      }
      sourceBandNames = bandNameList.toArray(new String[bandNameList.size()]);
    }

    final Band[] sourceBands = new Band[sourceBandNames.length];
    for (int i = 0; i < sourceBandNames.length; i++) {
      final String sourceBandName = sourceBandNames[i];
      final Band sourceBand = sourceProduct.getBand(sourceBandName);
      if (sourceBand == null) {
        throw new OperatorException("Source band not found: " + sourceBandName);
      }
      sourceBands[i] = sourceBand;
    }

    for (Band srcBand : sourceBands) {
      final Band targetBand =
          ProductUtils.copyBand(srcBand.getName(), sourceProduct, targetProduct, false);
      targetBand.setSourceImage(srcBand.getSourceImage());
    }

    // add latitude and longitude bands
    Band latBand =
        new Band(LATITUDE_BAND_NAME, ProductData.TYPE_FLOAT64, sourceImageWidth, sourceImageHeight);
    Band lonBand =
        new Band(
            LONGITUDE_BAND_NAME, ProductData.TYPE_FLOAT64, sourceImageWidth, sourceImageHeight);
    targetProduct.addBand(latBand);
    targetProduct.addBand(lonBand);

    targetProduct.setSceneGeoCoding(new PixelGeoCoding(latBand, lonBand, null, 6));
  }
  /**
   * Initializes this operator and sets the one and only target product.
   *
   * <p>The target product can be either defined by a field of type {@link Product} annotated with
   * the {@link TargetProduct TargetProduct} annotation or by calling {@link #setTargetProduct}
   * method.
   *
   * <p>The framework calls this method after it has created this operator. Any client code that
   * must be performed before computation of tile data should be placed here.
   *
   * @throws OperatorException If an error occurs during operator initialisation.
   * @see #getTargetProduct()
   */
  @Override
  public void initialize() throws OperatorException {

    try {
      targetProduct =
          new Product(
              sourceProduct.getName(),
              sourceProduct.getProductType(),
              sourceProduct.getSceneRasterWidth(),
              sourceProduct.getSceneRasterHeight());

      ProductUtils.copyProductNodes(sourceProduct, targetProduct);

      dataType = ProductData.getType(targetDataType);
      targetScaling = getScaling(targetScalingStr);

      addSelectedBands();

    } catch (Throwable e) {
      throw new OperatorException(e);
    }
  }
Ejemplo n.º 9
0
  private void addGeoTiffTags(final Product product) {
    final GeoTIFFMetadata geoTIFFMetadata = ProductUtils.createGeoTIFFMetadata(product);
    if (geoTIFFMetadata == null) {
      return;
    }

    //  for debug purpose
    //        geoTIFFMetadata.dump();

    final int numEntries = geoTIFFMetadata.getNumGeoKeyEntries();
    final TiffShort[] directoryTagValues = new TiffShort[numEntries * 4];
    final ArrayList<TiffDouble> doubleValues = new ArrayList<>();
    final ArrayList<String> asciiValues = new ArrayList<>();
    for (int i = 0; i < numEntries; i++) {
      final GeoTIFFMetadata.KeyEntry entry = geoTIFFMetadata.getGeoKeyEntryAt(i);
      final int[] data = entry.getData();
      for (int j = 0; j < data.length; j++) {
        directoryTagValues[i * 4 + j] = new TiffShort(data[j]);
      }
      if (data[1] == TiffTag.GeoDoubleParamsTag.getValue()) {
        directoryTagValues[i * 4 + 3] = new TiffShort(doubleValues.size());
        final double[] geoDoubleParams = geoTIFFMetadata.getGeoDoubleParams(data[0]);
        for (double geoDoubleParam : geoDoubleParams) {
          doubleValues.add(new TiffDouble(geoDoubleParam));
        }
      }
      if (data[1] == TiffTag.GeoAsciiParamsTag.getValue()) {
        int sizeInBytes = 0;
        for (String asciiValue : asciiValues) {
          sizeInBytes += asciiValue.length() + 1;
        }
        directoryTagValues[i * 4 + 3] = new TiffShort(sizeInBytes);
        asciiValues.add(geoTIFFMetadata.getGeoAsciiParam(data[0]));
      }
    }
    setEntry(new TiffDirectoryEntry(TiffTag.GeoKeyDirectoryTag, directoryTagValues));
    if (!doubleValues.isEmpty()) {
      final TiffDouble[] tiffDoubles = doubleValues.toArray(new TiffDouble[doubleValues.size()]);
      setEntry(new TiffDirectoryEntry(TiffTag.GeoDoubleParamsTag, tiffDoubles));
    }
    if (!asciiValues.isEmpty()) {
      final String[] tiffAsciies = asciiValues.toArray(new String[asciiValues.size()]);
      setEntry(new TiffDirectoryEntry(TiffTag.GeoAsciiParamsTag, new GeoTiffAscii(tiffAsciies)));
    }
    double[] modelTransformation = geoTIFFMetadata.getModelTransformation();
    if (!isZeroArray(modelTransformation)) {
      setEntry(
          new TiffDirectoryEntry(
              TiffTag.ModelTransformationTag, toTiffDoubles(modelTransformation)));
    } else {
      double[] modelPixelScale = geoTIFFMetadata.getModelPixelScale();
      if (!isZeroArray(modelPixelScale)) {
        setEntry(
            new TiffDirectoryEntry(TiffTag.ModelPixelScaleTag, toTiffDoubles(modelPixelScale)));
      }
      final int numModelTiePoints = geoTIFFMetadata.getNumModelTiePoints();
      if (numModelTiePoints > 0) {
        final TiffDouble[] tiePoints = new TiffDouble[numModelTiePoints * 6];
        for (int i = 0; i < numModelTiePoints; i++) {
          final GeoTIFFMetadata.TiePoint modelTiePoint = geoTIFFMetadata.getModelTiePointAt(i);
          final double[] data = modelTiePoint.getData();
          for (int j = 0; j < data.length; j++) {
            tiePoints[i * 6 + j] = new TiffDouble(data[j]);
          }
        }
        setEntry(new TiffDirectoryEntry(TiffTag.ModelTiepointTag, tiePoints));
      }
    }
  }