public static boolean stitchImagePartitionsFromHadoopFile()

in spark/common/src/main/java/org/apache/sedona/viz/core/ImageStitcher.java [239:328]


  public static boolean stitchImagePartitionsFromHadoopFile(
      String imageTilePath,
      int resolutionX,
      int resolutionY,
      int zoomLevel,
      int partitionOnX,
      int partitionOnY)
      throws Exception {
    logger.info("[Sedona-Viz][stitchImagePartitions][Start]");

    BufferedImage stitchedImage =
        BigBufferedImage.create(resolutionX, resolutionY, BufferedImage.TYPE_INT_ARGB);

    String[] splitString = imageTilePath.split(":");
    String hostName = splitString[0] + ":" + splitString[1];
    String[] portAndPath = splitString[2].split("/");
    String port = portAndPath[0];
    String localPath = "";
    for (int i = 1; i < portAndPath.length; i++) {
      localPath += "/" + portAndPath[i];
    }

    Configuration hadoopConf = new org.apache.hadoop.conf.Configuration();
    FileSystem hdfs = FileSystem.get(new URI(hostName + ":" + port), hadoopConf);

    // Stitch all image partitions together
    for (int i = 0; i < partitionOnX * partitionOnY; i++) {
      BufferedImage imageTile = null;
      try {
        if (hdfs.exists(
            new org.apache.hadoop.fs.Path(
                localPath
                    + "-"
                    + RasterizationUtils.getImageTileName(zoomLevel, partitionOnX, partitionOnY, i)
                    + ".png"))) {
          InputStream inputStream =
              hdfs.open(new org.apache.hadoop.fs.Path(localPath + "-" + i + ".png"));
          imageTile = ImageIO.read(inputStream);
          inputStream.close();
          hdfs.close();
        } else {
          continue;
        }
      } catch (IOException e) {
        continue;
      }
      Tuple2<Integer, Integer> partitionCoordinate =
          RasterizationUtils.Decode1DTo2DId(partitionOnX, partitionOnY, i);
      int partitionMinX = partitionCoordinate._1 * Math.round(resolutionX / partitionOnX);
      int partitionMinY = partitionCoordinate._2 * Math.round(resolutionY / partitionOnY);
      // if(partitionMinX!=0){partitionMinX--;}
      // if(partitionMinY!=0){partitionMinY--;}
      int[] rgbArray =
          imageTile.getRGB(
              0, 0, imageTile.getWidth(), imageTile.getHeight(), null, 0, imageTile.getWidth());
      int partitionMaxX = partitionMinX + imageTile.getWidth();
      int partitionMaxY = partitionMinY + imageTile.getHeight();
      logger.debug(
          "[Sedona-Viz][stitchImagePartitions] stitching image tile..."
              + i
              + " ResolutionX "
              + resolutionX
              + " ResolutionY "
              + resolutionY);
      logger.debug(
          "[Sedona-Viz][stitchImagePartitions] stitching a image tile..."
              + i
              + " MinX "
              + partitionMinX
              + " MaxX "
              + partitionMaxX
              + " MinY "
              + partitionMinY
              + " MaxY "
              + partitionMaxY);
      stitchedImage.setRGB(
          partitionMinX,
          partitionMinY,
          imageTile.getWidth(),
          imageTile.getHeight(),
          rgbArray,
          0,
          imageTile.getWidth());
    }
    ImageGenerator imageGenerator = new ImageGenerator();
    imageGenerator.SaveRasterImageAsLocalFile(
        stitchedImage, imageTilePath + "-" + zoomLevel + "-stitched", ImageType.PNG);
    logger.info("[Sedona-Viz][stitchImagePartitions][Stop]");
    return true;
  }