コード例 #1
0
  private static void applyTiePointGeoCoding(
      TiffFileInfo info, double[] tiePoints, Product product) {
    final SortedSet<Double> xSet = new TreeSet<>();
    final SortedSet<Double> ySet = new TreeSet<>();
    for (int i = 0; i < tiePoints.length; i += 6) {
      xSet.add(tiePoints[i]);
      ySet.add(tiePoints[i + 1]);
    }
    final double xMin = xSet.first();
    final double xMax = xSet.last();
    final double xDiff = (xMax - xMin) / (xSet.size() - 1);
    final double yMin = ySet.first();
    final double yMax = ySet.last();
    final double yDiff = (yMax - yMin) / (ySet.size() - 1);

    final int width = xSet.size();
    final int height = ySet.size();

    int idx = 0;
    final Map<Double, Integer> xIdx = new HashMap<>();
    for (Double val : xSet) {
      xIdx.put(val, idx);
      idx++;
    }
    idx = 0;
    final Map<Double, Integer> yIdx = new HashMap<>();
    for (Double val : ySet) {
      yIdx.put(val, idx);
      idx++;
    }

    final float[] lats = new float[width * height];
    final float[] lons = new float[width * height];

    for (int i = 0; i < tiePoints.length; i += 6) {
      final int idxX = xIdx.get(tiePoints[i + 0]);
      final int idxY = yIdx.get(tiePoints[i + 1]);
      final int arrayIdx = idxY * width + idxX;
      lons[arrayIdx] = (float) tiePoints[i + 3];
      lats[arrayIdx] = (float) tiePoints[i + 4];
    }

    String[] names = Utils.findSuitableLatLonNames(product);
    final TiePointGrid latGrid =
        new TiePointGrid(names[0], width, height, xMin, yMin, xDiff, yDiff, lats);
    final TiePointGrid lonGrid =
        new TiePointGrid(names[1], width, height, xMin, yMin, xDiff, yDiff, lons);

    product.addTiePointGrid(latGrid);
    product.addTiePointGrid(lonGrid);
    final SortedMap<Integer, GeoKeyEntry> geoKeyEntries = info.getGeoKeyEntries();
    final Datum datum = getDatum(geoKeyEntries);
    product.setGeoCoding(new TiePointGeoCoding(latGrid, lonGrid, datum));
  }
コード例 #2
0
  private static void applyGcpGeoCoding(
      final TiffFileInfo info, final double[] tiePoints, final Product product) {

    int numTiePoints = tiePoints.length / 6;

    final GcpGeoCoding.Method method;
    if (numTiePoints >= GcpGeoCoding.Method.POLYNOMIAL3.getTermCountP()) {
      method = GcpGeoCoding.Method.POLYNOMIAL3;
    } else if (numTiePoints >= GcpGeoCoding.Method.POLYNOMIAL2.getTermCountP()) {
      method = GcpGeoCoding.Method.POLYNOMIAL2;
    } else if (numTiePoints >= GcpGeoCoding.Method.POLYNOMIAL1.getTermCountP()) {
      method = GcpGeoCoding.Method.POLYNOMIAL1;
    } else {
      return; // not able to apply GCP geo coding; not enough tie points
    }

    final int width = product.getSceneRasterWidth();
    final int height = product.getSceneRasterHeight();

    final GcpDescriptor gcpDescriptor = GcpDescriptor.getInstance();
    final ProductNodeGroup<Placemark> gcpGroup = product.getGcpGroup();
    for (int i = 0; i < numTiePoints; i++) {
      final int offset = i * 6;

      final float x = (float) tiePoints[offset + 0];
      final float y = (float) tiePoints[offset + 1];
      final float lon = (float) tiePoints[offset + 3];
      final float lat = (float) tiePoints[offset + 4];

      if (Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(lon) || Double.isNaN(lat)) {
        continue;
      }
      final PixelPos pixelPos = new PixelPos(x, y);
      final GeoPos geoPos = new GeoPos(lat, lon);

      final Placemark gcp =
          Placemark.createPointPlacemark(
              gcpDescriptor, "gcp_" + i, "GCP_" + i, "", pixelPos, geoPos, product.getGeoCoding());
      gcpGroup.add(gcp);
    }

    final Placemark[] gcps = gcpGroup.toArray(new Placemark[gcpGroup.getNodeCount()]);
    final SortedMap<Integer, GeoKeyEntry> geoKeyEntries = info.getGeoKeyEntries();
    final Datum datum = getDatum(geoKeyEntries);
    product.setGeoCoding(new GcpGeoCoding(method, gcps, width, height, datum));
  }