Skip to content

Commit 259bf01

Browse files
authored
Merge pull request #451 from Stefal/add-GPS-GPSHPositioningError-support
Add support of GPSHPositioningError
2 parents 53becbb + 96dd0ea commit 259bf01

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/main/java/org/apache/commons/imaging/formats/tiff/constants/GpsTagConstants.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,21 @@ public final class GpsTagConstants {
148148

149149
public static final int GPS_TAG_GPS_DIFFERENTIAL_VALUE_DIFFERENTIAL_CORRECTED = 1;
150150

151+
/**
152+
* Horizontal positioning errors in meters.
153+
*
154+
* @since 1.0.0-alpha6
155+
*/
156+
public static final TagInfoRational GPS_TAG_GPS_HOR_POSITIONING_ERROR = new TagInfoRational("GPSHPositioningError", 0x001f,
157+
TiffDirectoryType.EXIF_DIRECTORY_GPS);
158+
151159
public static final List<TagInfo> ALL_GPS_TAGS = Collections.unmodifiableList(Arrays.asList(GPS_TAG_GPS_VERSION_ID, GPS_TAG_GPS_LATITUDE_REF,
152160
GPS_TAG_GPS_LATITUDE, GPS_TAG_GPS_LONGITUDE_REF, GPS_TAG_GPS_LONGITUDE, GPS_TAG_GPS_ALTITUDE_REF, GPS_TAG_GPS_ALTITUDE, GPS_TAG_GPS_TIME_STAMP,
153161
GPS_TAG_GPS_SATELLITES, GPS_TAG_GPS_STATUS, GPS_TAG_GPS_MEASURE_MODE, GPS_TAG_GPS_DOP, GPS_TAG_GPS_SPEED_REF, GPS_TAG_GPS_SPEED,
154162
GPS_TAG_GPS_TRACK_REF, GPS_TAG_GPS_TRACK, GPS_TAG_GPS_IMG_DIRECTION_REF, GPS_TAG_GPS_IMG_DIRECTION, GPS_TAG_GPS_MAP_DATUM,
155163
GPS_TAG_GPS_DEST_LATITUDE_REF, GPS_TAG_GPS_DEST_LATITUDE, GPS_TAG_GPS_DEST_LONGITUDE_REF, GPS_TAG_GPS_DEST_LONGITUDE, GPS_TAG_GPS_DEST_BEARING_REF,
156164
GPS_TAG_GPS_DEST_BEARING, GPS_TAG_GPS_DEST_DISTANCE_REF, GPS_TAG_GPS_DEST_DISTANCE, GPS_TAG_GPS_PROCESSING_METHOD, GPS_TAG_GPS_AREA_INFORMATION,
157-
GPS_TAG_GPS_DATE_STAMP, GPS_TAG_GPS_DIFFERENTIAL));
165+
GPS_TAG_GPS_DATE_STAMP, GPS_TAG_GPS_DIFFERENTIAL, GPS_TAG_GPS_HOR_POSITIONING_ERROR));
158166

159167
public static byte[] gpsVersion() {
160168
return GPS_VERSION.clone();

src/test/java/org/apache/commons/imaging/formats/jpeg/exif/GpsTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717

1818
package org.apache.commons.imaging.formats.jpeg.exif;
1919

20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
2022
import java.io.File;
2123
import java.util.stream.Stream;
2224

2325
import org.apache.commons.imaging.Imaging;
26+
import org.apache.commons.imaging.common.RationalNumber;
2427
import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
28+
import org.apache.commons.imaging.formats.tiff.TiffField;
2529
import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
30+
import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
2631
import org.apache.commons.imaging.internal.Debug;
32+
import org.junit.jupiter.api.Test;
2733
import org.junit.jupiter.params.ParameterizedTest;
2834
import org.junit.jupiter.params.provider.MethodSource;
2935

@@ -63,4 +69,16 @@ public void test(final File imageFile) throws Exception {
6369
Debug.debug();
6470

6571
}
72+
73+
/**
74+
* @throws Exception if it cannot open the images.
75+
*/
76+
@Test
77+
public void testReadMetadata() throws Exception {
78+
final File imageFile = new File(GpsTest.class.getResource("/images/jpeg/exif/2024-04-30_G012.JPG").getFile());
79+
final JpegImageMetadata jpegMetadata = (JpegImageMetadata) Imaging.getMetadata(imageFile);
80+
final TiffField gpsHPosErrorField = jpegMetadata.findExifValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_HOR_POSITIONING_ERROR);
81+
final RationalNumber gpsHPosError = (RationalNumber) gpsHPosErrorField.getValue();
82+
assertEquals(0.014, gpsHPosError.doubleValue());
83+
}
6684
}
45.8 KB
Loading

0 commit comments

Comments
 (0)