Ignore:
Timestamp:
2014-11-12T02:37:22+01:00 (10 years ago)
Author:
donvip
Message:

[josm_opendata] fix #josm10473 - detect duplicated ways during SHP import

Location:
applications/editors/josm/plugins/opendata
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/build.xml

    r30748 r30796  
    11<?xml version="1.0" encoding="utf-8"?>
    22<project name="opendata" default="dist" basedir=".">
    3     <property name="plugin.main.version" value="7371"/>
     3    <property name="plugin.main.version" value="7721"/>
    44    <property name="plugin.author" value="Don-vip"/>
    55    <property name="plugin.class" value="org.openstreetmap.josm.plugins.opendata.OdPlugin"/>
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/GeographicReader.java

    r30795 r30796  
    99import java.util.ArrayList;
    1010import java.util.Arrays;
     11import java.util.Collections;
    1112import java.util.HashMap;
    1213import java.util.List;
     
    4344import org.openstreetmap.josm.data.osm.RelationMember;
    4445import org.openstreetmap.josm.data.osm.Way;
     46import org.openstreetmap.josm.data.validation.tests.DuplicateWay;
    4547import org.openstreetmap.josm.gui.ExtendedDialog;
    4648import org.openstreetmap.josm.io.AbstractReader;
     
    116118    }
    117119   
    118         protected Node createOrGetEmptyNode(Point p) throws MismatchedDimensionException, TransformException {
    119                 Point p2 = (Point) JTS.transform(p, transform);
    120                 LatLon key = new LatLon(p2.getY(), p2.getX());
    121                 Node n = getNode(p2, key);
    122                 if(n != null && n.hasKeys()) {
    123                         n = null;
    124                 }
    125                 if (n == null) {
    126                         n = new Node(key);
    127                         if (handler == null || handler.useNodeMap()) {
    128                                 nodes.put(key, n);
    129                         }
    130                         ds.addPrimitive(n);
    131                 } else if (n.getDataSet() == null) {
    132                     // handler may have removed the node from DataSet (see Paris public light handler for example)
    133                     ds.addPrimitive(n);
    134                 }
    135                 return n;
    136         }
     120    protected Node createOrGetEmptyNode(Point p) throws MismatchedDimensionException, TransformException {
     121        Point p2 = (Point) JTS.transform(p, transform);
     122        LatLon key = new LatLon(p2.getY(), p2.getX());
     123        Node n = getNode(p2, key);
     124        if (n != null && n.hasKeys()) {
     125            n = null;
     126        }
     127        if (n == null) {
     128            n = new Node(key);
     129            if (handler == null || handler.useNodeMap()) {
     130                nodes.put(key, n);
     131            }
     132            ds.addPrimitive(n);
     133        } else if (n.getDataSet() == null) {
     134            // handler may have removed the node from DataSet (see Paris public light handler for example)
     135            ds.addPrimitive(n);
     136        }
     137        return n;
     138    }
    137139       
    138140    protected <T extends OsmPrimitive> T addOsmPrimitive(T p) {
     
    145147    }
    146148
    147     protected final Way createWay(LineString ls) {
    148         Way w = createWay();
     149    protected final Way createOrGetWay(LineString ls) {
     150        Way w = null;
     151        Way tempWay = new Way();
    149152        if (ls != null) {
     153            // Build list of nodes
    150154            for (int i=0; i<ls.getNumPoints(); i++) {
    151155                try {
    152                     w.addNode(createOrGetNode(ls.getPointN(i)));
     156                    tempWay.addNode(createOrGetNode(ls.getPointN(i)));
    153157                } catch (Exception e) {
    154158                    Main.error(e.getMessage());
    155159                }
    156160            }
     161            // Find possible duplicated ways
     162            if (tempWay.getNodesCount() > 0) {
     163                List<Way> candidates = OsmPrimitive.getFilteredList(tempWay.firstNode().getReferrers(), Way.class);
     164                candidates.remove(tempWay);
     165                List<LatLon> tempNodes = DuplicateWay.getOrderedNodes(tempWay);
     166                for (Way candidate : candidates) {
     167                    List<LatLon> candNodesA = DuplicateWay.getOrderedNodes(candidate);
     168                    List<LatLon> candNodesB = new ArrayList<>(candNodesA);
     169                    Collections.reverse(candNodesB);
     170                    if (tempNodes.equals(candNodesA) || tempNodes.equals(candNodesB)) {
     171                        w = candidate;
     172                        break;
     173                    }
     174                }
     175            }
     176        }
     177        // If no duplicate way found, create new one
     178        if (w == null) {
     179            w = createWay();
     180            w.setNodes(tempWay.getNodes());
    157181        }
    158182        return w;
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/geographic/ShpReader.java

    r30795 r30796  
    138138                                r = createMultipolygon();
    139139                            }
    140                             w = createWay(p.getExteriorRing());
     140                            w = createOrGetWay(p.getExteriorRing());
    141141                            if (r != null) {
    142142                                addWayToMp(r, "outer", w);
    143143                                for (int j=0; j<p.getNumInteriorRing(); j++) {
    144                                     addWayToMp(r, "inner", createWay(p.getInteriorRingN(j)));
     144                                    addWayToMp(r, "inner", createOrGetWay(p.getInteriorRingN(j)));
    145145                                }
    146146                            }
    147147                        } else if (g instanceof LineString) {
    148                             w = createWay((LineString) g);
     148                            w = createOrGetWay((LineString) g);
    149149                        } else if (g instanceof Point) {
    150150                            // Some belgian data sets hold points into collections ?!
Note: See TracChangeset for help on using the changeset viewer.