github-advanced-security[bot] commented on code in PR #884:
URL: 
https://github.com/apache/incubator-baremaps/pull/884#discussion_r1723938939


##########
baremaps-raster/src/main/java/org/apache/baremaps/raster/ContourTracer.java:
##########
@@ -0,0 +1,403 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.raster;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import org.locationtech.jts.geom.*;
+import org.locationtech.jts.geom.util.GeometryTransformer;
+import org.locationtech.jts.operation.linemerge.LineMerger;
+
+/**
+ * Provides methods for generating contour lines and contour polygons from 
digital elevation models
+ * (DEMs).
+ */
+public class ContourTracer {
+
+  private static final GeometryFactory GEOMETRY_FACTORY = new 
GeometryFactory();
+
+  private static final double EPSILON = 1e-10;
+
+  private final double[] grid;
+
+  private final int width;
+
+  private final int height;
+
+  private final boolean normalize;
+
+  private final boolean polygonize;
+
+  /**
+   * Constructs a new ContourTracer with the specified grid, width, height, 
normalization, and
+   * polygonization options.
+   *
+   * @param grid The grid of elevation values
+   * @param width The width of the grid
+   * @param height The height of the grid
+   * @param normalize Whether to normalize the coordinates
+   * @param polygonize Whether to polygonize the contours
+   */
+  public ContourTracer(double[] grid, int width, int height, boolean normalize,
+      boolean polygonize) {
+    this.grid = Arrays.copyOf(grid, grid.length);
+    this.width = width;
+    this.height = height;
+    this.normalize = normalize;
+    this.polygonize = polygonize;
+  }
+
+  /**
+   * Generates isolines for a given grid at a specific level.
+   *
+   * @param level The elevation level for which to generate isolines
+   * @return A list of LineString objects representing the isolines
+   */
+  public List<Geometry> traceContours(double level) {
+    validateInput(grid, width, height);
+
+    // Process each cell in the grid to generate segments
+    List<LineString> cells = new ArrayList<>();
+    for (int y = 0; y < height - 1; y++) {
+      for (int x = 0; x < width - 1; x++) {
+        cells.addAll(processCell(level, x, y));
+      }
+    }
+
+    // Merge the cells
+    LineMerger cellMerger = new LineMerger();
+    cellMerger.add(cells);
+    List<Geometry> contours = new 
ArrayList<>(cellMerger.getMergedLineStrings());
+
+    // Polygonize the lines
+    if (polygonize) {
+      contours = contours.stream()
+          .map(Geometry::getCoordinates)
+          .map(GEOMETRY_FACTORY::createPolygon)
+          .map(Geometry.class::cast)
+          .toList();
+    }
+
+    // Normalize the coordinates
+    if (normalize) {
+      NormalizationTransformer transformer = new NormalizationTransformer();
+      contours = contours.stream()
+          .map(geometry -> transformer.transform(geometry.copy()))
+          .toList();
+    }
+
+    return contours;
+  }
+
+  /**
+   * Generates contour for a given range of elevation levels.
+   *
+   * @param start The starting elevation level (inclusive)
+   * @param end The ending elevation level (exclusive)
+   * @param interval The interval between elevation levels
+   * @return A list of contour geometries
+   */
+  public List<Geometry> traceContours(int start, int end, int interval) {
+    validateInput(grid, width, height);
+    List<Geometry> contours = new ArrayList<>();
+    for (int level = start; level < end; level += interval) {
+      contours.addAll(traceContours(level));
+    }
+    return contours;
+  }
+
+  private static void validateInput(double[] grid, int width, int height) {
+    if (grid == null || grid.length == 0) {
+      throw new IllegalArgumentException("Grid array cannot be null or empty");
+    }
+    if (width <= 0 || height <= 0) {
+      throw new IllegalArgumentException("Width and height must be positive");
+    }
+    if (grid.length != width * height) {
+      throw new IllegalArgumentException("Grid array length does not match 
width * height");
+    }
+  }
+
+  @SuppressWarnings("squid:S3776")
+  private List<LineString> processCell(double level, int x, int y) {
+    List<LineString> segments = new ArrayList<>();
+
+    boolean htb = polygonize && y == height - 2;
+    boolean hrb = polygonize && x == width - 2;
+    boolean hbb = polygonize && y == 0;
+    boolean hlb = polygonize && x == 0;
+
+    Coordinate tlc = new Coordinate(x, y + 1.0);
+    Coordinate tmc = interpolateCoordinate(level, x, y + 1, x + 1, y + 1);
+    Coordinate trc = new Coordinate(x + 1.0, y + 1.0);
+    Coordinate mrc = interpolateCoordinate(level, x + 1, y, x + 1, y + 1);
+    Coordinate brc = new Coordinate(x + 1.0, y);
+    Coordinate bmc = interpolateCoordinate(level, x, y, x + 1, y);
+    Coordinate blc = new Coordinate(x, y);
+    Coordinate mlc = interpolateCoordinate(level, x, y, x, y + 1);
+
+    double tlv = grid[y * width + x];
+    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;

Review Comment:
   ## Unread local variable
   
   Variable 'double avg' is never read.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1542)



##########
baremaps-raster/src/main/java/org/apache/baremaps/raster/gdal/ProgressCallback.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.raster.gdal;
+
+class ProgressCallback extends org.gdal.gdal.ProgressCallback {

Review Comment:
   ## Class has same name as super class
   
   ProgressCallback has the same name as its supertype 
[org.gdal.gdal.ProgressCallback](1).
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1541)



##########
baremaps-raster/src/main/java/org/apache/baremaps/raster/gdal/TranslateOptions.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.raster.gdal;
+
+public class TranslateOptions extends Options {
+
+  public TranslateOptions() {
+    super();
+  }
+
+  // Basic Options
+  public TranslateOptions help() {
+    add("--help");
+    return this;
+  }
+
+  public TranslateOptions helpGeneral() {
+    add("--help-general");
+    return this;
+  }
+
+  public TranslateOptions longUsage() {
+    add("--long-usage");
+    return this;
+  }
+
+  public TranslateOptions outputType(String type) {
+    add("-ot");
+    add(type);
+    return this;
+  }
+
+  public TranslateOptions strict() {
+    add("-strict");
+    return this;
+  }
+
+  public TranslateOptions inputFormat(String format) {
+    add("-if");
+    add(format);
+    return this;
+  }
+
+  public TranslateOptions outputFormat(String format) {
+    add("-of");
+    add(format);
+    return this;
+  }
+
+  public TranslateOptions band(int band) {
+    add("-b");
+    add(band);
+    return this;
+  }
+
+  public TranslateOptions maskBand(int band) {
+    add("-mask");
+    add(band);
+    return this;
+  }
+
+  public TranslateOptions expand(String option) {
+    add("-expand");
+    add(option);
+    return this;
+  }
+
+  public TranslateOptions outsize(int xsize, int ysize) {
+    add("-outsize");
+    add(xsize);
+    add(ysize);
+    return this;
+  }
+
+  public TranslateOptions outsizePercent(int xpercent, int ypercent) {
+    add("-outsize");
+    add(xpercent + "%");
+    add(ypercent + "%");
+    return this;
+  }
+
+  public TranslateOptions targetResolution(double xres, double yres) {
+    add("-tr");
+    add(xres);
+    add(yres);
+    return this;
+  }
+
+  public TranslateOptions overview(int level) {
+    add("-ovr");
+    add(level);
+    return this;
+  }
+
+  public TranslateOptions overviewAuto() {
+    add("-ovr");
+    add("AUTO");
+    return this;
+  }
+
+  public TranslateOptions overviewNone() {
+    add("-ovr");
+    add("NONE");
+    return this;
+  }
+
+  public TranslateOptions resamplingMethod(String method) {
+    add("-r");
+    add(method);
+    return this;
+  }
+
+  public TranslateOptions unscale() {
+    add("-unscale");
+    return this;
+  }
+
+  public TranslateOptions scale(int band, double srcMin, double srcMax, double 
dstMin,
+      double dstMax) {
+    add("-scale_" + band);
+    add(srcMin);
+    add(srcMax);
+    add(dstMin);
+    add(dstMax);
+    return this;
+  }
+
+  public TranslateOptions scale(double srcMin, double srcMax, double dstMin, 
double dstMax) {
+    add("-scale");
+    add(srcMin);
+    add(srcMax);
+    add(dstMin);
+    add(dstMax);
+    return this;
+  }
+
+  public TranslateOptions exponent(int band, double expVal) {
+    add("-exponent_" + band);
+    add(expVal);
+    return this;
+  }
+
+  public TranslateOptions exponent(double expVal) {
+    add("-exponent");
+    add(expVal);
+    return this;
+  }
+
+  public TranslateOptions srcWindow(int xoff, int yoff, int xsize, int ysize) {

Review Comment:
   ## Useless parameter
   
   The parameter 'ysize' is never used.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1539)



##########
baremaps-raster/src/main/java/org/apache/baremaps/raster/gdal/WarpOptions.java:
##########
@@ -0,0 +1,373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.raster.gdal;
+
+public class WarpOptions extends Options {
+
+  public WarpOptions() {
+    super();
+  }
+
+  // Basic Options
+  public WarpOptions help() {
+    add("--help");
+    return this;
+  }
+
+  public WarpOptions longUsage() {
+    add("--long-usage");
+    return this;
+  }
+
+  public WarpOptions helpGeneral() {
+    add("--help-general");
+    return this;
+  }
+
+  public WarpOptions quiet() {
+    add("--quiet");
+    return this;
+  }
+
+  public WarpOptions overwrite() {
+    add("-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);
+    return this;
+  }
+
+  public WarpOptions sourceSRS(String srs) {
+    add("-s_srs");
+    add(srs);
+    return this;
+  }
+
+  public WarpOptions targetSRS(String srs) {
+    add("-t_srs");
+    add(srs);
+    return this;
+  }
+
+  public WarpOptions srcAlpha() {
+    add("-srcalpha");
+    return this;
+  }
+
+  public WarpOptions noSrcAlpha() {
+    add("-nosrcalpha");
+    return this;
+  }
+
+  public WarpOptions dstAlpha() {
+    add("-dstalpha");
+    return this;
+  }
+
+  public WarpOptions targetResolution(double xRes, double yRes) {
+    add("-tr");
+    add(xRes);
+    add(yRes);
+    return this;
+  }
+
+  public WarpOptions targetResolutionSquare(double res) {
+    add("-tr");
+    add(res);
+    add(res);
+    return this;
+  }
+
+  public WarpOptions targetSize(int width, int height) {
+    add("-ts");
+    add(width);
+    add(height);
+    return this;
+  }
+
+  public WarpOptions targetExtent(double xmin, double ymin, double xmax, 
double ymax) {
+    add("-te");
+    add(xmin);
+    add(ymin);
+    add(xmax);
+    add(ymax);
+    return this;
+  }
+
+  public WarpOptions targetExtentSRS(String srs) {
+    add("-te_srs");
+    add(srs);
+    return this;
+  }
+
+  public WarpOptions resampling(String resampling) {
+    add("-r");
+    add(resampling);
+    return this;
+  }
+
+  public WarpOptions outputType(String type) {
+    add("-ot");
+    add(type);
+    return this;
+  }
+
+  public WarpOptions srcDataset(String datasetName) {
+    add(datasetName);
+    return this;
+  }
+
+  public WarpOptions dstDataset(String datasetName) {
+    add(datasetName);
+    return this;
+  }
+
+  // Advanced Options
+  public WarpOptions warpOption(String name, String value) {
+    add("-wo");
+    add(name + "=" + value);
+    return this;
+  }
+
+  public WarpOptions multi() {
+    add("-multi");
+    return this;
+  }
+
+  public WarpOptions srcCoordEpoch(String epoch) {
+    add("-s_coord_epoch");
+    add(epoch);
+    return this;
+  }
+
+  public WarpOptions tgtCoordEpoch(String epoch) {

Review Comment:
   ## Useless parameter
   
   The parameter 'epoch' is never used.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1540)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to