From a12f2d69b85588752733cb5a6cb0fb898f4ed731 Mon Sep 17 00:00:00 2001 From: Dimitri Date: Mon, 21 Feb 2022 14:40:16 +1100 Subject: [PATCH] Add resolution x and y in export raster function, and fix y coordinates which was the lower y instead of the upper y --- .../org/flsgen/solver/LandscapeGenerator.java | 17 +++++++++++++---- src/main/java/org/flsgen/solver/Terrain.java | 11 ++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/flsgen/solver/LandscapeGenerator.java b/src/main/java/org/flsgen/solver/LandscapeGenerator.java index 03da3dd..3eee7b6 100644 --- a/src/main/java/org/flsgen/solver/LandscapeGenerator.java +++ b/src/main/java/org/flsgen/solver/LandscapeGenerator.java @@ -425,20 +425,25 @@ public int getRandomCell(ISet cells) { * Export the generated landscape to a raster file * @param x X position (geographical coordinates) of the top-left output raster pixel * @param y Y position (geographical coordinates) of the top-left output raster pixel - * @param resolution Spatial resolution (geographical units) of the output raster (i.e. pixel dimension) + * @param resolution_x x-spatial resolution (geographical units) of the output raster (i.e. pixel width) + * @param resolution_y y-spatial resolution (geographical units) of the output raster (i.e. pixel height) * @param epsg EPSG identifier of the output projection * @param dest path of output raster * @throws IOException * @throws FactoryException */ - public void exportRaster(double x, double y, double resolution, String epsg, String dest) throws IOException, FactoryException { + public void exportRaster(double x, double y, double resolution_x, double resolution_y, String epsg, String dest) throws IOException, FactoryException { GridCoverageFactory gcf = new GridCoverageFactory(); CoordinateReferenceSystem crs = CRS.decode(epsg); ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope( - x, x + (grid.getNbCols() * resolution), - y, y + (grid.getNbRows() * resolution), + x, x + (grid.getNbCols() * resolution_x), + y - (grid.getNbRows() * resolution_y), y, crs ); + System.out.println(referencedEnvelope.getMinX()); + System.out.println(referencedEnvelope.getMinY()); + System.out.println(referencedEnvelope.getMaxX()); + System.out.println(referencedEnvelope.getMaxY()); int[] data; if (grid instanceof PartialRegularSquareGrid) { int noDataValue = (int) CheckLandscape.getNodataValue(structure.maskRasterPath); @@ -467,6 +472,10 @@ public void exportRaster(double x, double y, double resolution, String epsg, Str writer.dispose(); } + public void exportRaster(double x, double y, double resolution, String epsg, String dest) throws IOException, FactoryException { + exportRaster(x, y, resolution, resolution, epsg, dest); + } + /** * Landscape generation main algorithm * @param terrainDependency the terrain dependency, between 0 (no terrain dependency) and 1 (only guided by terrain) diff --git a/src/main/java/org/flsgen/solver/Terrain.java b/src/main/java/org/flsgen/solver/Terrain.java index ce8e250..e6d2c7d 100644 --- a/src/main/java/org/flsgen/solver/Terrain.java +++ b/src/main/java/org/flsgen/solver/Terrain.java @@ -133,12 +133,12 @@ public static double randomDouble(double min, double max) { return new Random().nextDouble() * (max - min) + min; } - public void exportRaster(double x, double y, double resolution, String epsg, String dest) throws IOException, FactoryException { + public void exportRaster(double x, double y, double resolution_x, double resolution_y, String epsg, String dest) throws IOException, FactoryException { GridCoverageFactory gcf = new GridCoverageFactory(); CoordinateReferenceSystem crs = CRS.decode(epsg); ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope( - x, x + (grid.getNbCols() * resolution), - y, y + (grid.getNbRows() * resolution), + x, x + (grid.getNbCols() * resolution_x), + y - + (grid.getNbRows() * resolution_y), y, crs ); WritableRaster rast = RasterFactory.createBandedRaster( @@ -154,4 +154,9 @@ public void exportRaster(double x, double y, double resolution, String epsg, Str gc.dispose(true); writer.dispose(); } + + public void exportRaster(double x, double y, double resolution, String epsg, String dest) throws IOException, FactoryException { + exportRaster(x, y, resolution, resolution, epsg, dest); + } + }