Revision: 6461 http://sourceforge.net/p/jump-pilot/code/6461 Author: ma15569 Date: 2020-09-14 07:51:37 +0000 (Mon, 14 Sep 2020) Log Message: ----------- Chenged method to get Envelope directly form GeoRasterImage. This solves the bug about the right dimension of AsterDEM noted by Michael
Modified Paths: -------------- core/trunk/src/org/openjump/core/rasterimage/RasterImageIO.java core/trunk/src/org/openjump/core/rasterimage/RasterImageIOUtils.java core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java Modified: core/trunk/src/org/openjump/core/rasterimage/RasterImageIO.java =================================================================== --- core/trunk/src/org/openjump/core/rasterimage/RasterImageIO.java 2020-09-13 18:28:24 UTC (rev 6460) +++ core/trunk/src/org/openjump/core/rasterimage/RasterImageIO.java 2020-09-14 07:51:37 UTC (rev 6461) @@ -117,9 +117,9 @@ } } - - Envelope envelope = getGeoReferencing(fileNameOrURL, true, - new Point(bImage.getWidth(), bImage.getHeight())); + Envelope envelope = getGeoReferencing(fileNameOrURL); + //Envelope envelope = getGeoReferencing(fileNameOrURL, true, + // new Point(bImage.getWidth(), bImage.getHeight())); double cellSize = (envelope.getMaxX() - envelope.getMinX()) / bImage.getWidth(); return new ImageAndMetadata(bImage, new Metadata(envelope, @@ -136,8 +136,9 @@ int imgWidth = tiffMetadata.getColsCount(); int imgHeight = tiffMetadata.getRowsCount(); - Envelope imageEnvelope = getGeoReferencing(fileNameOrURL, true, - new Point(imgWidth, imgHeight)); + Envelope imageEnvelope = getGeoReferencing(fileNameOrURL); + // Envelope imageEnvelope = getGeoReferencing(fileNameOrURL, true, + // new Point(imgWidth, imgHeight)); Overviews overviews = OverviewsUtils.getOverviews(new File( fileNameOrURL), imageEnvelope); @@ -296,9 +297,9 @@ Coordinate coordinate, int band) throws Exception { Point imageDims = getImageDimensions(fileNameOrURL); - - Envelope envelope = getGeoReferencing(fileNameOrURL, true, new Point( - imageDims.x, imageDims.y)); + Envelope envelope = getGeoReferencing(fileNameOrURL); + //Envelope envelope = getGeoReferencing(fileNameOrURL, true, new Point( + // imageDims.x, imageDims.y)); double cellSizeX = (envelope.getMaxX() - envelope.getMinX()) / imageDims.x; double cellSizeY = (envelope.getMaxY() - envelope.getMinY()) @@ -414,6 +415,30 @@ return null; } + /** + * Get Envelope from file + * @param fileName + * @return Envelope + * @throws ReferencedImageException + */ + + public static Envelope getGeoReferencing(String fileName) throws ReferencedImageException { + GeoReferencedRaster geoRaster = new GeoReferencedRaster(new File(fileName).toURI().toString()); + return geoRaster.getEnvelope(); + + } + + /** + * Substituted by method getGeoReferencing(String fileName) + * @deprecated + * @param fileName + * @param allwaysLookForTFWExtension + * @param imageDimensions + * @return Envelope + * @throws Exception + */ + + @Deprecated public static Envelope getGeoReferencing(String fileName, boolean allwaysLookForTFWExtension, Point imageDimensions) throws Exception { @@ -610,14 +635,15 @@ } } return env; - } + } public static CellSizeXY getCellSize(String fileNameOrURL) throws Exception { Point imageDims = getImageDimensions(fileNameOrURL); - Envelope envelope = getGeoReferencing(fileNameOrURL, true, new Point( - imageDims.x, imageDims.y)); + Envelope envelope = getGeoReferencing(fileNameOrURL); + // Envelope envelope = getGeoReferencing(fileNameOrURL, true, new Point( +// imageDims.x, imageDims.y)); double cellSizeX = (envelope.getMaxX() - envelope.getMinX()) / imageDims.x; double cellSizeY = (envelope.getMaxY() - envelope.getMinY()) @@ -839,9 +865,9 @@ public static Resolution calcRequestedResolution(Viewport viewport) { double xRes = viewport.getEnvelopeInModelCoordinates().getWidth() - / (double) viewport.getPanel().getVisibleRect().width; + / viewport.getPanel().getVisibleRect().width; double yRes = viewport.getEnvelopeInModelCoordinates().getHeight() - / (double) viewport.getPanel().getVisibleRect().height; + / viewport.getPanel().getVisibleRect().height; return new Resolution(xRes, yRes); } Modified: core/trunk/src/org/openjump/core/rasterimage/RasterImageIOUtils.java =================================================================== --- core/trunk/src/org/openjump/core/rasterimage/RasterImageIOUtils.java 2020-09-13 18:28:24 UTC (rev 6460) +++ core/trunk/src/org/openjump/core/rasterimage/RasterImageIOUtils.java 2020-09-14 07:51:37 UTC (rev 6461) @@ -1,6 +1,5 @@ package org.openjump.core.rasterimage; -import java.awt.Point; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; @@ -780,10 +779,10 @@ ImageAndMetadata imageAndMetadata = rasterImageIO.loadImage( context.getWorkbenchContext(), file.getAbsolutePath(), null, viewport.getEnvelopeInModelCoordinates(), requestedRes); - Point point = RasterImageIO.getImageDimensions(file.getAbsolutePath()); - Envelope env = RasterImageIO.getGeoReferencing(file.getAbsolutePath(), - true, point); - + // Point point = RasterImageIO.getImageDimensions(file.getAbsolutePath()); + // Envelope env = RasterImageIO.getGeoReferencing(file.getAbsolutePath(), + // true, point); + Envelope env = RasterImageIO.getGeoReferencing(file.getAbsolutePath()); RasterImageLayer ril = new RasterImageLayer(file.getName(), context .getWorkbenchContext().getLayerManager(), file.getAbsolutePath(), imageAndMetadata.getImage(), env); Modified: core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java =================================================================== --- core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java 2020-09-13 18:28:24 UTC (rev 6460) +++ core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java 2020-09-14 07:51:37 UTC (rev 6461) @@ -1,10 +1,6 @@ package org.openjump.core.rasterimage; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Envelope; -import com.vividsolutions.jump.workbench.Logger; -import com.vividsolutions.jump.workbench.imagery.ReferencedImageException; -import com.vividsolutions.jump.workbench.imagery.geoimg.GeoReferencedRaster; +import static org.openjump.core.rasterimage.RasterImageIO.getGeoReferencing; import java.awt.Point; import java.awt.Rectangle; @@ -17,6 +13,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.List; + import javax.imageio.ImageIO; import javax.imageio.ImageReadParam; import javax.imageio.ImageReader; @@ -27,13 +24,18 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; + import org.apache.commons.imaging.ImageReadException; import org.apache.commons.imaging.formats.tiff.TiffField; import org.apache.commons.imaging.formats.tiff.TiffImageMetadata; import org.apache.commons.imaging.formats.tiff.TiffImageParser; -import static org.openjump.core.rasterimage.RasterImageIO.getGeoReferencing; import org.xml.sax.SAXException; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Envelope; +import com.vividsolutions.jump.workbench.Logger; +import com.vividsolutions.jump.workbench.imagery.geoimg.GeoReferencedRaster; + /** * * @author AdL @@ -60,8 +62,8 @@ envelope.getHeight() / originalImageHeight); } - Envelope wholeImageEnvelope = getGeoReferencing(tiffFile.getAbsolutePath(), true, new Point (originalImageWidth, originalImageHeight)); - + // Envelope wholeImageEnvelope = getGeoReferencing(tiffFile.getAbsolutePath(), true, new Point (originalImageWidth, originalImageHeight)); + Envelope wholeImageEnvelope = getGeoReferencing(tiffFile.getAbsolutePath()); if(requestedRes == null) { requestedRes = cellSize; } @@ -153,7 +155,7 @@ if(iterator != null && iterator.hasNext()) { - ImageReader imageReader = (ImageReader) iterator.next(); + ImageReader imageReader = iterator.next(); imageReader.setInput(imageInputStream); for(int i=0; i<imageReader.getNumImages(true); i++) { if(i + indexStart == overviewIndex) { _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel