Skip to content

Commit

Permalink
Add resolution x and y in export raster function, and fix y coordinat…
Browse files Browse the repository at this point in the history
…es which was the lower y instead of the upper y
  • Loading branch information
dimitri-justeau committed Feb 21, 2022
1 parent 889d3e9 commit a12f2d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/flsgen/solver/LandscapeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/flsgen/solver/Terrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}

}

0 comments on commit a12f2d6

Please sign in to comment.