Skip to content

Commit

Permalink
Add GeoTIFF test using sample data from OSGEO/libgeotiff
Browse files Browse the repository at this point in the history
  • Loading branch information
don-vip committed Jun 19, 2022
1 parent 6f82eaa commit 7bef8a1
Show file tree
Hide file tree
Showing 50 changed files with 143 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Tests/Data/GeogToWGS84GeoKey5.lgo
Original file line number Diff line number Diff line change
@@ -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)
Binary file added Tests/Data/GeogToWGS84GeoKey5.tif
Binary file not shown.
10 changes: 10 additions & 0 deletions Tests/Data/GeogToWGS84GeoKey5.txt
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
Binary file not shown.
Binary file added Tests/Data/libgeotiff/GeogGeodeticDatumGeoKey.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/GeogPrimeMeridianGeoKey.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/ProjLinearUnitsGeoKey_9036.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Tests/Data/libgeotiff/albers_equal_area.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/byte.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/byte_v11.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/cassini_soldner.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/equidistant_cylindrical.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Tests/Data/libgeotiff/lcc1sp.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/lcc2sp.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/mercator1sp.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/mercator2sp.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/new_zealand_mapping_grid.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/oblique_mercator_laborde.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/oblique_stereographic.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/pcs_32064.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/pixel_is_point_wgs84.tif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Tests/Data/libgeotiff/polyconic.tif
Binary file not shown.
Binary file added Tests/Data/libgeotiff/transverse_mercator.tif
Binary file not shown.
Binary file not shown.
102 changes: 102 additions & 0 deletions Tests/com/drew/metadata/geotiff/GeoTiffTest.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 7bef8a1

Please sign in to comment.