Skip to content

Commit

Permalink
Merge pull request #215 from integratedmodelling/IM-485-Error-unable-…
Browse files Browse the repository at this point in the history
…to-find-a-convex-corner

Im 485 error unable to find a convex corner
  • Loading branch information
inigo-cobian authored Dec 9, 2024
2 parents 5969d38 + 7b0d5b7 commit c501eac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
28 changes: 28 additions & 0 deletions klab.engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,19 @@
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</exclusion>
<exclusion>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>${jts.version}</version>
</dependency>

<!-- all of a sudden, WCS parsing stops working unless this is added. -->
<dependency>
<groupId>xml-apis</groupId>
Expand Down Expand Up @@ -642,6 +652,12 @@
<groupId>org.orbisgis</groupId>
<artifactId>h2gis</artifactId>
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- https://mvnrepository.com/artifact/args4j/args4j startup options parser -->
Expand Down Expand Up @@ -718,11 +734,23 @@
<groupId>org.geotools</groupId>
<artifactId>gt-process</artifactId>
<version>${geotools.version}</version>
<exclusions>
<exclusion>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-process-raster</artifactId>
<version>${geotools.version}</version>
<exclusions>
<exclusion>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import org.locationtech.jts.triangulate.polygon.PolygonTriangulator;

/**
* Simple, flexible rasterizer using an AWT image as a backend and closures to determine (a) the
Expand Down Expand Up @@ -131,9 +132,8 @@ public Collection<Coordinate> getCoordinates(IShape shape) {

Geometry geometry = ((Shape) shape).getJTSGeometry();
Color valueColor = new Color(255, 255, 255);
Color holeColor = new Color(0, 0, 0);

draw(geometry, valueColor, holeColor);
draw(geometry, valueColor);

int[] xy = new int[2];
for (int x = 0; x < this.raster.getWidth(); x++) {
Expand Down Expand Up @@ -165,36 +165,33 @@ public void add(IShape shape, Function<IShape, T> encoder) {
Geometry geometry = ((Shape) shape).getJTSGeometry();

int rgbVal = floatBitsToInt(encodeToFloat(value));
int holeVal = floatBitsToInt(Float.NaN);
Color valueColor = new Color(rgbVal, true);
Color holeColor = new Color(holeVal, true);

draw(geometry, valueColor, holeColor);
draw(geometry, valueColor);
}

private void draw(Geometry geometry, Color valueColor, Color holeColor) {
private void draw(Geometry geometry, Color valueColor) {

Geometries geomType = Geometries.get(geometry);
if (geomType == Geometries.MULTIPOLYGON || geomType == Geometries.MULTILINESTRING
|| geomType == Geometries.MULTIPOINT || geomType == Geometries.GEOMETRYCOLLECTION) {
final int numGeom = geometry.getNumGeometries();
for (int i = 0; i < numGeom; i++) {
Geometry geomN = geometry.getGeometryN(i);
draw(geomN, valueColor, holeColor);
draw(geomN, valueColor);
}
} else /* if (geometry.intersects(((Grid) extent).getShape().getJTSGeometry())) */ {

if (geometry.getClass().equals(Polygon.class)) {

for (int i = 0; i < geometry.getNumGeometries(); i++) {
Polygon poly = (Polygon) geometry.getGeometryN(i);
LinearRing lr = geoFactory.createLinearRing(poly.getExteriorRing().getCoordinates());
Polygon part = geoFactory.createPolygon(lr, null);
drawGeometry(part, valueColor);
for (int j = 0; j < poly.getNumInteriorRing(); j++) {
lr = geoFactory.createLinearRing(poly.getInteriorRingN(j).getCoordinates());
part = geoFactory.createPolygon(lr, null);
drawGeometry(part, holeColor);
boolean hasHoles = poly.getNumInteriorRing() > 0;
if (hasHoles) {
Geometry triangles = PolygonTriangulator.triangulate(poly);
draw(triangles, valueColor);
} else {
drawGeometry(poly, valueColor);
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
should be the same one that geotools and HM needs. -->
<geotools.version>28.0</geotools.version>
<hortonmachine.version>0.10.9-SNAPSHOT</hortonmachine.version>
<jts.version>1.18.1</jts.version>
<jts.version>1.20.0</jts.version>
<h2gis.version>1.5.0</h2gis.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down

0 comments on commit c501eac

Please sign in to comment.