Ticket #2124: agpifoj range support.patch
| File agpifoj range support.patch, 4.9 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/plugins/agpifoj/CorrelateGpxWithImages.java
571 571 String deltaText = tfOffset.getText().trim(); 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) { 576 578 JOptionPane.showMessageDialog(Main.parent, tr("Error while parsing offset.\nExpected format: {0}", "number"), … … 691 693 } 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)) : 1000; 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; 699 702 Double curElevation = null; … … 702 705 speed = new Double((1000 * distance) / (curDateWp - prevDateWp)); 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 } catch (Exception e) {} 712 713 713 714 while(i >= 0 714 && dateImgLst.get(i).time.getTime() == curDateWp) {715 && inRadius(dateImgLst.get(i).time.getTime(), curDateWp, interval)) { 715 716 dateImgLst.get(i).pos = curWp.eastNorth; 716 717 dateImgLst.get(i).coor = Main.proj.eastNorth2latlon(dateImgLst.get(i).pos); 717 718 dateImgLst.get(i).speed = speed; … … 740 741 return ret; 741 742 } 742 743 743 private int getLastIndexOfListBefore(ArrayList<ImageEntry> dateImgLst, long searchedDate ) {744 private int getLastIndexOfListBefore(ArrayList<ImageEntry> dateImgLst, long searchedDate, int interval) { 744 745 int lstSize = dateImgLst.size(); 745 746 if (lstSize == 0 || searchedDate < dateImgLst.get(0).time.getTime()) { 746 747 return -1; 747 } else if (searchedDate > dateImgLst.get(lstSize - 1).time.getTime()) {748 } else if (searchedDate-interval > dateImgLst.get(lstSize - 1).time.getTime()) { 748 749 return lstSize; 749 } else if ( searchedDate == dateImgLst.get(lstSize - 1).time.getTime()) {750 } else if (inRadius(searchedDate, dateImgLst.get(lstSize - 1).time.getTime(), interval)) { 750 751 return lstSize - 1; 751 } else if ( searchedDate == dateImgLst.get(0).time.getTime()) {752 } else if (inRadius(searchedDate , dateImgLst.get(0).time.getTime(), interval)) { 752 753 int curIndex = 0; 753 754 while (curIndex + 1 < lstSize 754 && dateImgLst.get(curIndex + 1).time.getTime() == searchedDate) {755 && inRadius(dateImgLst.get(curIndex + 1).time.getTime(), searchedDate, interval)) { 755 756 curIndex++; 756 757 } 757 758 return curIndex; … … 763 764 while (endIndex - startIndex > 1) { 764 765 curIndex = (endIndex + startIndex) / 2; 765 766 long curDate = dateImgLst.get(curIndex).time.getTime(); 766 if (curDate < searchedDate) {767 if (curDate-interval < searchedDate) { 767 768 startIndex = curIndex; 768 } else if (curDate > searchedDate) {769 } else if (curDate+interval > searchedDate) { 769 770 endIndex = curIndex; 770 771 } else { 771 772 // Check that there is no image _after_ that one that have exactly the same date. 772 773 while (curIndex + 1 < lstSize 773 && dateImgLst.get(curIndex + 1).time.getTime() == searchedDate) {774 && inRadius(dateImgLst.get(curIndex + 1).time.getTime(), searchedDate, interval)) { 774 775 curIndex++; 775 776 } 776 777 return curIndex; … … 886 887 * 6372795; // Earth radius, in meters 887 888 return ret; 888 889 } 890 891 private boolean inRadius(long time1, long time2, int interval) { 892 return Math.abs(time1 - time2) < interval; 893 } 889 894 }
