/** * description: the following TIFFKeys count as indicator if a TIFF-File carries GeoTIFF * information: <br> * ModelPixelScaleTag = 33550 (SoftDesk) <br> * ModelTransformationTag = 34264 (JPL Carto Group) <br> * ModelTiepointTag = 33922 (Intergraph) <br> * GeoKeyDirectoryTag = 34735 (SPOT) <br> * GeoDoubleParamsTag = 34736 (SPOT) <br> * GeoAsciiParamsTag = 34737 (SPOT) */ private boolean isGeoTiff(TIFFImage image) { TIFFDirectory directory = (TIFFDirectory) image.getProperty("tiff_directory"); if (directory.getField(GeoTiffTag.ModelPixelScaleTag) == null && directory.getField(GeoTiffTag.ModelTransformationTag) == null && directory.getField(GeoTiffTag.ModelTiepointTag) == null && directory.getField(GeoTiffTag.GeoKeyDirectoryTag) == null && directory.getField(GeoTiffTag.GeoDoubleParamsTag) == null && directory.getField(GeoTiffTag.GeoAsciiParamsTag) == null) { return false; } return true; }
/** * @return the bbox * @throws GeoTiffException */ public Envelope getBoundingBox() throws GeoTiffException { TIFFField modelPixelScaleTag = this.tifdir.getField(GeoTiffTag.ModelPixelScaleTag); double resx = modelPixelScaleTag.getAsDouble(0); double resy = modelPixelScaleTag.getAsDouble(1); TIFFField modelTiepointTag = this.tifdir.getField(GeoTiffTag.ModelTiepointTag); double val1 = 0.0; val1 = modelTiepointTag.getAsDouble(0); double val2 = 0.0; val2 = modelTiepointTag.getAsDouble(1); double val4 = 0.0; val4 = modelTiepointTag.getAsDouble(3); double val5 = 0.0; val5 = modelTiepointTag.getAsDouble(4); if ((resx == 0.0 || resy == 0.0) || (val1 == 0.0 && val2 == 0.0 && val4 == 0.0 && val5 == 0.0)) { throw new GeoTiffException("The image/coverage hasn't a bounding box"); // set the geoparams derived by geoTiffTags } // upper/left pixel double xOrigin = val4 - (val1 * resx); double yOrigin = val5 - (val2 * resy); // lower/right pixel double xRight = xOrigin + image.getWidth() * resx; double yBottom = yOrigin - image.getHeight() * resy; double xmin = xOrigin; double ymin = yBottom; double xmax = xRight; double ymax = yOrigin; Envelope envelope = geometryFactory.createEnvelope(xmin, ymin, xmax, ymax, null); return envelope; }
/** * @param file * @throws FileNotFoundException * @throws IOException * @throws GeoTiffException */ public GeoTiffReader(File file) throws FileNotFoundException, IOException, GeoTiffException { TIFFDecodeParam decodeParam = new TIFFDecodeParam(); int geodirectory = 0; FileInputStream fis = new FileInputStream(file); FileCacheSeekableStream fcss = new FileCacheSeekableStream(fis); this.image = new TIFFImage(fcss, decodeParam, geodirectory); if (!isGeoTiff(this.image)) { throw new GeoTiffException("GeoTiffReader: TIFF is no GeoTIFF image!"); } this.tifdir = (TIFFDirectory) image.getProperty("tiff_directory"); if (this.tifdir.getField(GeoTiffTag.GeoKeyDirectoryTag) != null) { setGeoKeyDirectoryTag(); } fcss.close(); }