in spark/common/src/main/java/org/apache/sedona/viz/core/ImageStitcher.java [56:127]
public static boolean stitchImagePartitionsFromLocalFile(
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);
// Stitch all image partitions together
for (int i = 0; i < partitionOnX * partitionOnY; i++) {
BufferedImage imageTile = null;
try {
imageTile =
ImageIO.read(
new File(
""
+ imageTilePath
+ "-"
+ RasterizationUtils.getImageTileName(
zoomLevel, partitionOnX, partitionOnY, i)
+ ".png"));
} 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;
}