Changeset 8807 in josm for trunk/src/org


Ignore:
Timestamp:
2015-09-29T21:17:43+02:00 (9 years ago)
Author:
simon04
Message:

fix #8110 - Conversion gpx -> osm -> gpx now retains order of segments (<trkseg>)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r8805 r8807  
    6363import org.openstreetmap.josm.data.osm.Node;
    6464import org.openstreetmap.josm.data.osm.OsmPrimitive;
     65import org.openstreetmap.josm.data.osm.OsmPrimitiveComparator;
    6566import org.openstreetmap.josm.data.osm.Relation;
    6667import org.openstreetmap.josm.data.osm.Way;
     
    560561
    561562    private static void waysToGpxData(Collection<Way> ways, GpxData gpxData, Set<Node> doneNodes) {
    562         for (Way w : ways) {
     563        /* When the dataset has been obtained from a gpx layer and now is being converted back,
     564         * the ways have negative ids. The first created way corresponds to the first gpx segment,
     565         * and has the highest id (i.e., closest to zero).
     566         * Thus, sorting by OsmPrimitive#getUniqueId gives the original order.
     567         * (Only works if the data layer has not been saved to and been loaded from an osm file before.)
     568         */
     569        final List<Way> sortedWays = new ArrayList<>(ways);
     570        Collections.sort(sortedWays, new OsmPrimitiveComparator(true, false)); // sort by OsmPrimitive#getUniqueId ascending
     571        Collections.reverse(sortedWays); // sort by OsmPrimitive#getUniqueId descending
     572        for (Way w : sortedWays) {
    563573            if (!w.isUsable()) {
    564574                continue;
Note: See TracChangeset for help on using the changeset viewer.