Changeset 13775 in osm for applications/editors/josm/plugins/agpifoj/src
- Timestamp:
- 2009-02-17T16:59:56+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/CorrelateGpxWithImages.java
r13497 r13775 572 572 if (deltaText.length() > 0) { 573 573 try { 574 if(deltaText.startsWith("+")) 575 deltaText = deltaText.substring(1); 574 576 delta = Long.parseLong(deltaText); 575 577 } catch(NumberFormatException nfe) { … … 692 694 693 695 private int matchPoints(ArrayList<ImageEntry> dateImgLst, WayPoint prevWp, long prevDateWp, WayPoint curWp, long curDateWp) { 696 int interval = prevDateWp > 0 ? ((int)Math.abs(curDateWp - prevDateWp))/2 : 500; 694 697 int ret = 0; 695 int i = getLastIndexOfListBefore(dateImgLst, curDateWp );696 if (i >= 0 && i < dateImgLst.size() && dateImgLst.get(i).time.getTime() > prevDateWp) {698 int i = getLastIndexOfListBefore(dateImgLst, curDateWp, interval); 699 if (i >= 0 && i < dateImgLst.size() && dateImgLst.get(i).time.getTime()+interval > prevDateWp) { 697 700 Double speed = null; 698 701 Double prevElevation = null; … … 703 706 try { 704 707 prevElevation = new Double((String) prevWp.attr.get("ele")); 705 } catch(Exception e) { 706 } 708 } catch(Exception e) {} 707 709 } 708 710 try { 709 711 curElevation = new Double((String) curWp.attr.get("ele")); 710 } catch (Exception e) { 711 } 712 713 while(i >= 0714 && dateImgLst.get(i).time.getTime() == curDateWp) {715 dateImgLst.get(i).pos = curWp.eastNorth;716 dateImgLst.get(i).coor = Main.proj.eastNorth2latlon(dateImgLst.get(i).pos);717 dateImgLst.get(i).speed = speed;718 dateImgLst.get(i).elevation = curElevation;719 ret++;712 } catch (Exception e) {} 713 714 while(i >= 0 && inRadius(dateImgLst.get(i).time.getTime(), curDateWp, interval)) { 715 if(dateImgLst.get(i).coor == null) { 716 dateImgLst.get(i).pos = curWp.eastNorth; 717 dateImgLst.get(i).coor = Main.proj.eastNorth2latlon(dateImgLst.get(i).pos); 718 dateImgLst.get(i).speed = speed; 719 dateImgLst.get(i).elevation = curElevation; 720 ret++; 721 } 720 722 i--; 721 723 } … … 725 727 while(i >= 0 726 728 && (imgDate = dateImgLst.get(i).time.getTime()) > prevDateWp) { 727 dateImgLst.get(i).pos = new EastNorth( 728 prevWp.eastNorth.east() + ((curWp.eastNorth.east() - prevWp.eastNorth.east()) * (imgDate - prevDateWp)) / (curDateWp - prevDateWp), 729 prevWp.eastNorth.north() + ((curWp.eastNorth.north() - prevWp.eastNorth.north()) * (imgDate - prevDateWp)) / (curDateWp - prevDateWp)); 730 dateImgLst.get(i).coor = Main.proj.eastNorth2latlon(dateImgLst.get(i).pos); 731 dateImgLst.get(i).speed = speed; 732 if (curElevation != null && prevElevation != null) { 733 dateImgLst.get(i).elevation = prevElevation + ((curElevation - prevElevation) * (imgDate - prevDateWp)) / (curDateWp - prevDateWp); 729 if(dateImgLst.get(i).coor == null) { 730 dateImgLst.get(i).pos = new EastNorth( 731 prevWp.eastNorth.east() + ((curWp.eastNorth.east() - prevWp.eastNorth.east()) * (imgDate - prevDateWp)) / (curDateWp - prevDateWp), 732 prevWp.eastNorth.north() + ((curWp.eastNorth.north() - prevWp.eastNorth.north()) * (imgDate - prevDateWp)) / (curDateWp - prevDateWp)); 733 dateImgLst.get(i).coor = Main.proj.eastNorth2latlon(dateImgLst.get(i).pos); 734 dateImgLst.get(i).speed = speed; 735 if (curElevation != null && prevElevation != null) { 736 dateImgLst.get(i).elevation = prevElevation + ((curElevation - prevElevation) * (imgDate - prevDateWp)) / (curDateWp - prevDateWp); 737 } 738 ret++; 734 739 } 735 ret++;736 740 i--; 737 741 } … … 741 745 } 742 746 743 private int getLastIndexOfListBefore(ArrayList<ImageEntry> dateImgLst, long searchedDate ) {747 private int getLastIndexOfListBefore(ArrayList<ImageEntry> dateImgLst, long searchedDate, int interval) { 744 748 int lstSize = dateImgLst.size(); 745 749 if (lstSize == 0 || searchedDate < dateImgLst.get(0).time.getTime()) { 746 750 return -1; 747 } else if (searchedDate > dateImgLst.get(lstSize - 1).time.getTime()) {751 } else if (searchedDate-interval > dateImgLst.get(lstSize - 1).time.getTime()) { 748 752 return lstSize; 749 } else if ( searchedDate == dateImgLst.get(lstSize - 1).time.getTime()) {753 } else if (inRadius(searchedDate, dateImgLst.get(lstSize - 1).time.getTime(), interval)) { 750 754 return lstSize - 1; 751 } else if ( searchedDate == dateImgLst.get(0).time.getTime()) {755 } else if (inRadius(searchedDate , dateImgLst.get(0).time.getTime(), interval)) { 752 756 int curIndex = 0; 753 757 while (curIndex + 1 < lstSize 754 && dateImgLst.get(curIndex + 1).time.getTime() == searchedDate) {758 && inRadius(dateImgLst.get(curIndex + 1).time.getTime(), searchedDate, interval)) { 755 759 curIndex++; 756 760 } … … 764 768 curIndex = (endIndex + startIndex) / 2; 765 769 long curDate = dateImgLst.get(curIndex).time.getTime(); 766 if (curDate < searchedDate) {770 if (curDate-interval < searchedDate) { 767 771 startIndex = curIndex; 768 } else if (curDate > searchedDate) {772 } else if (curDate+interval > searchedDate) { 769 773 endIndex = curIndex; 770 774 } else { 771 775 // Check that there is no image _after_ that one that have exactly the same date. 772 776 while (curIndex + 1 < lstSize 773 && dateImgLst.get(curIndex + 1).time.getTime() == searchedDate) {777 && inRadius(dateImgLst.get(curIndex + 1).time.getTime(), searchedDate, interval)) { 774 778 curIndex++; 775 779 } … … 887 891 return ret; 888 892 } 893 894 private boolean inRadius(long time1, long time2, int interval) { 895 return Math.abs(time1 - time2) < interval; 896 } 889 897 }
Note:
See TracChangeset
for help on using the changeset viewer.