我编写了一段访问大型Geotiff的Java代码。我的代码使用GeoTiffReader方法。当我在本地运行代码时,我只需传递GeoTiffReader文件名,一切正常。但是,我最终试图让代码从AWS S3存储桶中读取栅格。 我试图做的是设置一个本地FileInputStream,并将其传递给GeoTiffReader。它似乎工作正常,达到一定程度。它正确地读取了波段数,CRS,一切......除了实际数据!当我尝试阅读时,它会崩溃。以下两行是向南走的地方:
这有效:
GridCoverage2DReader reader = new GeoTiffReader(file); //One result from the grid read
this.grid = reader.read(null);
这不是:
GridCoverage2DReader reader = new GeoTiffReader(fileInputStream); //One result from the grid read
this.grid = reader.read(null);
当发送FileInputStream时,read方法会获得AbstractGridCoverage2DReader类。在getRescaledRasterToModel方法内部,它在
的第一行崩溃final int ssWidth = coverageRaster.getWidth();
如果我在本地或在AWS s3存储桶上托管文件,我会收到同样的错误。正如我所说,它打开GeoTiff就好了,并访问所有位置数据。它只是最终读取实际数据失败了。任何帮助都非常感谢!
密钥导入如下:
import org.geotools.coverage.grid.io.GridCoverage2DReader;
import org.geotools.gce.geotiff.GeoTiffReader;
import org.geotools.coverage.grid.*;
import org.opengis.coverage.grid.*;
import org.geotools.geometry.DirectPosition2D;
import org.geotools.geometry.jts.JTS;
import org.geotools.referencing.CRS;
import org.opengis.geometry.DirectPosition;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
如果我使用Netbeans标准调试设置运行,我会得到以下堆栈跟踪:
JPDA Listening Start...
JPDA Address: BruceXPS15:53848
Port:53848
cd C:\Users\Mount\OneDrive\Documents\GeoTiffTest; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_77" cmd /c "\"\"C:\\Program Files\\NetBeans 8.2\\java\\maven\\bin\\mvn.bat\" -Dexec.args=\"-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=53848 -classpath %classpath GeoTIFF_Demo.GeoTIFF_Test\" -Dexec.executable=\"C:\\Program Files\\Java\\jdk1.8.0_77\\bin\\java.exe\" -Dexec.classpathScope=runtime -Djpda.listen=true -Djpda.address=53848 -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.2.1:exec\""
Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
------------------------------------------------------------------------
Building GeoTiffTest_Local 1.0-SNAPSHOT
------------------------------------------------------------------------
--- exec-maven-plugin:1.2.1:exec (default-cli) @ GeoTiffTest ---
Exception in thread "main" javax.media.jai.util.ImagingException: All factories fail for the operation "ImageRead"
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1687)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getWidth(RenderedOp.java:2179)
at org.geotools.coverage.grid.io.AbstractGridCoverage2DReader.getRescaledRasterToModel(AbstractGridCoverage2DReader.java:1231)
at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:591)
at GeoTIFF_Demo.GeoTifReader.<init>(GeoTifReader.java:33)
at GeoTIFF_Demo.GeoTIFF_Test.main(GeoTIFF_Test.java:35)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
... 9 more
Caused by: java.lang.RuntimeException: javax.imageio.IIOException: I/O error reading header!
at com.sun.media.jai.imageioimpl.ImageReadCRIF.create(ImageReadCRIF.java:317)
... 15 more
Caused by: javax.imageio.IIOException: I/O error reading header!
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.readHeader(TIFFImageReader.java:458)
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.locateImage(TIFFImageReader.java:465)
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:589)
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.getImageTypes(TIFFImageReader.java:1104)
at javax.imageio.ImageReader.getRawImageType(ImageReader.java:681)
at com.sun.media.jai.imageioimpl.ImageReadOpImage.layoutHelper(ImageReadOpImage.java:228)
at com.sun.media.jai.imageioimpl.ImageReadOpImage.<init>(ImageReadOpImage.java:473)
at com.sun.media.jai.imageioimpl.ImageReadCRIF.create(ImageReadCRIF.java:309)
... 15 more
Caused by: java.io.EOFException
at javax.imageio.stream.ImageInputStreamImpl.readShort(ImageInputStreamImpl.java:229)
at javax.imageio.stream.ImageInputStreamImpl.readUnsignedShort(ImageInputStreamImpl.java:242)
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.readHeader(TIFFImageReader.java:404)
... 22 more
Caused by:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.media.jai.FactoryCache.invoke(FactoryCache.java:122)
at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819)
at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867)
at javax.media.jai.RenderedOp.getWidth(RenderedOp.java:2179)
at org.geotools.coverage.grid.io.AbstractGridCoverage2DReader.getRescaledRasterToModel(AbstractGridCoverage2DReader.java:1231)
at org.geotools.gce.geotiff.GeoTiffReader.read(GeoTiffReader.java:591)
at GeoTIFF_Demo.GeoTifReader.<init>(GeoTifReader.java:33)
at GeoTIFF_Demo.GeoTIFF_Test.main(GeoTIFF_Test.java:35)
Caused by: java.lang.RuntimeException: javax.imageio.IIOException: I/O error reading header!
at com.sun.media.jai.imageioimpl.ImageReadCRIF.create(ImageReadCRIF.java:317)
... 15 more
Caused by: javax.imageio.IIOException: I/O error reading header!
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.readHeader(TIFFImageReader.java:458)
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.locateImage(TIFFImageReader.java:465)
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:589)
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.getImageTypes(TIFFImageReader.java:1104)
at javax.imageio.ImageReader.getRawImageType(ImageReader.java:681)
at com.sun.media.jai.imageioimpl.ImageReadOpImage.layoutHelper(ImageReadOpImage.java:228)
at com.sun.media.jai.imageioimpl.ImageReadOpImage.<init>(ImageReadOpImage.java:473)
at com.sun.media.jai.imageioimpl.ImageReadCRIF.create(ImageReadCRIF.java:309)
... 15 more
Caused by: java.io.EOFException
at javax.imageio.stream.ImageInputStreamImpl.readShort(ImageInputStreamImpl.java:229)
at javax.imageio.stream.ImageInputStreamImpl.readUnsignedShort(ImageInputStreamImpl.java:242)
at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.readHeader(TIFFImageReader.java:404)
... 22 more
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 6.253s
Finished at: Mon Dec 12 15:48:47 EST 2016
Final Memory: 6M/153M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project GeoTiffTest: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException