Example #1
0
 private void writeGeoCoding() throws IOException {
   final Product product = getSourceProduct();
   if (product.getGeoCoding() instanceof TiePointGeoCoding) {
     writeGeoCoding((TiePointGeoCoding) product.getGeoCoding());
   } else if (product.getGeoCoding() instanceof MapGeoCoding) {
     writeGeoCoding((MapGeoCoding) product.getGeoCoding());
   }
 }
Example #2
0
  public void createData(final RepositoryEntry entry, final Repository repository)
      throws IOException {
    final Product product = entry.getProduct();
    final PropertyMap propertyMap = repository.getPropertyMap();
    final String productName = entry.getProductFile().getName();

    if (product.getGeoCoding() != null) {
      final String boundaryPathString = createPathsString(product);
      propertyMap.setPropertyString(productName + KEY_BOUNDARY_PATH, boundaryPathString);
      final GeoPos centerGeoPos = ProductUtils.getCenterGeoPos(product);
      propertyMap.setPropertyDouble(productName + KEY_PRODUCT_CENTER_LAT, centerGeoPos.lat);
      propertyMap.setPropertyDouble(productName + KEY_PRODUCT_CENTER_LON, centerGeoPos.lon);
    } else {
      propertyMap.setPropertyString(productName + KEY_BOUNDARY_PATH, "");
      propertyMap.setPropertyDouble(productName + KEY_PRODUCT_CENTER_LAT, null);
      propertyMap.setPropertyDouble(productName + KEY_PRODUCT_CENTER_LON, null);
    }

    if (createWorldMapFile) {
      final File worldMapImageFile =
          getWorldMapImageFile(repository.getStorageDir(), entry.getProductFile().getName());
      final BufferedImage worldMapImage = createWorldMapImage(product);
      writeImage(worldMapImage, worldMapImageFile);
    }
  }
 @Override
 public boolean accept(Product sourceProduct) {
   final ProductData.UTC productStartTime = sourceProduct.getStartTime();
   final ProductData.UTC productEndTime = sourceProduct.getEndTime();
   final boolean hasStartTime = productStartTime != null;
   final boolean hasEndTime = productEndTime != null;
   final GeoCoding geoCoding = sourceProduct.getGeoCoding();
   if (geoCoding == null || !geoCoding.canGetGeoPos()) {
     return false;
   } else if (startTime != null
       && hasStartTime
       && productStartTime.getAsDate().after(startTime.getAsDate())
       && endTime != null
       && hasEndTime
       && productEndTime.getAsDate().before(endTime.getAsDate())) {
     return true;
   } else if (!hasStartTime && !hasEndTime) {
     return true;
   } else if (startTime != null
       && hasStartTime
       && productStartTime.getAsDate().after(startTime.getAsDate())
       && !hasEndTime) {
     return true;
   } else if (!hasStartTime
       && endTime != null
       && productEndTime.getAsDate().before(endTime.getAsDate())) {
     return true;
   } else {
     return false;
   }
 }
  private static void setLatLongMetadata(
      final Product product,
      final MetadataElement absRoot,
      final String tagLat,
      final String tagLon,
      final float x,
      final float y) {
    final PixelPos pixelPos = new PixelPos(x, y);
    final GeoPos geoPos = new GeoPos();
    if (product.getGeoCoding() == null) return;
    product.getGeoCoding().getGeoPos(pixelPos, geoPos);

    final MetadataAttribute lat = absRoot.getAttribute(tagLat);
    if (lat != null) lat.getData().setElemDouble(geoPos.getLat());
    final MetadataAttribute lon = absRoot.getAttribute(tagLon);
    if (lon != null) lon.getData().setElemDouble(geoPos.getLon());
  }
Example #5
0
 public static Rectangle computePixelRegion(
     Product product, Geometry geoRegion, int numBorderPixels) {
   final Geometry productGeometry = computeProductGeometry(product);
   final Geometry regionIntersection = geoRegion.intersection(productGeometry);
   if (regionIntersection.isEmpty()) {
     return new Rectangle();
   }
   final PixelRegionFinder pixelRegionFinder = new PixelRegionFinder(product.getGeoCoding());
   regionIntersection.apply(pixelRegionFinder);
   final Rectangle pixelRegion = pixelRegionFinder.getPixelRegion();
   pixelRegion.grow(numBorderPixels, numBorderPixels);
   return pixelRegion.intersection(
       new Rectangle(product.getSceneRasterWidth(), product.getSceneRasterHeight()));
 }
Example #6
0
  static boolean addDiagnosticSitePin(Product product) {
    final MetadataElement pa = product.getMetadataRoot().getElement(GLOBAL_ATTRIBUTES);
    if (pa == null || product.getGeoCoding() == null) {
      return false;
    }

    final MetadataAttribute siteIdAttr = pa.getAttribute(ProductAttributes.SITE_ID);
    final MetadataAttribute siteLonAttr = pa.getAttribute(ProductAttributes.SITE_LON);
    final MetadataAttribute siteLatAttr = pa.getAttribute(ProductAttributes.SITE_LAT);
    if (siteIdAttr == null || siteLonAttr == null || siteLatAttr == null) {
      return false;
    }

    final String siteId = siteIdAttr.getData().getElemString();
    final float siteLon = siteLonAttr.getData().getElemFloat();
    final float siteLat = siteLatAttr.getData().getElemFloat();

    final String pinName = new StringBuilder("SITE").append("_").append(siteId).toString();
    if (product.getPinGroup().contains(pinName)) {
      return false;
    }

    final String pinLabel = pa.getAttributeString(ProductAttributes.SITE_NAME, pinName);

    final Placemark pointPlacemark =
        Placemark.createPointPlacemark(
            PinDescriptor.getInstance(),
            pinName,
            pinLabel,
            "GlobColour diagnostic site",
            null,
            new GeoPos(siteLat, siteLon),
            product.getGeoCoding());
    product.getPinGroup().add(pointPlacemark);

    return true;
  }
Example #7
0
  private Product createClostProduct(RenderedOp blueAerosolPanCirrusImage) {

    Product product =
        new Product(
            sourceProduct.getName() + "_clost",
            sourceProduct.getProductType() + " (clost)",
            sourceProduct.getSceneRasterWidth(),
            sourceProduct.getSceneRasterHeight());

    product.setGeoCoding(sourceProduct.getGeoCoding());
    product.setDescription("Product holding Clost Image");

    Band band = product.addBand(CLOST_BAND_NAME, ProductData.TYPE_FLOAT32);
    band.setSourceImage(blueAerosolPanCirrusImage);
    band.setUnit("dl");
    band.setDescription("CLOST Image: aerosol * blue * pan * cirrus ");

    return product;
  }
Example #8
0
  @Override
  public void actionPerformed(final CommandEvent event) {
    VisatApp visatApp = VisatApp.getApp();

    File file = visatApp.showFileOpenDialog(TITLE, false, null, "importTrack.lastDir");
    if (file == null) {
      return;
    }

    Product product = visatApp.getSelectedProduct();

    FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection;
    try {
      featureCollection = readTrack(file, product.getGeoCoding());
    } catch (IOException e) {
      visatApp.showErrorDialog(TITLE, "Failed to load track file:\n" + e.getMessage());
      return;
    }

    if (featureCollection.isEmpty()) {
      visatApp.showErrorDialog(TITLE, "No records found.");
      return;
    }

    String name = FileUtils.getFilenameWithoutExtension(file);
    final PlacemarkDescriptor placemarkDescriptor =
        PlacemarkDescriptorRegistry.getInstance()
            .getPlacemarkDescriptor(featureCollection.getSchema());
    placemarkDescriptor.setUserDataOf(featureCollection.getSchema());
    VectorDataNode vectorDataNode =
        new VectorDataNode(name, featureCollection, placemarkDescriptor);

    product.getVectorDataGroup().add(vectorDataNode);

    final ProductSceneView view = visatApp.getSelectedProductSceneView();
    if (view != null) {
      view.setLayersVisible(vectorDataNode);
    }
  }
Example #9
0
 private boolean canUseGeoCoordinates(Product product) {
   final GeoCoding geoCoding = product.getGeoCoding();
   return geoCoding != null && geoCoding.canGetPixelPos() && geoCoding.canGetGeoPos();
 }
Example #10
0
  /**
   * Writes the systems byte order to the out stream. In java only high byte first.
   *
   * @param out the stream to write to
   * @param rasterDataNode
   */
  private static void writeMapProjectionInfo(PrintWriter out, RasterDataNode rasterDataNode) {
    Product product = rasterDataNode.getProduct();
    if (product == null) {
      return;
    }

    String mapProjectionName = "Arbitrary";
    String mapUnits = "Meters";
    double referencePixelX = 0, referencePixelY = 0;
    double easting = 0, northing = 0;
    double pixelSizeX = 0, pixelSizeY = 0;
    String datumName = "";
    int utmZone = -1;
    String utmHemisphere = "";
    MapProjection mapProjection = null;

    if (product.getGeoCoding() instanceof CrsGeoCoding) {
      final CrsGeoCoding crsGeoCoding = (CrsGeoCoding) product.getGeoCoding();
      final CoordinateReferenceSystem crs = crsGeoCoding.getMapCRS();

      final ImageGeometry imgGeom =
          ImageGeometry.createTargetGeometry(
              product, crs, null, null, null, null, null, null, null, null, null);

      final String crsName = crs.getName().toString().toUpperCase();
      if (crsName.equals("WGS84(DD)")) {
        mapProjectionName = "Geographic Lat/Lon";
        mapUnits = "Degrees";
      } else if (crsName.contains("UTM")) {
        mapProjectionName = "UTM";
        String zoneStr = crsName.substring(crsName.indexOf("ZONE") + 5, crsName.length()).trim();
        int i = 0;
        String zoneNumStr = "";
        while (Character.isDigit(zoneStr.charAt(i))) {
          zoneNumStr += zoneStr.charAt(i++);
        }
        utmZone = Integer.parseInt(zoneNumStr);

        GeoPos centrePos =
            crsGeoCoding.getGeoPos(
                new PixelPos(product.getSceneRasterWidth() / 2, product.getSceneRasterHeight() / 2),
                null);
        utmHemisphere = centrePos.getLat() > 0 ? "North" : "South";
      }
      referencePixelX = imgGeom.getReferencePixelX();
      referencePixelY = imgGeom.getReferencePixelY();
      easting = imgGeom.getEasting();
      northing = imgGeom.getNorthing();
      pixelSizeX = imgGeom.getPixelSizeX();
      pixelSizeY = imgGeom.getPixelSizeY();
      datumName = crsGeoCoding.getDatum().getName();

    } else if (product.getGeoCoding() instanceof MapGeoCoding) {
      final MapGeoCoding mapGeoCoding = (MapGeoCoding) product.getGeoCoding();

      final MapInfo info = mapGeoCoding.getMapInfo();
      if (info == null) {
        return;
      }
      mapProjection = info.getMapProjection();

      if (mapProjection instanceof UTMProjection) {
        mapProjectionName = "UTM";
        final UTMProjection utmProjection = (UTMProjection) mapProjection;
        utmZone = utmProjection.getZone();
        utmHemisphere = utmProjection.isNorth() ? "North" : "South";
      } else if (mapProjection.isPreDefined()) {
        mapProjectionName = mapProjection.getName();
      }

      if ("meter".equals(mapProjection.getMapUnit())) {
        mapUnits = "Meters";
      } else if ("degree".equals(mapProjection.getMapUnit())) {
        mapUnits = "Degrees";
      } else {
        mapUnits = mapProjection.getMapUnit();
      }

      datumName = mapGeoCoding.getDatum().getName();
    } else {
      return;
    }

    out.print(_enviMapInfo);
    out.print(" = {");
    out.print(mapProjectionName);
    out.print(",");
    out.print(referencePixelX + 1.0f);
    out.print(",");
    out.print(referencePixelY + 1.0f);
    out.print(",");
    out.print(easting);
    out.print(",");
    out.print(northing);
    out.print(",");
    out.print(pixelSizeX);
    out.print(",");
    out.print(pixelSizeY);
    out.print(",");
    if (utmZone != -1) {
      out.print(utmZone);
      out.print(",");
      out.print(utmHemisphere);
      out.print(",");
    }
    out.print(datumName);
    out.print(",");
    out.print("units=" + mapUnits);
    out.print("}");
    out.println();

    if (mapProjection != null && !mapProjection.isPreDefined()) {
      final MapTransform mapTransform = mapProjection.getMapTransform();
      final double[] parameterValues = mapTransform.getParameterValues();
      final String transformName = mapTransform.getDescriptor().getName();
      out.print(_enviProjectionInfo);
      out.print(" = {");
      if (transformName.equals(TransverseMercatorDescriptor.NAME)) {
        out.print(3);
        out.print(",");
        out.print(parameterValues[0]); // semi_major (meters)
        out.print(",");
        out.print(parameterValues[1]); // semi_minor (meters)
        out.print(",");
        out.print(parameterValues[2]); // latitude_of_origin (degree)
        out.print(",");
        out.print(parameterValues[3]); // central_meridian (degree)
        out.print(",");
        out.print(parameterValues[5]); // false_easting (meters)
        out.print(",");
        out.print(parameterValues[6]); // false_northing (meters)
        out.print(",");
        out.print(parameterValues[4]); //  scaling_factor (no unit)
        out.print(",");
      } else if (transformName.equals(LambertConformalConicDescriptor.NAME)) {
        out.print(4);
        out.print(",");
        out.print(parameterValues[0]); // semi_major (meters)
        out.print(",");
        out.print(parameterValues[1]); // semi_minor (meters)
        out.print(",");
        out.print(parameterValues[2]); // latitude_of_origin (degree)
        out.print(",");
        out.print(parameterValues[3]); // central_meridian (degree)
        out.print(",");
        out.print(0.0); // false_easting (meters)
        out.print(",");
        out.print(0.0); // false_northing (meters)
        out.print(",");
        out.print(parameterValues[4]); // latitude_of_intersection_1 (meters)
        out.print(",");
        out.print(parameterValues[5]); // latitude_of_intersection_2 (meters)
        out.print(",");
      }
      out.print(mapProjectionName);
      out.print(",");
      out.print("units=" + mapUnits);
      out.print("}");
      out.println();
    }
  }