Skip to content

Commit

Permalink
Fix rasterization
Browse files Browse the repository at this point in the history
  • Loading branch information
Kontinuation committed Jun 8, 2024
1 parent 53e9ec7 commit e52ff26
Showing 1 changed file with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,29 +178,30 @@ private static List<Object> rasterization(Geometry geom, GridCoverage2D raster,

Envelope2D bound = null;

int width, height;
if (useGeometryExtent) {
bound = JTS.getEnvelope2D(geom.getEnvelopeInternal(), raster.getCoordinateReferenceSystem2D());
double scaleX = Math.abs(metadata[4]), scaleY = Math.abs(metadata[5]);
double boundWidth = bound.getWidth(), boundHeight = bound.getHeight();
width = (int) (boundWidth / Math.abs(scaleX));
height = (int) (boundHeight / Math.abs(scaleY));
if (width == 0 && height == 0) {
bound = new Envelope2D(bound.getCoordinateReferenceSystem(), bound.getCenterX() - scaleX * 0.5, bound.getCenterY() - scaleY * 0.5, scaleX, scaleY);
width = 1;
height = 1;
} else if (height == 0) {
bound = new Envelope2D(bound.getCoordinateReferenceSystem(), bound.getCenterX() - scaleX * 0.5, bound.getCenterY() - scaleY * 0.5, boundWidth, scaleY);
height = 1;
} else if (width == 0) {
bound = new Envelope2D(bound.getCoordinateReferenceSystem(), bound.getCenterX() - scaleX * 0.5, bound.getCenterY() - scaleY * 0.5, scaleX, boundHeight);
width = 1;
}
} else {
ReferencedEnvelope envelope = ReferencedEnvelope.create(raster.getEnvelope(), raster.getCoordinateReferenceSystem());
bound = JTS.getEnvelope2D(envelope, raster.getCoordinateReferenceSystem2D());
}

double scaleX = Math.abs(metadata[4]), scaleY = Math.abs(metadata[5]);
int width = (int) bound.getWidth(), height = (int) bound.getHeight();
if (width == 0 && height == 0) {
bound = new Envelope2D(bound.getCoordinateReferenceSystem(), bound.getCenterX() - scaleX * 0.5, bound.getCenterY() - scaleY * 0.5, scaleX, scaleY);
width = 1;
height = 1;
} else if (height == 0) {
bound = new Envelope2D(bound.getCoordinateReferenceSystem(), bound.getCenterX() - scaleX * 0.5, bound.getCenterY() - scaleY * 0.5, width, scaleY);
height = 1;
} else if (width == 0) {
bound = new Envelope2D(bound.getCoordinateReferenceSystem(), bound.getCenterX() - scaleX * 0.5, bound.getCenterY() - scaleY * 0.5, scaleX, height);
width = 1;
} else {
// To preserve scale of reference raster
width = (int) (width / scaleX);
height = (int) (height / scaleY);
GridEnvelope2D gridRange = raster.getGridGeometry().getGridRange2D();
width = gridRange.width;
height = gridRange.height;
}

VectorToRasterProcess rasterProcess = new VectorToRasterProcess();
Expand Down

0 comments on commit e52ff26

Please sign in to comment.