List of usage examples for org.apache.commons.imaging.formats.tiff.constants GpsTagConstants GPS_TAG_GPS_LATITUDE_REF
TagInfoAscii GPS_TAG_GPS_LATITUDE_REF
To view the source code for org.apache.commons.imaging.formats.tiff.constants GpsTagConstants GPS_TAG_GPS_LATITUDE_REF.
Click Source Link
From source file:org.openstreetmap.josm.plugins.mapillary.oauth.UploadTest.java
/** * Tests the {@link UploadUtils#updateFile(MapillaryImportedImage)} method. *//*from ww w.jav a2s . c o m*/ @Test public void updateFileTest() throws IOException { File image = new File("images/icon16.png"); MapillaryImportedImage img = ImageUtil.readImagesFrom(image, new LatLon(0, 0)).get(0); File updatedFile = null; try { updatedFile = UploadUtils.updateFile(img); ImageMetadata metadata = Imaging.getMetadata(updatedFile); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; assertTrue(jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF) != null); assertTrue(jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE) != null); assertTrue(jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF) != null); assertTrue(jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE) != null); assertTrue(jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION) != null); assertTrue( jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL) != null); assertEquals(0, MapillaryUtils.degMinSecToDouble( (RationalNumber[]) jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE).getValue(), jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF) .getValue().toString()), 0.01); assertEquals(0, MapillaryUtils.degMinSecToDouble( (RationalNumber[]) jpegMetadata .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE).getValue(), jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF) .getValue().toString()), 0.01); } catch (ImageReadException | ImageWriteException | IOException e) { fail(); } finally { updatedFile.delete(); } }
From source file:org.openstreetmap.josm.plugins.mapillary.utils.ImageImportUtil.java
/** * @param is the input stream to read the metadata from * @param f the file that will be set as a field to the returned {@link MapillaryImportedImage} * @param defaultLL the coordinates that the image should get, if no coordinates are found in metadata * @return the {@link MapillaryImportedImage} with the read metadata and the given file set * @throws IOException if an IOException occurs while reading from the input stream *//*w w w. j av a2 s . c o m*/ private static MapillaryImportedImage readImageFrom(final InputStream is, final File f, final LatLon defaultLL) throws IOException { Object latRef = null; Object lonRef = null; Object lat = null; Object lon = null; Object gpsDir = null; Object dateTime = null; final ImageMetadata meta; try { meta = Imaging.getMetadata(is, null); if (meta instanceof JpegImageMetadata) { final JpegImageMetadata jpegMeta = (JpegImageMetadata) meta; latRef = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); lonRef = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); lat = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_LATITUDE); lon = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_LONGITUDE); gpsDir = getTiffFieldValue(jpegMeta, GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); dateTime = getTiffFieldValue(jpegMeta, ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); } } catch (ImageReadException e) { // Can't read metadata from image, use defaults instead } final LatLon latLon; if (lat instanceof RationalNumber[] && latRef != null && lon instanceof RationalNumber[] && lonRef != null) { latLon = new LatLon(MapillaryUtils.degMinSecToDouble((RationalNumber[]) lat, latRef.toString()), MapillaryUtils.degMinSecToDouble((RationalNumber[]) lon, lonRef.toString())); } else { latLon = defaultLL; } final double ca; if (gpsDir instanceof RationalNumber) { ca = ((RationalNumber) gpsDir).doubleValue(); } else { ca = 0; } if (dateTime == null) { return new MapillaryImportedImage(latLon, ca, f); } return new MapillaryImportedImage(latLon, ca, f, dateTime.toString()); }