I'm trying to read my .tiff image using GeoTools. After reading I intend to perform georeferencing of the image using the four coordinates of the image. Following is my code.
public static void main(String[] args) throws IOException, FactoryException {
AbstractGridCoverage2DReader data = new GeoTiffReader(new FileInputStream(new File("a.tif")));
GridCoverageFactory gcf = new GridCoverageFactory();
CoordinateReferenceSystem crs = CRS.decode("EPSG:29901");// null;//null;
int llx = 500000;
int lly = 105000;
int urx = 501000;
int ury = 106000;
ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(llx, urx, lly, ury, crs);
GridCoverage2D gc = gcf.create("name", (RenderedImage) data, referencedEnvelope);
String url = "random.tif";
File file = new File(url);
GeoTiffWriter writer = null;
try {
writer = new GeoTiffWriter(file);
} catch (IOException e) {
e.printStackTrace();
}
writer.write(gc, null);
writer.dispose();
}
I am getting the following exceptions and warnings.
WARNING: Coordinate Reference System is not available
Exception in thread "main" org.geotools.data.DataSourceException: Raster to Model Transformation is not available for: null
at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:279)
at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:192)
at IrishGridConverter.main(IrishGridConverter.java:26)
Caused by: org.geotools.data.DataSourceException: Raster to Model Transformation is not available for: null
at org.geotools.gce.geotiff.GeoTiffReader.getHRInfo(GeoTiffReader.java:539)
at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:265)
... 2 more
what could be the potential reasons, and how can I solve?
crs
? do you have a referencing jar in your classpath?gt-epsg-hsql
dependency set in my pom.xml.a.tif
a GeoTiff or just a tiff?BufferedImage image = ImageIO.read(inputFile);
instead