001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.gpx; 003 004import java.awt.Dimension; 005import java.awt.image.BufferedImage; 006import java.io.File; 007import java.io.IOException; 008import java.io.InputStream; 009import java.net.URI; 010import java.nio.file.Files; 011import java.time.Instant; 012import java.util.List; 013import java.util.Objects; 014 015import javax.imageio.IIOParam; 016 017import org.openstreetmap.josm.data.IQuadBucketType; 018import org.openstreetmap.josm.data.coor.CachedLatLon; 019import org.openstreetmap.josm.data.coor.ILatLon; 020import org.openstreetmap.josm.data.coor.LatLon; 021import org.openstreetmap.josm.data.imagery.street_level.Projections; 022import org.openstreetmap.josm.data.osm.BBox; 023import org.openstreetmap.josm.gui.layer.geoimage.ImageMetadata; 024 025/** 026 * Stores info about each image 027 * @since 14205 (extracted from gui.layer.geoimage.ImageEntry) 028 */ 029public class GpxImageEntry implements Comparable<GpxImageEntry>, IQuadBucketType, ImageMetadata { 030 private File file; 031 private Integer exifOrientation; 032 private LatLon exifCoor; 033 private Double exifImgDir; 034 private Double exifGpsTrack; 035 private Double exifHPosErr; 036 private Double exifGpsDop; 037 private Instant exifTime; 038 private Projections cameraProjection = Projections.UNKNOWN; 039 /** 040 * Flag isNewGpsData indicates that the GPS data of the image is new or has changed. 041 * GPS data includes the position, speed, elevation, time (e.g. as extracted from the GPS track). 042 * The flag can used to decide for which image file the EXIF GPS data is (re-)written. 043 */ 044 private boolean isNewGpsData; 045 /** Temporary source of GPS time if not correlated with GPX track. */ 046 private Instant exifGpsTime; 047 048 private String iptcCaption; 049 private String iptcHeadline; 050 private List<String> iptcKeywords; 051 private String iptcObjectName; 052 053 /** 054 * The following values are computed from the correlation with the gpx track 055 * or extracted from the image EXIF data. 056 */ 057 private CachedLatLon pos; 058 /** Speed in kilometer per hour */ 059 private Double speed; 060 /** Elevation (altitude) in meters */ 061 private Double elevation; 062 /** GPS Differential mode */ 063 private Integer gpsDiffMode; 064 /** GPS Measure mode */ 065 private Integer gps2d3dMode; 066 /** GPS Datum */ 067 private String exifGpsDatum; 068 /** GPS processing method */ 069 private String exifGpsProcMethod; 070 /** The time after correlation with a gpx track */ 071 private Instant gpsTime; 072 073 private int width; 074 private int height; 075 076 /** 077 * When the correlation dialog is open, we like to show the image position 078 * for the current time offset on the map in real time. 079 * On the other hand, when the user aborts this operation, the old values 080 * should be restored. We have a temporary copy, that overrides 081 * the normal values if it is not null. (This may be not the most elegant 082 * solution for this, but it works.) 083 */ 084 private GpxImageEntry tmp; 085 086 /** 087 * Constructs a new {@code GpxImageEntry}. 088 */ 089 public GpxImageEntry() {} 090 091 /** 092 * Constructs a new {@code GpxImageEntry} from an existing instance. 093 * @param other existing instance 094 * @since 14624 095 */ 096 public GpxImageEntry(GpxImageEntry other) { 097 file = other.file; 098 exifOrientation = other.exifOrientation; 099 exifCoor = other.exifCoor; 100 exifImgDir = other.exifImgDir; 101 exifGpsTrack = other.exifGpsTrack; 102 exifHPosErr = other.exifHPosErr; 103 gpsDiffMode = other.gpsDiffMode; 104 gps2d3dMode = other.gps2d3dMode; 105 exifGpsDop = other.exifGpsDop; 106 exifGpsDatum = other.exifGpsDatum; 107 exifGpsProcMethod = other.exifGpsProcMethod; 108 exifTime = other.exifTime; 109 isNewGpsData = other.isNewGpsData; 110 exifGpsTime = other.exifGpsTime; 111 pos = other.pos; 112 speed = other.speed; 113 elevation = other.elevation; 114 gpsTime = other.gpsTime; 115 width = other.width; 116 height = other.height; 117 tmp = other.tmp; 118 } 119 120 /** 121 * Constructs a new {@code GpxImageEntry}. 122 * @param file Path to image file on disk 123 */ 124 public GpxImageEntry(File file) { 125 setFile(file); 126 } 127 128 @Override 129 public URI getImageURI() { 130 return this.getFile().toURI(); 131 } 132 133 /** 134 * Returns width of the image this GpxImageEntry represents. 135 * @return width of the image this GpxImageEntry represents 136 * @since 13220 137 */ 138 @Override 139 public int getWidth() { 140 return width; 141 } 142 143 /** 144 * Returns height of the image this GpxImageEntry represents. 145 * @return height of the image this GpxImageEntry represents 146 * @since 13220 147 */ 148 @Override 149 public int getHeight() { 150 return height; 151 } 152 153 /** 154 * Returns the position value. The position value from the temporary copy 155 * is returned if that copy exists. 156 * @return the position value 157 */ 158 @Override 159 public CachedLatLon getPos() { 160 if (tmp != null) 161 return tmp.pos; 162 return pos; 163 } 164 165 /** 166 * Returns the speed value. The speed value from the temporary copy is 167 * returned if that copy exists. 168 * @return the speed value 169 */ 170 @Override 171 public Double getSpeed() { 172 if (tmp != null) 173 return tmp.speed; 174 return speed; 175 } 176 177 /** 178 * Returns the elevation value. The elevation value from the temporary 179 * copy is returned if that copy exists. 180 * @return the elevation value 181 */ 182 @Override 183 public Double getElevation() { 184 if (tmp != null) 185 return tmp.elevation; 186 return elevation; 187 } 188 189 /** 190 * Return the GPS Differential mode value. The GPS Differential mode value from the temporary 191 * copy is returned if that copy exists. 192 * @return the differential mode value 193 * @since 19387 194 */ 195 @Override 196 public Integer getGpsDiffMode() { 197 if (tmp != null) 198 return tmp.gpsDiffMode; 199 return gpsDiffMode; 200 } 201 202 /** 203 * Return the GPS 2d or 3d mode value. The GPS mode value form the temporary 204 * copy is returned if that copy exists. 205 * @return the GPS 2d/3d mode value 206 * @since 19387 207 */ 208 @Override 209 public Integer getGps2d3dMode() { 210 if (tmp != null) 211 return tmp.gps2d3dMode; 212 return gps2d3dMode; 213 } 214 215 /** 216 * Return the GPS DOP value. The GPS DOP value from the temporary 217 * copy is returned if that copy exists. 218 * @return the DOP value 219 * @since 19387 220 */ 221 @Override 222 public Double getExifGpsDop() { 223 if (tmp != null) 224 return tmp.exifGpsDop; 225 return exifGpsDop; 226 } 227 228 /** 229 * Return the EXIF GPS coordinates datum value. 230 * @return The datum value 231 * @since 19387 232 */ 233 @Override 234 public String getExifGpsDatum() { 235 if (tmp != null) 236 return tmp.exifGpsDatum; 237 return exifGpsDatum; 238 } 239 240 /** 241 * Return the EXIF GPS processing method string 242 * @return the processing method string 243 * @since 19387 244 */ 245 @Override 246 public String getExifGpsProcMethod() { 247 if (tmp != null) 248 return tmp.exifGpsProcMethod; 249 return exifGpsProcMethod; 250 } 251 252 /** 253 * Returns the GPS time value. The GPS time value from the temporary copy 254 * is returned if that copy exists. 255 * @return the GPS time value 256 */ 257 @Override 258 public Instant getGpsInstant() { 259 return tmp != null ? tmp.gpsTime : gpsTime; 260 } 261 262 /** 263 * Convenient way to determine if this entry has a GPS time, without the cost of building a defensive copy. 264 * @return {@code true} if this entry has a GPS time 265 * @since 6450 266 */ 267 @Override 268 public boolean hasGpsTime() { 269 return (tmp != null && tmp.gpsTime != null) || gpsTime != null; 270 } 271 272 /** 273 * Returns associated file. 274 * @return associated file 275 */ 276 public File getFile() { 277 return file; 278 } 279 280 /** 281 * Returns a display name for this entry 282 * @return a display name for this entry 283 */ 284 @Override 285 public String getDisplayName() { 286 return file == null ? "" : file.getName(); 287 } 288 289 /** 290 * Returns EXIF orientation 291 * @return EXIF orientation 292 */ 293 @Override 294 public Integer getExifOrientation() { 295 return exifOrientation != null ? exifOrientation : 1; 296 } 297 298 /** 299 * Returns EXIF time 300 * @return EXIF time 301 * @since 17715 302 */ 303 @Override 304 public Instant getExifInstant() { 305 return exifTime; 306 } 307 308 /** 309 * Convenient way to determine if this entry has a EXIF time, without the cost of building a defensive copy. 310 * @return {@code true} if this entry has a EXIF time 311 * @since 6450 312 */ 313 @Override 314 public boolean hasExifTime() { 315 return exifTime != null; 316 } 317 318 /** 319 * Returns the EXIF GPS time. 320 * @return the EXIF GPS time 321 * @since 17715 322 */ 323 @Override 324 public Instant getExifGpsInstant() { 325 return exifGpsTime; 326 } 327 328 /** 329 * Convenient way to determine if this entry has a EXIF GPS time, without the cost of building a defensive copy. 330 * @return {@code true} if this entry has a EXIF GPS time 331 * @since 6450 332 */ 333 @Override 334 public boolean hasExifGpsTime() { 335 return exifGpsTime != null; 336 } 337 338 /** 339 * Return the time value selected with the parameter. 340 * @param timeSource the wanted time value, exifCamTime or exifGpsTime 341 * @return exifInstant or exifGpsInstant value 342 * @since 19426 343 */ 344 @Override 345 public Instant getTimeSourceInstant(TimeSource timeSource) { 346 if (timeSource == TimeSource.EXIFGPSTIME) 347 return getExifGpsInstant(); 348 else if (timeSource == TimeSource.EXIFCAMTIME) 349 return getExifInstant(); 350 return null; 351 } 352 353 @Override 354 public LatLon getExifCoor() { 355 return exifCoor; 356 } 357 358 @Override 359 public Double getExifImgDir() { 360 if (tmp != null) 361 return tmp.exifImgDir; 362 return exifImgDir; 363 } 364 365 /** 366 * Convenient way to determine if this entry has a EXIF GPS track angle value, 367 * without the cost of building a defensive copy. 368 * @return {@code true} if this entry has a EXIF track angle value 369 * @since 19387 370 */ 371 @Override 372 public Double getExifGpsTrack() { 373 if (tmp != null) 374 return tmp.exifGpsTrack; 375 return exifGpsTrack; 376 } 377 378 /** 379 * Convenient way to determine if this entry has a EXIF GPS horizontal positionning error value, 380 * without the cost of building a defensive copy. 381 * @return {@code true} if this entry has a EXIF GPS horizontal positionning error value 382 * @since 19387 383 */ 384 @Override 385 public Double getExifHPosErr() { 386 if (tmp != null) 387 return tmp.exifHPosErr; 388 return exifHPosErr; 389 } 390 391 @Override 392 public Instant getLastModified() { 393 return Instant.ofEpochMilli(this.getFile().lastModified()); 394 } 395 396 /** 397 * Sets the width of this GpxImageEntry. 398 * @param width set the width of this GpxImageEntry 399 * @since 13220 400 */ 401 @Override 402 public void setWidth(int width) { 403 this.width = width; 404 } 405 406 /** 407 * Sets the height of this GpxImageEntry. 408 * @param height set the height of this GpxImageEntry 409 * @since 13220 410 */ 411 @Override 412 public void setHeight(int height) { 413 this.height = height; 414 } 415 416 /** 417 * Sets the position. 418 * @param pos cached position 419 */ 420 public void setPos(CachedLatLon pos) { 421 this.pos = pos; 422 } 423 424 /** 425 * Sets the position. 426 * @param pos position (will be cached) 427 */ 428 public void setPos(LatLon pos) { 429 setPos(pos != null ? new CachedLatLon(pos) : null); 430 } 431 432 @Override 433 public void setPos(ILatLon pos) { 434 if (pos instanceof CachedLatLon) { 435 this.setPos((CachedLatLon) pos); 436 } else if (pos instanceof LatLon) { 437 this.setPos((LatLon) pos); 438 } else if (pos != null) { 439 this.setPos(new LatLon(pos)); 440 } else { 441 this.setPos(null); 442 } 443 } 444 445 /** 446 * Sets the speed. 447 * @param speed speed 448 */ 449 @Override 450 public void setSpeed(Double speed) { 451 this.speed = speed; 452 } 453 454 /** 455 * Sets the elevation. 456 * @param elevation elevation 457 */ 458 @Override 459 public void setElevation(Double elevation) { 460 this.elevation = elevation; 461 } 462 463 /** 464 * Sets GPS Differential mode. 465 * @param gpsDiffMode GPS Differential mode 466 * @since 19387 467 */ 468 @Override 469 public void setGpsDiffMode(Integer gpsDiffMode) { 470 this.gpsDiffMode = gpsDiffMode; 471 } 472 473 /** 474 * Sets GPS 2d/3d mode. 475 * @param gps2d3dMode GPS 2d/3d mode value 476 * @since 19387 477 */ 478 @Override 479 public void setGps2d3dMode(Integer gps2d3dMode) { 480 this.gps2d3dMode = gps2d3dMode; 481 } 482 483 /** 484 * Sets GPS DOP value. 485 * @param exifGpsDop GPS DOP value 486 * @since 19387 487 */ 488 @Override 489 public void setExifGpsDop(Double exifGpsDop) { 490 this.exifGpsDop = exifGpsDop; 491 } 492 493 /** 494 * Sets the GPS Datum. 495 * @param exifGpsDatum GPS Datum 496 * @since 19387 497 */ 498 @Override 499 public void setExifGpsDatum(String exifGpsDatum) { 500 this.exifGpsDatum = exifGpsDatum; 501 } 502 503 /** 504 * Sets the GPS Processing Method. 505 * @param exifGpsProcMethod GPS Processing Method 506 * @since 19387 507 */ 508 @Override 509 public void setExifGpsProcMethod(String exifGpsProcMethod) { 510 this.exifGpsProcMethod = exifGpsProcMethod; 511 } 512 513 /** 514 * Sets associated file. 515 * @param file associated file 516 */ 517 public void setFile(File file) { 518 this.file = file; 519 } 520 521 /** 522 * Sets EXIF orientation. 523 * @param exifOrientation EXIF orientation 524 */ 525 @Override 526 public void setExifOrientation(Integer exifOrientation) { 527 this.exifOrientation = exifOrientation; 528 } 529 530 /** 531 * Sets EXIF time. 532 * @param exifTime EXIF time 533 * @since 17715 534 */ 535 @Override 536 public void setExifTime(Instant exifTime) { 537 this.exifTime = exifTime; 538 } 539 540 /** 541 * Sets the EXIF GPS time. 542 * @param exifGpsTime the EXIF GPS time 543 * @since 17715 544 */ 545 @Override 546 public void setExifGpsTime(Instant exifGpsTime) { 547 this.exifGpsTime = exifGpsTime; 548 } 549 550 /** 551 * Sets the GPS time. 552 * @param gpsTime the GPS time 553 * @since 17715 554 */ 555 @Override 556 public void setGpsTime(Instant gpsTime) { 557 this.gpsTime = gpsTime; 558 } 559 560 /** 561 * Sets the EXIF coordinate. 562 * @param exifCoor the coordinate 563 */ 564 public void setExifCoor(LatLon exifCoor) { 565 this.exifCoor = exifCoor; 566 } 567 568 @Override 569 public void setExifCoor(ILatLon exifCoor) { 570 if (exifCoor instanceof LatLon) { 571 this.exifCoor = (LatLon) exifCoor; 572 } else if (exifCoor != null) { 573 this.exifCoor = new LatLon(exifCoor); 574 } else { 575 this.exifCoor = null; 576 } 577 } 578 579 @Override 580 public void setExifImgDir(Double exifDir) { 581 this.exifImgDir = exifDir; 582 } 583 584 /** 585 * Sets the EXIF GPS track (move direction angle) 586 * @param exifGpsTrack the EXIF GPS track angle 587 * @since 19387 588 */ 589 @Override 590 public void setExifGpsTrack(Double exifGpsTrack) { 591 this.exifGpsTrack = exifGpsTrack; 592 } 593 594 /** 595 * Sets the EXIF horizontal positioning error 596 * @param exifHPosErr the EXIF horizontal positionning error 597 * @since 19387 598 */ 599 @Override 600 public void setExifHPosErr(Double exifHPosErr) { 601 this.exifHPosErr = exifHPosErr; 602 } 603 604 /** 605 * Sets the IPTC caption. 606 * @param iptcCaption the IPTC caption 607 * @since 15219 608 */ 609 @Override 610 public void setIptcCaption(String iptcCaption) { 611 this.iptcCaption = iptcCaption; 612 } 613 614 /** 615 * Sets the IPTC headline. 616 * @param iptcHeadline the IPTC headline 617 * @since 15219 618 */ 619 @Override 620 public void setIptcHeadline(String iptcHeadline) { 621 this.iptcHeadline = iptcHeadline; 622 } 623 624 /** 625 * Sets the IPTC keywords. 626 * @param iptcKeywords the IPTC keywords 627 * @since 15219 628 */ 629 @Override 630 public void setIptcKeywords(List<String> iptcKeywords) { 631 this.iptcKeywords = iptcKeywords; 632 } 633 634 /** 635 * Sets the IPTC object name. 636 * @param iptcObjectName the IPTC object name 637 * @since 15219 638 */ 639 @Override 640 public void setIptcObjectName(String iptcObjectName) { 641 this.iptcObjectName = iptcObjectName; 642 } 643 644 /** 645 * Returns the IPTC caption. 646 * @return the IPTC caption 647 * @since 15219 648 */ 649 @Override 650 public String getIptcCaption() { 651 return iptcCaption; 652 } 653 654 /** 655 * Returns the IPTC headline. 656 * @return the IPTC headline 657 * @since 15219 658 */ 659 @Override 660 public String getIptcHeadline() { 661 return iptcHeadline; 662 } 663 664 /** 665 * Returns the IPTC keywords. 666 * @return the IPTC keywords 667 * @since 15219 668 */ 669 @Override 670 public List<String> getIptcKeywords() { 671 return iptcKeywords; 672 } 673 674 /** 675 * Returns the IPTC object name. 676 * @return the IPTC object name 677 * @since 15219 678 */ 679 @Override 680 public String getIptcObjectName() { 681 return iptcObjectName; 682 } 683 684 @Override 685 public int compareTo(GpxImageEntry image) { 686 if (exifTime != null && image.exifTime != null) 687 return exifTime.compareTo(image.exifTime); 688 else if (exifTime == null && image.exifTime == null) 689 return 0; 690 else if (exifTime == null) 691 return -1; 692 else 693 return 1; 694 } 695 696 @Override 697 public int hashCode() { 698 return Objects.hash(height, width, isNewGpsData, 699 elevation, exifCoor, exifGpsTime, exifImgDir, exifGpsTrack, exifHPosErr, 700 exifGpsDop, gpsDiffMode, gps2d3dMode, exifGpsDatum, exifGpsProcMethod, 701 exifOrientation, exifTime, iptcCaption, iptcHeadline, iptcKeywords, 702 iptcObjectName, file, gpsTime, pos, speed, tmp, cameraProjection); 703 } 704 705 @Override 706 public boolean equals(Object obj) { 707 if (this == obj) 708 return true; 709 if (obj == null || getClass() != obj.getClass()) 710 return false; 711 GpxImageEntry other = (GpxImageEntry) obj; 712 return height == other.height 713 && width == other.width 714 && isNewGpsData == other.isNewGpsData 715 && Objects.equals(elevation, other.elevation) 716 && Objects.equals(exifCoor, other.exifCoor) 717 && Objects.equals(exifGpsTime, other.exifGpsTime) 718 && Objects.equals(exifImgDir, other.exifImgDir) 719 && Objects.equals(exifGpsTrack, other.exifGpsTrack) 720 && Objects.equals(exifHPosErr, other.exifHPosErr) 721 && Objects.equals(gpsDiffMode, other.gpsDiffMode) 722 && Objects.equals(gps2d3dMode, other.gps2d3dMode) 723 && Objects.equals(exifGpsDop, other.exifGpsDop) 724 && Objects.equals(exifGpsDatum, other.exifGpsDatum) 725 && Objects.equals(exifGpsProcMethod, other.exifGpsProcMethod) 726 && Objects.equals(exifOrientation, other.exifOrientation) 727 && Objects.equals(exifTime, other.exifTime) 728 && Objects.equals(iptcCaption, other.iptcCaption) 729 && Objects.equals(iptcHeadline, other.iptcHeadline) 730 && Objects.equals(iptcKeywords, other.iptcKeywords) 731 && Objects.equals(iptcObjectName, other.iptcObjectName) 732 && Objects.equals(file, other.file) 733 && Objects.equals(gpsTime, other.gpsTime) 734 && Objects.equals(pos, other.pos) 735 && Objects.equals(speed, other.speed) 736 && Objects.equals(tmp, other.tmp) 737 && cameraProjection == other.cameraProjection; 738 } 739 740 /** 741 * Make a fresh copy and save it in the temporary variable. Use 742 * {@link #applyTmp()} or {@link #discardTmp()} if the temporary variable 743 * is not needed anymore. 744 * @return the fresh copy. 745 */ 746 public GpxImageEntry createTmp() { 747 tmp = new GpxImageEntry(this); 748 tmp.tmp = null; 749 return tmp; 750 } 751 752 /** 753 * Get temporary variable that is used for real time parameter 754 * adjustments. The temporary variable is created if it does not exist 755 * yet. Use {@link #applyTmp()} or {@link #discardTmp()} if the temporary 756 * variable is not needed anymore. 757 * @return temporary variable 758 */ 759 public GpxImageEntry getTmp() { 760 if (tmp == null) { 761 createTmp(); 762 } 763 return tmp; 764 } 765 766 /** 767 * Copy the values from the temporary variable to the main instance. The 768 * temporary variable is deleted. 769 * @see #discardTmp() 770 * @since 19387 exifGpsTrack, exifHPosErr, gpsDiffMode, gps2d3dMode, exifGpsDop, exifGpsDatum, exifGpsProcMethod added 771 */ 772 public void applyTmp() { 773 if (tmp != null) { 774 pos = tmp.pos; 775 speed = tmp.speed; 776 elevation = tmp.elevation; 777 gpsTime = tmp.gpsTime; 778 exifImgDir = tmp.exifImgDir; 779 exifGpsTrack = tmp.exifGpsTrack; 780 exifHPosErr = tmp.exifHPosErr; 781 gpsDiffMode = tmp.gpsDiffMode; 782 gps2d3dMode = tmp.gps2d3dMode; 783 exifGpsDop = tmp.exifGpsDop; 784 exifGpsDatum = tmp.exifGpsDatum; 785 exifGpsProcMethod = tmp.exifGpsProcMethod; 786 isNewGpsData = isNewGpsData || tmp.isNewGpsData; 787 tmp = null; 788 } 789 tmpUpdated(); 790 } 791 792 /** 793 * Delete the temporary variable. Temporary modifications are lost. 794 * @see #applyTmp() 795 */ 796 public void discardTmp() { 797 tmp = null; 798 tmpUpdated(); 799 } 800 801 /** 802 * If it has been tagged i.e. matched to a gpx track or retrieved lat/lon from exif 803 * @return {@code true} if it has been tagged 804 */ 805 public boolean isTagged() { 806 return pos != null; 807 } 808 809 /** 810 * String representation. (only partial info) 811 */ 812 @Override 813 public String toString() { 814 return file.getName()+": "+ 815 "pos = "+pos+" | "+ 816 "exifCoor = "+exifCoor+" | "+ 817 (tmp == null ? " tmp==null" : 818 " [tmp] pos = "+tmp.pos); 819 } 820 821 /** 822 * Indicates that the image has new GPS data. 823 * That flag is set by new GPS data providers. It is used e.g. by the photo_geotagging plugin 824 * to decide for which image file the EXIF GPS data needs to be (re-)written. 825 * @since 6392 826 */ 827 public void flagNewGpsData() { 828 isNewGpsData = true; 829 } 830 831 /** 832 * Indicate that the temporary copy has been updated. Mostly used to prevent UI issues. 833 * By default, this is a no-op. Override when needed in subclasses. 834 * @since 17579 835 */ 836 protected void tmpUpdated() { 837 // No-op by default 838 } 839 840 @Override 841 public BBox getBBox() { 842 // new BBox(LatLon) is null safe. 843 // Use `getPos` instead of `getExifCoor` since the image may be correlated against a GPX track 844 return new BBox(this.getPos()); 845 } 846 847 /** 848 * Remove the flag that indicates new GPS data. 849 * The flag is cleared by a new GPS data consumer. 850 */ 851 public void unflagNewGpsData() { 852 isNewGpsData = false; 853 } 854 855 /** 856 * Queries whether the GPS data changed. The flag value from the temporary 857 * copy is returned if that copy exists. 858 * @return {@code true} if GPS data changed, {@code false} otherwise 859 * @since 6392 860 */ 861 public boolean hasNewGpsData() { 862 if (tmp != null) 863 return tmp.isNewGpsData; 864 return isNewGpsData; 865 } 866 867 /** 868 * Extract GPS metadata from image EXIF. Has no effect if the image file is not set 869 * 870 * If successful, fills in the LatLon, speed, elevation, image direction, and other attributes 871 * @since 9270 872 */ 873 @Override 874 public void extractExif() { 875 ImageMetadata.super.extractExif(); 876 } 877 878 @Override 879 public InputStream getInputStream() throws IOException { 880 return Files.newInputStream(this.getFile().toPath()); 881 } 882 883 /** 884 * Reads the image represented by this entry in the given target dimension. 885 * @param target the desired dimension used for {@linkplain IIOParam#setSourceSubsampling subsampling} or {@code null} 886 * @return the read image, or {@code null} 887 * @throws IOException if any I/O error occurs 888 * @since 18246 889 */ 890 public BufferedImage read(Dimension target) throws IOException { 891 throw new UnsupportedOperationException("read not implemented for " + this.getClass().getSimpleName()); 892 } 893 894 /** 895 * Get the projection type for this entry 896 * @return The projection type 897 * @since 18246 898 */ 899 @Override 900 public Projections getProjectionType() { 901 return this.cameraProjection; 902 } 903 904 @Override 905 public void setProjectionType(Projections newProjection) { 906 this.cameraProjection = newProjection; 907 } 908 909 /** 910 * Returns a {@link WayPoint} representation of this GPX image entry. 911 * @return a {@code WayPoint} representation of this GPX image entry (containing position, instant and elevation) 912 * @since 18065 913 */ 914 public WayPoint asWayPoint() { 915 CachedLatLon position = getPos(); 916 WayPoint wpt = null; 917 if (position != null) { 918 wpt = new WayPoint(position); 919 wpt.setInstant(exifTime); 920 Double ele = getElevation(); 921 if (ele != null) { 922 wpt.put(GpxConstants.PT_ELE, ele.toString()); 923 } 924 } 925 return wpt; 926 } 927}