From f61fd4cad576ff1a9b9cb7515813113b75ebb09e Mon Sep 17 00:00:00 2001 From: Bertil Chapuis Date: Sun, 1 Sep 2024 23:52:34 +0200 Subject: [PATCH] Clean code and fix issues detected by sonar --- .../baremaps/cli/dem/VectorTileContours.java | 2 +- .../tilestore/TileStoreException.java | 6 ++-- .../tilestore/raster/GeoTiffException.java} | 29 ++++++++++++++-- .../tilestore/raster/GeoTiffReader.java | 11 +++--- .../tilestore/raster/TerrariumTileStore.java | 22 +++++++----- .../apache/baremaps/config/TileSetTest.java | 5 --- .../apache/baremaps/dem/ContourTracer.java | 3 +- .../baremaps/dem/ContourTracerTest.java | 3 +- .../baremaps/dem/MarchingSquareRenderer.java | 1 - .../java/org/apache/baremaps/gdal/Band.java | 26 +++++++------- .../org/apache/baremaps/gdal/Dataset.java | 18 +++++----- .../java/org/apache/baremaps/gdal/Driver.java | 14 ++++---- .../java/org/apache/baremaps/gdal/Gdal.java | 22 ++++++------ .../java/org/apache/baremaps/gdal/Layer.java | 8 ++--- .../org/apache/baremaps/gdal/Options.java | 14 ++++---- .../baremaps/gdal/TranslateOptions.java | 34 +++++++++---------- .../org/apache/baremaps/gdal/WarpOptions.java | 6 ---- .../server/BufferedImageResource.java | 18 ++++------ 18 files changed, 124 insertions(+), 118 deletions(-) rename baremaps-core/src/{test/java/org/apache/baremaps/tilestore/raster/VectorHillshadeTileStoreTest.java => main/java/org/apache/baremaps/tilestore/raster/GeoTiffException.java} (55%) diff --git a/baremaps-cli/src/main/java/org/apache/baremaps/cli/dem/VectorTileContours.java b/baremaps-cli/src/main/java/org/apache/baremaps/cli/dem/VectorTileContours.java index 065add209..9328dd796 100644 --- a/baremaps-cli/src/main/java/org/apache/baremaps/cli/dem/VectorTileContours.java +++ b/baremaps-cli/src/main/java/org/apache/baremaps/cli/dem/VectorTileContours.java @@ -38,7 +38,7 @@ import picocli.CommandLine.Option; @Command(name = "vector-contours", description = "Generate vector contours from a DEM.") -@SuppressWarnings("squid:S106") +@SuppressWarnings({"squid:S106", "squid:S3864"}) public class VectorTileContours implements Callable { @Option(names = {"--path"}, paramLabel = "PATH", description = "The path of a geoTIFF file.") diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileStoreException.java b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileStoreException.java index 1ad72e1eb..490a680ce 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileStoreException.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/TileStoreException.java @@ -21,7 +21,7 @@ public class TileStoreException extends Exception { /** - * Constructs an {@code BlobStoreException} with the specified detail message. + * Constructs an {@code TileStoreException} with the specified detail message. * * @param message the message */ @@ -30,7 +30,7 @@ public TileStoreException(String message) { } /** - * Constructs a {@code BlobStoreException} with the specified cause. + * Constructs a {@code TileStoreException} with the specified cause. * * @param cause the cause */ @@ -39,7 +39,7 @@ public TileStoreException(Throwable cause) { } /** - * Constructs a {@code BlobStoreException} with the specified detail message and cause. + * Constructs a {@code TileStoreException} with the specified detail message and cause. * * @param message the message * @param cause the cause diff --git a/baremaps-core/src/test/java/org/apache/baremaps/tilestore/raster/VectorHillshadeTileStoreTest.java b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/GeoTiffException.java similarity index 55% rename from baremaps-core/src/test/java/org/apache/baremaps/tilestore/raster/VectorHillshadeTileStoreTest.java rename to baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/GeoTiffException.java index c79b25e3a..cb0db57bd 100644 --- a/baremaps-core/src/test/java/org/apache/baremaps/tilestore/raster/VectorHillshadeTileStoreTest.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/GeoTiffException.java @@ -17,10 +17,33 @@ package org.apache.baremaps.tilestore.raster; -import static org.junit.jupiter.api.Assertions.*; +public class GeoTiffException extends Exception { + /** + * Constructs an {@code GeoTiffException} with the specified detail message. + * + * @param message the message + */ + public GeoTiffException(String message) { + super(message); + } -class VectorHillshadeTileStoreTest { - + /** + * Constructs a {@code GeoTiffException} with the specified cause. + * + * @param cause the cause + */ + public GeoTiffException(Throwable cause) { + super(cause); + } + /** + * Constructs a {@code GeoTiffException} with the specified detail message and cause. + * + * @param message the message + * @param cause the cause + */ + public GeoTiffException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/GeoTiffReader.java b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/GeoTiffReader.java index 62b906d98..a5280237d 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/GeoTiffReader.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/GeoTiffReader.java @@ -19,7 +19,6 @@ import java.nio.file.Path; import org.apache.baremaps.tilestore.TileCoord; -import org.apache.baremaps.tilestore.TileStoreException; import org.apache.sis.coverage.grid.*; import org.apache.sis.geometry.Envelopes; import org.apache.sis.geometry.GeneralEnvelope; @@ -52,7 +51,7 @@ public class GeoTiffReader implements AutoCloseable { Id["EPSG", 3857]] """); } catch (FactoryException e) { - throw new RuntimeException(e); + throw new IllegalArgumentException(e); } } @@ -60,7 +59,7 @@ public class GeoTiffReader implements AutoCloseable { private final GridCoverage gridCoverage; - public GeoTiffReader(Path path) { + public GeoTiffReader(Path path) throws GeoTiffException { try { this.dataStore = DataStores.open(path); var allImages = ((Aggregate) dataStore).components(); @@ -68,11 +67,11 @@ public GeoTiffReader(Path path) { firstImage.setLoadingStrategy(RasterLoadingStrategy.AT_GET_TILE_TIME); gridCoverage = firstImage.read(null); } catch (DataStoreException e) { - throw new RuntimeException(e); + throw new GeoTiffException(e); } } - public double[] read(TileCoord tileCoord, int size, int buffer) throws TileStoreException { + public double[] read(TileCoord tileCoord, int size, int buffer) throws GeoTiffException { try { // Compute the buffer size and expand the envelope var fullSize = size + 2 * buffer; @@ -115,7 +114,7 @@ public double[] read(TileCoord tileCoord, int size, int buffer) throws TileStore return values; } catch (Exception e) { - throw new TileStoreException(e); + throw new GeoTiffException(e); } } diff --git a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/TerrariumTileStore.java b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/TerrariumTileStore.java index 2de83a949..db7b609a5 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/TerrariumTileStore.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/raster/TerrariumTileStore.java @@ -34,17 +34,21 @@ public TerrariumTileStore(GeoTiffReader geoTiffReader) { @Override public BufferedImage read(TileCoord tileCoord) throws TileStoreException { - var size = 256; - var grid = geoTiffReader.read(tileCoord, size, 0); - var bufferedImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); - for (int x = 0; x < size; x++) { - for (int y = 0; y < size; y++) { - double value = (int) grid[y * size + x]; - int rgb = ElevationUtils.elevationToTerrarium(value); - bufferedImage.setRGB(x, y, rgb); + try { + var size = 256; + var grid = geoTiffReader.read(tileCoord, size, 0); + var bufferedImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + double value = (int) grid[y * size + x]; + int rgb = ElevationUtils.elevationToTerrarium(value); + bufferedImage.setRGB(x, y, rgb); + } } + return bufferedImage; + } catch (Exception e) { + throw new TileStoreException(e); } - return bufferedImage; } @Override diff --git a/baremaps-core/src/test/java/org/apache/baremaps/config/TileSetTest.java b/baremaps-core/src/test/java/org/apache/baremaps/config/TileSetTest.java index debba41f5..e09e9cb49 100644 --- a/baremaps-core/src/test/java/org/apache/baremaps/config/TileSetTest.java +++ b/baremaps-core/src/test/java/org/apache/baremaps/config/TileSetTest.java @@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import org.apache.baremaps.maplibre.tilejson.TileJSON; @@ -35,10 +34,6 @@ public class TileSetTest { final ObjectMapper objectMapper = ObjectMapperUtils.objectMapper(); final ConfigReader configReader = new ConfigReader(); - private File resourceFile(String path) { - return new File(TileSetTest.class.getResource(path).getFile()); - } - @Test public void testBasemapJSConfig() throws IOException { var path = Path.of("../basemap/tileset.js"); diff --git a/baremaps-dem/src/main/java/org/apache/baremaps/dem/ContourTracer.java b/baremaps-dem/src/main/java/org/apache/baremaps/dem/ContourTracer.java index 6773cc127..7bae91be7 100644 --- a/baremaps-dem/src/main/java/org/apache/baremaps/dem/ContourTracer.java +++ b/baremaps-dem/src/main/java/org/apache/baremaps/dem/ContourTracer.java @@ -27,6 +27,7 @@ * Provides methods for generating contour lines and contour polygons from digital elevation models * (DEMs). */ +@SuppressWarnings({"squid:S3776", "squid:S135"}) public class ContourTracer { private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); @@ -222,7 +223,6 @@ private static void validateInput(double[] grid, int width, int height) { * @param y The y-coordinate of the cell * @return A list of line segments */ - @SuppressWarnings("squid:S3776") private List processCell(double level, int x, int y) { List segments = new ArrayList<>(); @@ -244,7 +244,6 @@ private List processCell(double level, int x, int y) { double trv = grid[y * width + (x + 1)]; double brv = grid[(y + 1) * width + (x + 1)]; double blv = grid[(y + 1) * width + x]; - double avg = (tlv + trv + brv + blv) / 4.0; int index = (tlv >= level ? 1 : 0) | diff --git a/baremaps-dem/src/test/java/org/apache/baremaps/dem/ContourTracerTest.java b/baremaps-dem/src/test/java/org/apache/baremaps/dem/ContourTracerTest.java index f96cf5a7f..145dfeb8e 100644 --- a/baremaps-dem/src/test/java/org/apache/baremaps/dem/ContourTracerTest.java +++ b/baremaps-dem/src/test/java/org/apache/baremaps/dem/ContourTracerTest.java @@ -27,13 +27,12 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.locationtech.jts.geom.Polygon; -import org.locationtech.jts.io.ParseException; class ContourTracerTest { @Test @DisplayName("Test grid normalization") - void testGrid1() throws ParseException { + void testGrid1() { var grid = new double[] { 0, 0, 0, 0, 1, 0, diff --git a/baremaps-dem/src/test/java/org/apache/baremaps/dem/MarchingSquareRenderer.java b/baremaps-dem/src/test/java/org/apache/baremaps/dem/MarchingSquareRenderer.java index dee4d9376..1deacfb36 100644 --- a/baremaps-dem/src/test/java/org/apache/baremaps/dem/MarchingSquareRenderer.java +++ b/baremaps-dem/src/test/java/org/apache/baremaps/dem/MarchingSquareRenderer.java @@ -90,7 +90,6 @@ public static void main(String[] args) { JFrame frame = new JFrame("Geometry Drawer"); JPanel mainPanel = new JPanel(new GridLayout(4, 4)); - // mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); for (double[] c : MarchingSquareUtils.CASES) { List geometries = trace(c) diff --git a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Band.java b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Band.java index 71d58f3b7..f91644ad5 100644 --- a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Band.java +++ b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Band.java @@ -25,42 +25,42 @@ */ public class Band implements AutoCloseable { - private final org.gdal.gdal.Band band; + private final org.gdal.gdal.Band gdalBand; - protected Band(org.gdal.gdal.Band band) { - this.band = band; + protected Band(org.gdal.gdal.Band gdalBand) { + this.gdalBand = gdalBand; } public int getWidth() { - return band.getXSize(); + return gdalBand.getXSize(); } public int getHeight() { - return band.getYSize(); + return gdalBand.getYSize(); } public void read(int x, int y, int width, int height, byte[] buffer) { - band.ReadRaster(x, y, width, height, buffer); + gdalBand.ReadRaster(x, y, width, height, buffer); } public void read(int x, int y, int width, int height, int[] buffer) { - band.ReadRaster(x, y, width, height, buffer); + gdalBand.ReadRaster(x, y, width, height, buffer); } public void read(int x, int y, int width, int height, long[] buffer) { - band.ReadRaster(x, y, width, height, buffer); + gdalBand.ReadRaster(x, y, width, height, buffer); } public void read(int x, int y, int width, int height, double[] buffer) { - band.ReadRaster(x, y, width, height, buffer); + gdalBand.ReadRaster(x, y, width, height, buffer); } public BufferedImage asBufferedImage(int imageType) { // Copy the data of the band into a byte array - int width = band.getXSize(); - int height = band.getYSize(); + int width = gdalBand.getXSize(); + int height = gdalBand.getYSize(); double[] values = new double[height * width]; - band.ReadRaster(0, 0, 256, 256, values); + gdalBand.ReadRaster(0, 0, 256, 256, values); // Create a BufferedImage from the byte array BufferedImage image = new BufferedImage(width, height, imageType); @@ -77,7 +77,7 @@ public BufferedImage asBufferedImage(int imageType) { @Override public void close() throws Exception { - band.delete(); + gdalBand.delete(); } } diff --git a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Dataset.java b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Dataset.java index 7e754201a..1b78af853 100644 --- a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Dataset.java +++ b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Dataset.java @@ -22,34 +22,34 @@ */ public class Dataset implements AutoCloseable { - protected final org.gdal.gdal.Dataset dataset; + protected final org.gdal.gdal.Dataset gdalDataset; - protected Dataset(org.gdal.gdal.Dataset dataset) { - this.dataset = dataset; + protected Dataset(org.gdal.gdal.Dataset gdalDataset) { + this.gdalDataset = gdalDataset; } public Driver getDriver() { - return new Driver(dataset.GetDriver()); + return new Driver(gdalDataset.GetDriver()); } public int getRasterWidth() { - return dataset.getRasterXSize(); + return gdalDataset.getRasterXSize(); } public int getRasterHeight() { - return dataset.getRasterYSize(); + return gdalDataset.getRasterYSize(); } public int getRasterCount() { - return dataset.getRasterCount(); + return gdalDataset.getRasterCount(); } public Band getRasterBand(int index) { - return new Band(dataset.GetRasterBand(index)); + return new Band(gdalDataset.GetRasterBand(index)); } @Override public void close() throws Exception { - dataset.delete(); + gdalDataset.delete(); } } diff --git a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Driver.java b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Driver.java index a170eb6ed..023e4cc38 100644 --- a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Driver.java +++ b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Driver.java @@ -22,26 +22,26 @@ */ public class Driver implements AutoCloseable { - private final org.gdal.gdal.Driver driver; + private final org.gdal.gdal.Driver gdalDriver; - protected Driver(org.gdal.gdal.Driver driver) { - this.driver = driver; + protected Driver(org.gdal.gdal.Driver gdalDriver) { + this.gdalDriver = gdalDriver; } public String getShortName() { - return driver.getShortName(); + return gdalDriver.getShortName(); } public String getLongName() { - return driver.getLongName(); + return gdalDriver.getLongName(); } public String getHelpTopic() { - return driver.getHelpTopic(); + return gdalDriver.getHelpTopic(); } @Override public void close() throws Exception { - driver.delete(); + gdalDriver.delete(); } } diff --git a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Gdal.java b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Gdal.java index 610688d42..192d0c974 100644 --- a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Gdal.java +++ b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Gdal.java @@ -55,16 +55,16 @@ public static Dataset open(String path) { public static Dataset copy(String path, Dataset source) { var driver = gdal.IdentifyDriver(path); - return new Dataset(driver.CreateCopy(path, source.dataset)); + return new Dataset(driver.CreateCopy(path, source.gdalDataset)); } public static String info(Dataset dataset) { - return org.gdal.gdal.gdal.GDALInfo(dataset.dataset, null); + return org.gdal.gdal.gdal.GDALInfo(dataset.gdalDataset, null); } public static String info(Dataset dataset, InfoOptions options) { try (var infoOptions = new InfoResource(options)) { - return org.gdal.gdal.gdal.GDALInfo(dataset.dataset, infoOptions); + return org.gdal.gdal.gdal.GDALInfo(dataset.gdalDataset, infoOptions); } } @@ -98,7 +98,7 @@ public static Dataset translate(Dataset source, TranslateOptions options) { try (var translateResource = new TranslateResource(options)) { var dataset = org.gdal.gdal.gdal.Translate( "", - source.dataset, + source.gdalDataset, translateResource); return new Dataset(dataset); } @@ -110,7 +110,7 @@ public static Dataset translate(Dataset source, TranslateOptions options, var progressResource = new ProgressResource(progressListener)) { var dataset = org.gdal.gdal.gdal.Translate( "", - source.dataset, + source.gdalDataset, translateResource, progressResource); return new Dataset(dataset); @@ -139,7 +139,7 @@ public static Dataset warp(List sources, WarpOptions options) { try (var warpResource = new WarpResource(options)) { return new Dataset(gdal.Warp( "", - sources.stream().map(d -> d.dataset).toArray(org.gdal.gdal.Dataset[]::new), + sources.stream().map(d -> d.gdalDataset).toArray(org.gdal.gdal.Dataset[]::new), warpResource)); } } @@ -150,7 +150,7 @@ public static Dataset warp(List sources, WarpOptions options, var progressResource = new ProgressResource(progressCallback)) { return new Dataset(gdal.Warp( "", - sources.stream().map(d -> d.dataset).toArray(org.gdal.gdal.Dataset[]::new), + sources.stream().map(d -> d.gdalDataset).toArray(org.gdal.gdal.Dataset[]::new), warpResource, progressResource)); } @@ -159,8 +159,8 @@ public static Dataset warp(List sources, WarpOptions options, public static void warp(Dataset target, List sources, WarpOptions options) { try (var warpResource = new WarpResource(options)) { gdal.Warp( - target.dataset, - sources.stream().map(d -> d.dataset).toArray(org.gdal.gdal.Dataset[]::new), + target.gdalDataset, + sources.stream().map(d -> d.gdalDataset).toArray(org.gdal.gdal.Dataset[]::new), warpResource); } } @@ -170,8 +170,8 @@ public static void warp(Dataset target, List sources, WarpOptions optio try (var warpResource = new WarpResource(options); var progressResource = new ProgressResource(progressCallback)) { gdal.Warp( - target.dataset, - sources.stream().map(d -> d.dataset).toArray(org.gdal.gdal.Dataset[]::new), + target.gdalDataset, + sources.stream().map(d -> d.gdalDataset).toArray(org.gdal.gdal.Dataset[]::new), warpResource, progressResource); } diff --git a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Layer.java b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Layer.java index cbac48881..35eb2b65d 100644 --- a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Layer.java +++ b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Layer.java @@ -22,14 +22,14 @@ */ public class Layer implements AutoCloseable { - private final org.gdal.ogr.Layer layer; + private final org.gdal.ogr.Layer gdalLayer; - protected Layer(org.gdal.ogr.Layer layer) { - this.layer = layer; + protected Layer(org.gdal.ogr.Layer gdalLayer) { + this.gdalLayer = gdalLayer; } @Override public void close() throws Exception { - layer.delete(); + gdalLayer.delete(); } } diff --git a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Options.java b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Options.java index 188d47fa7..85e9fa8a5 100644 --- a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Options.java +++ b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/Options.java @@ -26,34 +26,34 @@ */ public class Options { - private final List options; + private final List values; public Options() { - this.options = new ArrayList<>(); + this.values = new ArrayList<>(); } public Options add(String value) { - options.add(value); + values.add(value); return this; } public Options add(int value) { - options.add(String.valueOf(value)); + values.add(String.valueOf(value)); return this; } public Options add(double value) { - options.add(String.valueOf(value)); + values.add(String.valueOf(value)); return this; } public Options add(boolean value) { - options.add(String.valueOf(value)); + values.add(String.valueOf(value)); return this; } public Vector asVector() { - return new Vector<>(options); + return new Vector<>(values); } } diff --git a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/TranslateOptions.java b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/TranslateOptions.java index 12197094e..8a6d32bac 100644 --- a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/TranslateOptions.java +++ b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/TranslateOptions.java @@ -83,24 +83,24 @@ public TranslateOptions expand(String option) { return this; } - public TranslateOptions outsize(int xsize, int ysize) { + public TranslateOptions outsize(int xSize, int ySize) { add("-outsize"); - add(xsize); - add(ysize); + add(xSize); + add(ySize); return this; } - public TranslateOptions outsizePercent(int xpercent, int ypercent) { + public TranslateOptions outsizePercent(int xPercent, int yPercent) { add("-outsize"); - add(xpercent + "%"); - add(ypercent + "%"); + add(xPercent + "%"); + add(yPercent + "%"); return this; } - public TranslateOptions targetResolution(double xres, double yres) { + public TranslateOptions targetResolution(double xRes, double yRes) { add("-tr"); - add(xres); - add(yres); + add(xRes); + add(yRes); return this; } @@ -164,11 +164,11 @@ public TranslateOptions exponent(double expVal) { return this; } - public TranslateOptions srcWindow(int xoff, int yoff, int xsize, int ysize) { + public TranslateOptions srcWindow(int xOff, int yOff, int xSize, int ySize) { add("-srcwin"); - add(xoff); - add(yoff); - add(xsize); + add(xOff); + add(yOff); + add(xSize); return this; } @@ -314,13 +314,13 @@ public TranslateOptions openOption(String name, String value) { return this; } - public TranslateOptions srcDataset(String dataset) { - add(dataset); + public TranslateOptions srcDataset(String srcDataset) { + add(srcDataset); return this; } - public TranslateOptions dstDataset(String dataset) { - add(dataset); + public TranslateOptions dstDataset(String dstDataset) { + add(dstDataset); return this; } } diff --git a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/WarpOptions.java b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/WarpOptions.java index f220cf65f..7d8bdd292 100644 --- a/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/WarpOptions.java +++ b/baremaps-gdal/src/main/java/org/apache/baremaps/gdal/WarpOptions.java @@ -52,12 +52,6 @@ public WarpOptions overwrite() { return this; } - public WarpOptions format(String format) { - add("-of"); - add(format); - return this; - } - public WarpOptions creationOption(String name, String value) { add("-co"); add(name + "=" + value); diff --git a/baremaps-server/src/main/java/org/apache/baremaps/server/BufferedImageResource.java b/baremaps-server/src/main/java/org/apache/baremaps/server/BufferedImageResource.java index 82ccc43a5..e9149407d 100644 --- a/baremaps-server/src/main/java/org/apache/baremaps/server/BufferedImageResource.java +++ b/baremaps-server/src/main/java/org/apache/baremaps/server/BufferedImageResource.java @@ -32,7 +32,6 @@ import javax.imageio.ImageIO; import org.apache.baremaps.tilestore.TileCoord; import org.apache.baremaps.tilestore.TileStore; -import org.apache.baremaps.tilestore.TileStoreException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,26 +52,21 @@ public BufferedImageResource(Supplier> tileStoreSupplie @Blocking public HttpResponse tile(@Param("z") int z, @Param("x") int x, @Param("y") int y) { TileCoord tileCoord = new TileCoord(x, y, z); - try { - TileStore tileStore = tileStoreSupplier.get(); + TileStore tileStore = tileStoreSupplier.get(); + try (var outputStream = new ByteArrayOutputStream()) { BufferedImage bufferedImage = tileStore.read(tileCoord); if (bufferedImage != null) { var headers = ResponseHeaders.builder(200) .add(CONTENT_TYPE, TILE_TYPE) .add(ACCESS_CONTROL_ALLOW_ORIGIN, "*") .build(); - - try (var outputStream = new ByteArrayOutputStream()) { - ImageIO.write(bufferedImage, "png", outputStream); - HttpData data = HttpData.wrap(outputStream.toByteArray()); - return HttpResponse.of(headers, data); - } catch (Exception e) { - return HttpResponse.of(204); - } + ImageIO.write(bufferedImage, "png", outputStream); + HttpData data = HttpData.wrap(outputStream.toByteArray()); + return HttpResponse.of(headers, data); } else { return HttpResponse.of(204); } - } catch (TileStoreException ex) { + } catch (Exception ex) { logger.error("Error while reading tile.", ex); return HttpResponse.of(404); }