Skip to content

Commit 159acf9

Browse files
committed
Add GeoTIFF test using sample data from OSGEO/libgeotiff
1 parent ad0e555 commit 159acf9

File tree

50 files changed

+143
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+143
-0
lines changed

Tests/Data/GeogToWGS84GeoKey5.lgo

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Geotiff_Information:
2+
Version: 1
3+
Key_Revision: 1.0
4+
Tagged_Information:
5+
ModelTiepointTag (2,3):
6+
50.5 50.5 0
7+
9.00105738 52.001376 0
8+
ModelPixelScaleTag (1,3):
9+
2.77777778e-005 2.77777778e-005 1
10+
End_Of_Tags.
11+
Keyed_Information:
12+
GTModelTypeGeoKey (Short,1): ModelTypeGeographic
13+
GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
14+
GeographicTypeGeoKey (Short,1): User-Defined
15+
GeogGeodeticDatumGeoKey (Short,1): User-Defined
16+
GeogAngularUnitsGeoKey (Short,1): Angular_Degree
17+
GeogEllipsoidGeoKey (Short,1): Ellipse_Bessel_1841
18+
Unknown-2062 (Double,7): 598.1 73.7 418.2
19+
0.202 0.045 -2.455
20+
6.7
21+
End_Of_Keys.
22+
End_Of_Geotiff.
23+
24+
Ellipsoid: 7004/(unknown) (0.00,0.00)
25+
26+
Corner Coordinates:
27+
Upper Left ( 8d59'58.76"E, 52d 0'10.00"N)
28+
Lower Left ( 8d59'58.76"E, 51d59'59.90"N)
29+
Upper Right ( 9d 0' 8.86"E, 52d 0'10.00"N)
30+
Lower Right ( 9d 0' 8.86"E, 51d59'59.90"N)
31+
Center ( 9d 0' 3.81"E, 52d 0' 4.95"N)

Tests/Data/GeogToWGS84GeoKey5.tif

3.96 KB
Binary file not shown.

Tests/Data/GeogToWGS84GeoKey5.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
GeogToWGS84GeoKey5.tif is an sample GeoTIFF file for the GeogToWGS84GeoKey
2+
geo key. After datum transformation to the WGS84 reference system the center
3+
of the image (marked by a red pixel) should be exactly at N 52° E 9° in a
4+
geographic coordinate system.
5+
6+
The output of listgeo is included as GeogToWGS84GeoKey5.lgo.
7+
8+
The files are placed in the public domain.
9+
10+
Christian Zietz <[email protected]>
Binary file not shown.
312 Bytes
Binary file not shown.
441 Bytes
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.
542 Bytes
Binary file not shown.

Tests/Data/libgeotiff/byte.tif

736 Bytes
Binary file not shown.

Tests/Data/libgeotiff/byte_v11.tif

736 Bytes
Binary file not shown.
595 Bytes
Binary file not shown.
526 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Tests/Data/libgeotiff/lcc1sp.tif

531 Bytes
Binary file not shown.

Tests/Data/libgeotiff/lcc2sp.tif

533 Bytes
Binary file not shown.

Tests/Data/libgeotiff/mercator1sp.tif

522 Bytes
Binary file not shown.

Tests/Data/libgeotiff/mercator2sp.tif

522 Bytes
Binary file not shown.
535 Bytes
Binary file not shown.
533 Bytes
Binary file not shown.
538 Bytes
Binary file not shown.

Tests/Data/libgeotiff/pcs_32064.tif

361 Bytes
Binary file not shown.
298 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

Tests/Data/libgeotiff/polyconic.tif

511 Bytes
Binary file not shown.
509 Bytes
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright 2002-2022 Drew Noakes and contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* More information about this project is available at:
17+
*
18+
* https://drewnoakes.com/code/exif/
19+
* https://github.com/drewnoakes/metadata-extractor
20+
*/
21+
package com.drew.metadata.geotiff;
22+
23+
import static org.junit.Assert.assertEquals;
24+
import static org.junit.Assert.assertFalse;
25+
import static org.junit.Assert.assertNotNull;
26+
import static org.junit.Assert.assertNull;
27+
import static org.junit.Assert.assertTrue;
28+
29+
import java.io.File;
30+
import java.io.FilenameFilter;
31+
import java.util.Objects;
32+
33+
import org.junit.Test;
34+
35+
import com.drew.imaging.tiff.TiffMetadataReader;
36+
import com.drew.metadata.Metadata;
37+
import com.drew.metadata.exif.ExifDirectoryBase;
38+
import com.drew.metadata.exif.ExifIFD0Directory;
39+
40+
public class GeoTiffTest {
41+
42+
@Test
43+
public void testGeogToWGS84GeoKey5() throws Exception {
44+
Metadata metadata = TiffMetadataReader.readMetadata(new File("Tests/Data/GeogToWGS84GeoKey5.tif"));
45+
assertNotNull(metadata);
46+
47+
ExifIFD0Directory exif = checkExif(metadata, 24);
48+
49+
assertEquals("[32 values]", exif.getDescription(ExifDirectoryBase.TAG_GEOTIFF_GEO_KEYS));
50+
assertEquals("[768 values]", exif.getDescription(ExifDirectoryBase.TAG_COLOR_MAP));
51+
assertEquals("0 0 1", exif.getDescription(ExifDirectoryBase.TAG_PIXEL_SCALE));
52+
assertEquals("50.5 50.5 0 9.001 52.001 0", exif.getDescription(ExifDirectoryBase.TAG_MODEL_TIE_POINT).replace(',', '.'));
53+
assertNull(exif.getDescription(ExifDirectoryBase.TAG_GEOTIFF_GEO_ASCII_PARAMS));
54+
assertNull(exif.getDescription(ExifDirectoryBase.TAG_GEOTIFF_GEO_DOUBLE_PARAMS));
55+
assertNull(exif.getDescription(ExifDirectoryBase.TAG_GDAL_METADATA));
56+
assertNull(exif.getDescription(ExifDirectoryBase.TAG_GDAL_NO_DATA));
57+
58+
GeoTiffDirectory geotiff = checkGeoTiff(metadata);
59+
60+
assertEquals("Geographic", geotiff.getDescription(GeoTiffDirectory.TAG_MODEL_TYPE));
61+
assertEquals("PixelIsArea", geotiff.getDescription(GeoTiffDirectory.TAG_RASTER_TYPE));
62+
assertEquals("User Defined", geotiff.getDescription(GeoTiffDirectory.TAG_GEOGRAPHIC_TYPE));
63+
assertEquals("User Defined", geotiff.getDescription(GeoTiffDirectory.TAG_GEODETIC_DATUM));
64+
assertEquals("Angular Degree", geotiff.getDescription(GeoTiffDirectory.TAG_GEOGRAPHIC_ANGULAR_UNITS));
65+
assertEquals("Bessel 1841", geotiff.getDescription(GeoTiffDirectory.TAG_GEOGRAPHIC_ELLIPSOID));
66+
assertEquals("598.1 73.7 418.2 0.202 0.045 -2.455 6.7", geotiff.getDescription(GeoTiffDirectory.TAG_GEOGRAPHIC_TO_WGS84).replace(',', '.'));
67+
assertEquals(7, geotiff.getTagCount());
68+
}
69+
70+
@Test
71+
public void testLibgeotiff() throws Exception {
72+
for (File tiffFile : new File("Tests/Data/libgeotiff").listFiles(new FilenameFilter() {
73+
@Override
74+
public boolean accept(File dir, String name) {
75+
return name.endsWith(".tif");
76+
}
77+
}))
78+
{
79+
Metadata metadata = TiffMetadataReader.readMetadata(tiffFile);
80+
assertNotNull(tiffFile.getName(), metadata);
81+
checkExif(metadata, 14);
82+
String description = tiffFile.getName() + "\n " + checkGeoTiff(metadata).getTags();
83+
assertFalse(description, description.contains("Unknown"));
84+
}
85+
}
86+
87+
private static ExifIFD0Directory checkExif(Metadata metadata, int numberOfTags) {
88+
ExifIFD0Directory exif = metadata.getDirectoriesOfType(ExifIFD0Directory.class).iterator().next();
89+
assertNotNull(exif);
90+
assertFalse(Objects.toString(exif.getErrors()), exif.hasErrors());
91+
assertEquals(numberOfTags, exif.getTagCount());
92+
return exif;
93+
}
94+
95+
private static GeoTiffDirectory checkGeoTiff(Metadata metadata) {
96+
GeoTiffDirectory geotiff = metadata.getDirectoriesOfType(GeoTiffDirectory.class).iterator().next();
97+
assertNotNull(geotiff);
98+
assertFalse(Objects.toString(geotiff.getErrors()), geotiff.hasErrors());
99+
assertTrue(geotiff.getTagCount() > 0);
100+
return geotiff;
101+
}
102+
}

0 commit comments

Comments
 (0)