Skip to content

Commit

Permalink
Revert "Merge pull request #210 from integratedmodelling/IM-437-Polyg…
Browse files Browse the repository at this point in the history
…ons-not-detected-by-k.LAB"

This reverts commit 969cfc0.
  • Loading branch information
inigo-cobian authored and euskalhenriko committed Nov 18, 2024
1 parent 2b98d94 commit 52fb9a5
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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 @@ -132,8 +131,9 @@ 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);
draw(geometry, valueColor, holeColor);

int[] xy = new int[2];
for (int x = 0; x < this.raster.getWidth(); x++) {
Expand Down Expand Up @@ -165,33 +165,36 @@ 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);
draw(geometry, valueColor, holeColor);
}

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

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);
draw(geomN, valueColor, holeColor);
}
} 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);
boolean hasHoles = poly.getNumInteriorRing() > 0;
if (hasHoles) {
Geometry triangles = PolygonTriangulator.triangulate(poly);
draw(triangles, valueColor);
} else {
drawGeometry(poly, valueColor);
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);
}
}
} else {
Expand Down

0 comments on commit 52fb9a5

Please sign in to comment.