Changeset 13775 in osm for applications


Ignore:
Timestamp:
2009-02-17T16:59:56+01:00 (15 years ago)
Author:
stoecker
Message:

close #2124. patch by xeen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/agpifoj/src/org/openstreetmap/josm/plugins/agpifoj/CorrelateGpxWithImages.java

    r13497 r13775  
    572572            if (deltaText.length() > 0) {
    573573                try {
     574                    if(deltaText.startsWith("+"))
     575                        deltaText = deltaText.substring(1);
    574576                    delta = Long.parseLong(deltaText);
    575577                } catch(NumberFormatException nfe) {
     
    692694
    693695    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;
    694697        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) {
    697700            Double speed = null;
    698701            Double prevElevation = null;
     
    703706                try {
    704707                    prevElevation = new Double((String) prevWp.attr.get("ele"));
    705                 } catch(Exception e) {
    706                 }
     708                } catch(Exception e) {}
    707709            }
    708710            try {
    709711                curElevation = new Double((String) curWp.attr.get("ele"));
    710             } catch (Exception e) {
    711             }
    712 
    713             while(i >= 0
    714                     && 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                }
    720722                i--;
    721723            }
     
    725727                while(i >= 0
    726728                        && (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++;
    734739                    }
    735                     ret++;
    736740                    i--;
    737741                }
     
    741745    }
    742746
    743     private int getLastIndexOfListBefore(ArrayList<ImageEntry> dateImgLst, long searchedDate) {
     747    private int getLastIndexOfListBefore(ArrayList<ImageEntry> dateImgLst, long searchedDate, int interval) {
    744748        int lstSize = dateImgLst.size();
    745749        if (lstSize == 0 || searchedDate < dateImgLst.get(0).time.getTime()) {
    746750            return -1;
    747         } else if (searchedDate > dateImgLst.get(lstSize - 1).time.getTime()) {
     751        } else if (searchedDate-interval > dateImgLst.get(lstSize - 1).time.getTime()) {
    748752            return lstSize;
    749         } else if (searchedDate == dateImgLst.get(lstSize - 1).time.getTime()) {
     753        } else if (inRadius(searchedDate, dateImgLst.get(lstSize - 1).time.getTime(), interval)) {
    750754            return lstSize - 1;
    751         } else if (searchedDate == dateImgLst.get(0).time.getTime()) {
     755        } else if (inRadius(searchedDate , dateImgLst.get(0).time.getTime(), interval)) {
    752756            int curIndex = 0;
    753757            while (curIndex + 1 < lstSize
    754                     && dateImgLst.get(curIndex + 1).time.getTime() == searchedDate) {
     758                    && inRadius(dateImgLst.get(curIndex + 1).time.getTime(), searchedDate, interval)) {
    755759                curIndex++;
    756760            }
     
    764768            curIndex = (endIndex + startIndex) / 2;
    765769            long curDate = dateImgLst.get(curIndex).time.getTime();
    766             if (curDate < searchedDate) {
     770            if (curDate-interval < searchedDate) {
    767771                startIndex = curIndex;
    768             } else if (curDate > searchedDate) {
     772            } else if (curDate+interval > searchedDate) {
    769773                endIndex = curIndex;
    770774            } else {
    771775                // Check that there is no image _after_ that one that have exactly the same date.
    772776                while (curIndex + 1 < lstSize
    773                         && dateImgLst.get(curIndex + 1).time.getTime() == searchedDate) {
     777                        && inRadius(dateImgLst.get(curIndex + 1).time.getTime(), searchedDate, interval)) {
    774778                    curIndex++;
    775779                }
     
    887891        return ret;
    888892    }
     893   
     894    private boolean inRadius(long time1, long time2, int interval) {
     895        return Math.abs(time1 - time2) < interval;
     896    }
    889897}
Note: See TracChangeset for help on using the changeset viewer.