Revision: 6676 http://sourceforge.net/p/jump-pilot/code/6676 Author: ma15569 Date: 2021-12-02 05:44:49 +0000 (Thu, 02 Dec 2021) Log Message: ----------- Removed shift of 0.5 pixel in GeoTiff
Modified Paths: -------------- core/trunk/src/org/openjump/core/rasterimage/RasterImageLayer.java core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java Modified: core/trunk/src/org/openjump/core/rasterimage/RasterImageLayer.java =================================================================== --- core/trunk/src/org/openjump/core/rasterimage/RasterImageLayer.java 2021-11-29 17:00:42 UTC (rev 6675) +++ core/trunk/src/org/openjump/core/rasterimage/RasterImageLayer.java 2021-12-02 05:44:49 UTC (rev 6676) @@ -1343,55 +1343,31 @@ return RasterImageIO.loadRasterData(imageFileName, subset); } + //Upgraded to OpenJUMP 2 modification public Rectangle getRectangleFromEnvelope(Envelope envelope) { - - double imgWidth = origImageWidth; - double imgHeight = origImageHeight; - Envelope imageEnv = originalImageEnvelope; - - double minVisibleX = Math.max(envelope.getMinX(), imageEnv.getMinX()); - double minVisibleY = Math.max(envelope.getMinY(), imageEnv.getMinY()); - - double maxVisibleX = Math.min(envelope.getMaxX(), imageEnv.getMaxX()); - double maxVisibleY = Math.min(envelope.getMaxY(), imageEnv.getMaxY()); - - double offset2VisibleX = imageEnv.getMinX() - envelope.getMinX(); - double offset2VisibleY = envelope.getMaxY() - imageEnv.getMaxY(); - - double scaleX = imgWidth / imageEnv.getWidth(); - double scaleY = imgHeight / imageEnv.getHeight(); - - // use local variables! - int xOffset, yOffset, width, height; - - if (offset2VisibleX >= 0){ - xOffset = 0; - } else { - xOffset = (int)(-offset2VisibleX * scaleX); - } - - if (offset2VisibleY >= 0){ - yOffset = 0; - } else { - yOffset = (int)(-offset2VisibleY * scaleY); - } - - width = (int)((maxVisibleX-minVisibleX) * scaleX); - height = (int)((maxVisibleY-minVisibleY) * scaleY); - - if (width < imgWidth && height < imgHeight){ - width += 1; - height += 1; - } - - - if (width <= 0 || height <= 0) return null; - - int wantedWidth = (int)(envelope.getWidth() * scaleX); - int wantedHeight = (int)(envelope.getHeight() * scaleY); - - return new Rectangle(xOffset, yOffset, wantedWidth, wantedHeight); - } + final double imgWidth = origImageWidth; + final double imgHeight = origImageHeight; + final Envelope imageEnv = originalImageEnvelope; + final double offset2VisibleX = imageEnv.getMinX() - envelope.getMinX(); + final double offset2VisibleY = envelope.getMaxY() - imageEnv.getMaxY(); + final double scaleX = imgWidth / imageEnv.getWidth(); + final double scaleY = imgHeight / imageEnv.getHeight(); + // use local variables! + int xOffset, yOffset; + if (offset2VisibleX >= 0) { + xOffset = 0; + } else { + xOffset = (int) Math.round((-offset2VisibleX * scaleX)); + } + if (offset2VisibleY >= 0) { + yOffset = 0; + } else { + yOffset = (int) Math.round((-offset2VisibleY * scaleY)); + } + final int wantedWidth = (int) Math.round((envelope.getWidth() * scaleX)); + final int wantedHeight = (int) Math.round((envelope.getHeight() * scaleY)); + return new Rectangle(xOffset, yOffset, wantedWidth, wantedHeight); + } // /** // * to set the Raster data, use also setImage() Modified: core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java =================================================================== --- core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java 2021-11-29 17:00:42 UTC (rev 6675) +++ core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java 2021-12-02 05:44:49 UTC (rev 6676) @@ -59,11 +59,27 @@ return rop; } - public static Envelope getEnvelope(File tiffFile) throws IOException { - GeoReferencedRaster geoRaster = getGeoReferencedRaster(tiffFile); - - return geoRaster.getOriginalEnvelope(); - } + //[Giuseppe Aruta 2021-11-12] modified: + // first checks and reads a worldfile + // if no worldfile is found, then checks and reads geotiff tags + public static Envelope getEnvelope(File tiffFile) throws IOException { + final GeoReferencedRaster geoRaster = getGeoReferencedRaster(tiffFile); + final String filePath = tiffFile.getAbsolutePath(); + final WorldFileHandler worldFileHandler = new WorldFileHandler(filePath, true); + if (worldFileHandler.isWorldFileExistentForImage() != null) { + final RenderedOp op = getRenderedOp(tiffFile); + final Point imageDimensions = new Point(op.getWidth(), op.getHeight()); + return worldFileHandler.readWorldFile(imageDimensions.x, imageDimensions.y); + } else { + return geoRaster.getOriginalEnvelope(); + } + } + +// public static Envelope getEnvelope(File tiffFile) throws IOException { +// GeoReferencedRaster geoRaster = getGeoReferencedRaster(tiffFile); +// +// return geoRaster.getOriginalEnvelope(); +// } private static GeoReferencedRaster getGeoReferencedRaster(File tiffFile) throws IOException { // prevent recreating inputs by reusing cached RenderedOp _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel