diff --git a/Tests/Data/GeogToWGS84GeoKey5.lgo b/Tests/Data/GeogToWGS84GeoKey5.lgo new file mode 100644 index 000000000..2c7e3815c --- /dev/null +++ b/Tests/Data/GeogToWGS84GeoKey5.lgo @@ -0,0 +1,31 @@ +Geotiff_Information: + Version: 1 + Key_Revision: 1.0 + Tagged_Information: + ModelTiepointTag (2,3): + 50.5 50.5 0 + 9.00105738 52.001376 0 + ModelPixelScaleTag (1,3): + 2.77777778e-005 2.77777778e-005 1 + End_Of_Tags. + Keyed_Information: + GTModelTypeGeoKey (Short,1): ModelTypeGeographic + GTRasterTypeGeoKey (Short,1): RasterPixelIsArea + GeographicTypeGeoKey (Short,1): User-Defined + GeogGeodeticDatumGeoKey (Short,1): User-Defined + GeogAngularUnitsGeoKey (Short,1): Angular_Degree + GeogEllipsoidGeoKey (Short,1): Ellipse_Bessel_1841 + Unknown-2062 (Double,7): 598.1 73.7 418.2 +0.202 0.045 -2.455 +6.7 + End_Of_Keys. + End_Of_Geotiff. + +Ellipsoid: 7004/(unknown) (0.00,0.00) + +Corner Coordinates: +Upper Left ( 8d59'58.76"E, 52d 0'10.00"N) +Lower Left ( 8d59'58.76"E, 51d59'59.90"N) +Upper Right ( 9d 0' 8.86"E, 52d 0'10.00"N) +Lower Right ( 9d 0' 8.86"E, 51d59'59.90"N) +Center ( 9d 0' 3.81"E, 52d 0' 4.95"N) diff --git a/Tests/Data/GeogToWGS84GeoKey5.tif b/Tests/Data/GeogToWGS84GeoKey5.tif new file mode 100644 index 000000000..e878c608a Binary files /dev/null and b/Tests/Data/GeogToWGS84GeoKey5.tif differ diff --git a/Tests/Data/GeogToWGS84GeoKey5.txt b/Tests/Data/GeogToWGS84GeoKey5.txt new file mode 100644 index 000000000..4738d3380 --- /dev/null +++ b/Tests/Data/GeogToWGS84GeoKey5.txt @@ -0,0 +1,10 @@ +GeogToWGS84GeoKey5.tif is an sample GeoTIFF file for the GeogToWGS84GeoKey +geo key. After datum transformation to the WGS84 reference system the center +of the image (marked by a red pixel) should be exactly at N 52° E 9° in a +geographic coordinate system. + +The output of listgeo is included as GeogToWGS84GeoKey5.lgo. + +The files are placed in the public domain. + +Christian Zietz \ No newline at end of file diff --git a/Tests/Data/libgeotiff/GeogAngularUnitsGeoKey_9114.tif b/Tests/Data/libgeotiff/GeogAngularUnitsGeoKey_9114.tif new file mode 100644 index 000000000..e15144c15 Binary files /dev/null and b/Tests/Data/libgeotiff/GeogAngularUnitsGeoKey_9114.tif differ diff --git a/Tests/Data/libgeotiff/GeogGeodeticDatumGeoKey.tif b/Tests/Data/libgeotiff/GeogGeodeticDatumGeoKey.tif new file mode 100644 index 000000000..e34afd858 Binary files /dev/null and b/Tests/Data/libgeotiff/GeogGeodeticDatumGeoKey.tif differ diff --git a/Tests/Data/libgeotiff/GeogPrimeMeridianGeoKey.tif b/Tests/Data/libgeotiff/GeogPrimeMeridianGeoKey.tif new file mode 100644 index 000000000..7964cb578 Binary files /dev/null and b/Tests/Data/libgeotiff/GeogPrimeMeridianGeoKey.tif differ diff --git a/Tests/Data/libgeotiff/ProjLinearUnitsGeoKey_9036.tif b/Tests/Data/libgeotiff/ProjLinearUnitsGeoKey_9036.tif new file mode 100644 index 000000000..3169e5308 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjLinearUnitsGeoKey_9036.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_2046_transverse_mercator_south_oriented.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_2046_transverse_mercator_south_oriented.tif new file mode 100644 index 000000000..6fd6a90a6 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_2046_transverse_mercator_south_oriented.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_27200_new_zealand_mapping_grid.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_27200_new_zealand_mapping_grid.tif new file mode 100644 index 000000000..b41d64c78 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_27200_new_zealand_mapping_grid.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_28191_cassini_soldner.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_28191_cassini_soldner.tif new file mode 100644 index 000000000..4326cab1b Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_28191_cassini_soldner.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_29101_polyconic.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_29101_polyconic.tif new file mode 100644 index 000000000..aeda046f1 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_29101_polyconic.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3032_polar_stereographic_variant_b.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3032_polar_stereographic_variant_b.tif new file mode 100644 index 000000000..ac344781d Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3032_polar_stereographic_variant_b.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3035_lambert_azimuthal_equal_area.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3035_lambert_azimuthal_equal_area.tif new file mode 100644 index 000000000..313911a1c Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3035_lambert_azimuthal_equal_area.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3083_albers_equal_area.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3083_albers_equal_area.tif new file mode 100644 index 000000000..813322b05 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3083_albers_equal_area.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3410_lambert_cylindrical_equal_area.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3410_lambert_cylindrical_equal_area.tif new file mode 100644 index 000000000..60725aa7a Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3410_lambert_cylindrical_equal_area.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3812_lcc2sp.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3812_lcc2sp.tif new file mode 100644 index 000000000..848afe9c9 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3812_lcc2sp.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3814_transverse_mercator.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3814_transverse_mercator.tif new file mode 100644 index 000000000..497d3f552 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_3814_transverse_mercator.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_4087_equidistant_cylindrical.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_4087_equidistant_cylindrical.tif new file mode 100644 index 000000000..b01885846 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_4087_equidistant_cylindrical.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5329_mercator1sp.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5329_mercator1sp.tif new file mode 100644 index 000000000..a06dd85e0 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5329_mercator1sp.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5456_lcc1sp.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5456_lcc1sp.tif new file mode 100644 index 000000000..64bc46346 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5456_lcc1sp.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5482_polar_stereographic_variant_a.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5482_polar_stereographic_variant_a.tif new file mode 100644 index 000000000..28b6defb3 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5482_polar_stereographic_variant_a.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5588_oblique_stereographic.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5588_oblique_stereographic.tif new file mode 100644 index 000000000..0c0fc4336 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5588_oblique_stereographic.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5641_mercator2sp.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5641_mercator2sp.tif new file mode 100644 index 000000000..2bba355f4 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_5641_mercator2sp.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_6808_hotine_oblique_mercator_variant_a.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_6808_hotine_oblique_mercator_variant_a.tif new file mode 100644 index 000000000..1e5e10eab Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_6808_hotine_oblique_mercator_variant_a.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_8065_hotine_oblique_mercator_variant_b.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_8065_hotine_oblique_mercator_variant_b.tif new file mode 100644 index 000000000..325727943 Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_8065_hotine_oblique_mercator_variant_b.tif differ diff --git a/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_8441_oblique_mercator_laborde.tif b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_8441_oblique_mercator_laborde.tif new file mode 100644 index 000000000..b9c88831d Binary files /dev/null and b/Tests/Data/libgeotiff/ProjectedCSTypeGeoKey_8441_oblique_mercator_laborde.tif differ diff --git a/Tests/Data/libgeotiff/albers_equal_area.tif b/Tests/Data/libgeotiff/albers_equal_area.tif new file mode 100644 index 000000000..1d5f8633c Binary files /dev/null and b/Tests/Data/libgeotiff/albers_equal_area.tif differ diff --git a/Tests/Data/libgeotiff/byte.tif b/Tests/Data/libgeotiff/byte.tif new file mode 100644 index 000000000..6fddac128 Binary files /dev/null and b/Tests/Data/libgeotiff/byte.tif differ diff --git a/Tests/Data/libgeotiff/byte_v11.tif b/Tests/Data/libgeotiff/byte_v11.tif new file mode 100644 index 000000000..e6d8f023f Binary files /dev/null and b/Tests/Data/libgeotiff/byte_v11.tif differ diff --git a/Tests/Data/libgeotiff/cassini_soldner.tif b/Tests/Data/libgeotiff/cassini_soldner.tif new file mode 100644 index 000000000..54c3dbe11 Binary files /dev/null and b/Tests/Data/libgeotiff/cassini_soldner.tif differ diff --git a/Tests/Data/libgeotiff/equidistant_cylindrical.tif b/Tests/Data/libgeotiff/equidistant_cylindrical.tif new file mode 100644 index 000000000..308f87046 Binary files /dev/null and b/Tests/Data/libgeotiff/equidistant_cylindrical.tif differ diff --git a/Tests/Data/libgeotiff/hotine_oblique_mercator_variant_a.tif b/Tests/Data/libgeotiff/hotine_oblique_mercator_variant_a.tif new file mode 100644 index 000000000..6e0a02dfe Binary files /dev/null and b/Tests/Data/libgeotiff/hotine_oblique_mercator_variant_a.tif differ diff --git a/Tests/Data/libgeotiff/hotine_oblique_mercator_variant_b.tif b/Tests/Data/libgeotiff/hotine_oblique_mercator_variant_b.tif new file mode 100644 index 000000000..d84033885 Binary files /dev/null and b/Tests/Data/libgeotiff/hotine_oblique_mercator_variant_b.tif differ diff --git a/Tests/Data/libgeotiff/lambert_azimuthal_equal_area.tif b/Tests/Data/libgeotiff/lambert_azimuthal_equal_area.tif new file mode 100644 index 000000000..78da3313c Binary files /dev/null and b/Tests/Data/libgeotiff/lambert_azimuthal_equal_area.tif differ diff --git a/Tests/Data/libgeotiff/lambert_cylindrical_equal_area.tif b/Tests/Data/libgeotiff/lambert_cylindrical_equal_area.tif new file mode 100644 index 000000000..7c87e79a4 Binary files /dev/null and b/Tests/Data/libgeotiff/lambert_cylindrical_equal_area.tif differ diff --git a/Tests/Data/libgeotiff/lcc1sp.tif b/Tests/Data/libgeotiff/lcc1sp.tif new file mode 100644 index 000000000..8324b86ae Binary files /dev/null and b/Tests/Data/libgeotiff/lcc1sp.tif differ diff --git a/Tests/Data/libgeotiff/lcc2sp.tif b/Tests/Data/libgeotiff/lcc2sp.tif new file mode 100644 index 000000000..7096c996d Binary files /dev/null and b/Tests/Data/libgeotiff/lcc2sp.tif differ diff --git a/Tests/Data/libgeotiff/mercator1sp.tif b/Tests/Data/libgeotiff/mercator1sp.tif new file mode 100644 index 000000000..37f3372c1 Binary files /dev/null and b/Tests/Data/libgeotiff/mercator1sp.tif differ diff --git a/Tests/Data/libgeotiff/mercator2sp.tif b/Tests/Data/libgeotiff/mercator2sp.tif new file mode 100644 index 000000000..8b49fea30 Binary files /dev/null and b/Tests/Data/libgeotiff/mercator2sp.tif differ diff --git a/Tests/Data/libgeotiff/new_zealand_mapping_grid.tif b/Tests/Data/libgeotiff/new_zealand_mapping_grid.tif new file mode 100644 index 000000000..dd9a2dec5 Binary files /dev/null and b/Tests/Data/libgeotiff/new_zealand_mapping_grid.tif differ diff --git a/Tests/Data/libgeotiff/oblique_mercator_laborde.tif b/Tests/Data/libgeotiff/oblique_mercator_laborde.tif new file mode 100644 index 000000000..01eb113aa Binary files /dev/null and b/Tests/Data/libgeotiff/oblique_mercator_laborde.tif differ diff --git a/Tests/Data/libgeotiff/oblique_stereographic.tif b/Tests/Data/libgeotiff/oblique_stereographic.tif new file mode 100644 index 000000000..849ae81b2 Binary files /dev/null and b/Tests/Data/libgeotiff/oblique_stereographic.tif differ diff --git a/Tests/Data/libgeotiff/pcs_32064.tif b/Tests/Data/libgeotiff/pcs_32064.tif new file mode 100644 index 000000000..19ff4f388 Binary files /dev/null and b/Tests/Data/libgeotiff/pcs_32064.tif differ diff --git a/Tests/Data/libgeotiff/pixel_is_point_wgs84.tif b/Tests/Data/libgeotiff/pixel_is_point_wgs84.tif new file mode 100644 index 000000000..f8a7ab272 Binary files /dev/null and b/Tests/Data/libgeotiff/pixel_is_point_wgs84.tif differ diff --git a/Tests/Data/libgeotiff/polar_stereographic_variant_a.tif b/Tests/Data/libgeotiff/polar_stereographic_variant_a.tif new file mode 100644 index 000000000..2d510da27 Binary files /dev/null and b/Tests/Data/libgeotiff/polar_stereographic_variant_a.tif differ diff --git a/Tests/Data/libgeotiff/polar_stereographic_variant_b.tif b/Tests/Data/libgeotiff/polar_stereographic_variant_b.tif new file mode 100644 index 000000000..906b0fdbd Binary files /dev/null and b/Tests/Data/libgeotiff/polar_stereographic_variant_b.tif differ diff --git a/Tests/Data/libgeotiff/polyconic.tif b/Tests/Data/libgeotiff/polyconic.tif new file mode 100644 index 000000000..a11875b6d Binary files /dev/null and b/Tests/Data/libgeotiff/polyconic.tif differ diff --git a/Tests/Data/libgeotiff/transverse_mercator.tif b/Tests/Data/libgeotiff/transverse_mercator.tif new file mode 100644 index 000000000..827344819 Binary files /dev/null and b/Tests/Data/libgeotiff/transverse_mercator.tif differ diff --git a/Tests/Data/libgeotiff/transverse_mercator_south_oriented.tif b/Tests/Data/libgeotiff/transverse_mercator_south_oriented.tif new file mode 100644 index 000000000..1a79cfc69 Binary files /dev/null and b/Tests/Data/libgeotiff/transverse_mercator_south_oriented.tif differ diff --git a/Tests/com/drew/metadata/geotiff/GeoTiffTest.java b/Tests/com/drew/metadata/geotiff/GeoTiffTest.java new file mode 100644 index 000000000..b9d2eb1ed --- /dev/null +++ b/Tests/com/drew/metadata/geotiff/GeoTiffTest.java @@ -0,0 +1,102 @@ +/* + * Copyright 2002-2022 Drew Noakes and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * More information about this project is available at: + * + * https://drewnoakes.com/code/exif/ + * https://github.com/drewnoakes/metadata-extractor + */ +package com.drew.metadata.geotiff; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.Objects; + +import org.junit.Test; + +import com.drew.imaging.tiff.TiffMetadataReader; +import com.drew.metadata.Metadata; +import com.drew.metadata.exif.ExifDirectoryBase; +import com.drew.metadata.exif.ExifIFD0Directory; + +public class GeoTiffTest { + + @Test + public void testGeogToWGS84GeoKey5() throws Exception { + Metadata metadata = TiffMetadataReader.readMetadata(new File("Tests/Data/GeogToWGS84GeoKey5.tif")); + assertNotNull(metadata); + + ExifIFD0Directory exif = checkExif(metadata, 24); + + assertEquals("[32 values]", exif.getDescription(ExifDirectoryBase.TAG_GEOTIFF_GEO_KEYS)); + assertEquals("[768 values]", exif.getDescription(ExifDirectoryBase.TAG_COLOR_MAP)); + assertEquals("0 0 1", exif.getDescription(ExifDirectoryBase.TAG_PIXEL_SCALE)); + assertEquals("50.5 50.5 0 9.001 52.001 0", exif.getDescription(ExifDirectoryBase.TAG_MODEL_TIE_POINT).replace(',', '.')); + assertNull(exif.getDescription(ExifDirectoryBase.TAG_GEOTIFF_GEO_ASCII_PARAMS)); + assertNull(exif.getDescription(ExifDirectoryBase.TAG_GEOTIFF_GEO_DOUBLE_PARAMS)); + assertNull(exif.getDescription(ExifDirectoryBase.TAG_GDAL_METADATA)); + assertNull(exif.getDescription(ExifDirectoryBase.TAG_GDAL_NO_DATA)); + + GeoTiffDirectory geotiff = checkGeoTiff(metadata); + + assertEquals("Geographic", geotiff.getDescription(GeoTiffDirectory.TAG_MODEL_TYPE)); + assertEquals("PixelIsArea", geotiff.getDescription(GeoTiffDirectory.TAG_RASTER_TYPE)); + assertEquals("User Defined", geotiff.getDescription(GeoTiffDirectory.TAG_GEOGRAPHIC_TYPE)); + assertEquals("User Defined", geotiff.getDescription(GeoTiffDirectory.TAG_GEODETIC_DATUM)); + assertEquals("Angular Degree", geotiff.getDescription(GeoTiffDirectory.TAG_GEOGRAPHIC_ANGULAR_UNITS)); + assertEquals("Bessel 1841", geotiff.getDescription(GeoTiffDirectory.TAG_GEOGRAPHIC_ELLIPSOID)); + assertEquals("598.1 73.7 418.2 0.202 0.045 -2.455 6.7", geotiff.getDescription(GeoTiffDirectory.TAG_GEOGRAPHIC_TO_WGS84).replace(',', '.')); + assertEquals(7, geotiff.getTagCount()); + } + + @Test + public void testLibgeotiff() throws Exception { + for (File tiffFile : new File("Tests/Data/libgeotiff").listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.endsWith(".tif"); + } + })) + { + Metadata metadata = TiffMetadataReader.readMetadata(tiffFile); + assertNotNull(tiffFile.getName(), metadata); + checkExif(metadata, 14); + String description = tiffFile.getName() + "\n " + checkGeoTiff(metadata).getTags(); + assertFalse(description, description.contains("Unknown")); + } + } + + private static ExifIFD0Directory checkExif(Metadata metadata, int numberOfTags) { + ExifIFD0Directory exif = metadata.getDirectoriesOfType(ExifIFD0Directory.class).iterator().next(); + assertNotNull(exif); + assertFalse(Objects.toString(exif.getErrors()), exif.hasErrors()); + assertEquals(numberOfTags, exif.getTagCount()); + return exif; + } + + private static GeoTiffDirectory checkGeoTiff(Metadata metadata) { + GeoTiffDirectory geotiff = metadata.getDirectoriesOfType(GeoTiffDirectory.class).iterator().next(); + assertNotNull(geotiff); + assertFalse(Objects.toString(geotiff.getErrors()), geotiff.hasErrors()); + assertTrue(geotiff.getTagCount() > 0); + return geotiff; + } +}