Ignore:
Timestamp:
2010-11-02T20:43:02+01:00 (14 years ago)
Author:
oliverw
Message:

Several bugfixes/perf improvements relating guesses.

Location:
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressEditContainer.java

    r24026 r24028  
    8989        private List<AddressNode> shadowIncompleteAddresses = new ArrayList<AddressNode>(100);
    9090       
    91         /** The visited nodes cache to increase iteration spped. */
     91        /** The visited nodes cache to increase iteration speed. */
    9292        private HashSet<Node> visitedNodes = new HashSet<Node>();
    93         /** The visited ways cache to increase iteration spped. */
     93        /** The visited ways cache to increase iteration speed. */
    9494        private HashSet<Way> visitedWays = new HashSet<Way>(); 
    9595        /** The tag list used within the data area. */
    9696        private HashSet<String> tags = new HashSet<String>();
     97        /** The tag list used within the data area. */
     98        private HashMap<String, String> values = new HashMap<String, String>();
    9799       
    98100        /** The change listeners. */
     
    241243                        // Assignment failed: Street is not known (yet) -> add to 'unresolved' list
    242244                        shadowUnresolvedAddresses.add(aNode);
    243                        
    244                         if ("BaDaubringen".equals(aNode.getCity())) {
    245                                 @SuppressWarnings("unused")
    246                                 int x = 0;
    247                         }
    248245                }
    249246
    250247                if (!aNode.isComplete()) {
    251248                        shadowIncompleteAddresses.add(aNode);
    252                        
    253                         if ("BaDaubringen".equals(aNode.getCity())) {
    254                                 @SuppressWarnings("unused")
    255                                 int x = 0;
    256                         }
    257249                }
    258250        }
     
    276268                                if (!tags.contains(key)) {
    277269                                        tags.add(key);
     270                                }
     271                               
     272                                String v = w.get(key);
     273                                if (!values.containsKey(v)) {
     274                                        values.put(v, key);
    278275                                }
    279276                        }
     
    395392                return tags;
    396393        }
    397        
     394               
     395        /**
     396         * @return the values
     397         */
     398        protected HashMap<String, String> getValues() {
     399                return values;
     400        }
     401
    398402        /**
    399403         * Gets the number of streets in the container.
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressFinderThread.java

    r24023 r24028  
    211211                                        // guess values
    212212                                        for (int i = 0; i < guessers.length; i++) {
     213                                                if (!guessers[i].needsGuess()) continue;
     214                                               
    213215                                                osmPrimitive.visit(guessers[i]);
     216                                               
     217                                                if (guessers[i].currentValue == null && i == 0) {
     218                                                        System.err.println("Guess #" + i + " failed for " + aNode);
     219                                                }
    214220                                        }
    215221                                }
     
    243249                @Override
    244250                public void visit(Way w) {                     
    245                         if (TagUtils.hasHighwayTag(w)) {
     251                        if (TagUtils.isStreetSupportingHousenumbers(w)) {
    246252                                AddressNode aNode = getAddressNode();
    247253                                double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w);
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressNode.java

    r24026 r24028  
    342342         * has either no street name, post code or city.
    343343         *
     344         * @return true, if this instance needs at least one guessed value.
     345         */
     346        public boolean needsGuess() {
     347                return  needsGuessedValue(TagUtils.ADDR_CITY_TAG) ||
     348                                needsGuessedValue(TagUtils.ADDR_POSTCODE_TAG) ||
     349                                needsGuessedValue(TagUtils.ADDR_STREET_TAG);
     350        }
     351       
     352        /**
     353         * Check if this instance needs guessed value for a given tag.
    344354         * @return true, if successful
    345355         */
    346         public boolean needsGuess() {
    347                 return !hasStreetName() || !hasCity() || !hasPostCode();
     356        public boolean needsGuessedValue(String tag) {
     357                return MISSING_TAG.equals(getTagValueWithGuess(tag));
    348358        }
    349359       
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/FixUnresolvedStreetsAction.java

    r23981 r24028  
    4040               
    4141                addressEditContainer = new AddressEditContainer();
     42                               
    4243                DataSet.addSelectionListener(this);             
    4344        }
     
    6061                        addressEditContainer.attachToDataSet(newSelection);
    6162                        try {
     63                                //generateTagCode(addressEditContainer);
    6264                                AddressEditDialog dlg = new AddressEditDialog(addressEditContainer);
    6365                                dlg.setVisible(true);
     
    111113                                        .toUpperCase().replaceAll(":", "_"), tag));
    112114                }
     115                               
     116                for (String value : addrVisitor.getValues().keySet()) {
     117                        String tag = addrVisitor.getValues().get(value);
     118                       
     119                        String tags = tag.toUpperCase().replaceAll(":", "_");
     120                        String values = value.toUpperCase().replaceAll(":", "_");
     121                        System.out.println(String.format(
     122                                        "public static final String %s_%s_VALUE = \"%s\";", tags, values
     123                                        , value));
     124                }
    113125        }
    114126
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/GuessedValueHandler.java

    r24018 r24028  
    123123        }
    124124       
     125        /**
     126         * Check if we need to visit the OSM data
     127         *
     128         * @return true, if successful
     129         */
     130        public boolean needsGuess() {
     131                return aNode.needsGuessedValue(tag);
     132        }
     133       
    125134        /* (non-Javadoc)
    126135         * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Node)
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OsmUtils.java

    r24023 r24028  
    7272                double min = Math.min(Math.min(ac, mc), bc);
    7373               
     74                               
    7475                if (min < 5.0) { // close enough?
    7576                        return min;
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/TagUtils.java

    r24023 r24028  
    1717import org.openstreetmap.josm.data.osm.Relation;
    1818import org.openstreetmap.josm.data.osm.RelationMember;
     19import org.openstreetmap.josm.data.osm.Way;
    1920
    2021/**
     
    18771878        public static String getEmbankmentValue(OsmPrimitive osmPrimitive) {
    18781879                return osmPrimitive != null ? osmPrimitive.get(EMBANKMENT_TAG) : null;
     1880        }
     1881       
     1882        /**
     1883         * Checks if the given street supporting housenumbers. Usually motor ways and primary roads have
     1884         * no addresses, also no paths or tracks.
     1885         *
     1886         * @param w the w
     1887         * @return true, if is street supporting housenumbers
     1888         */
     1889        public static boolean isStreetSupportingHousenumbers(Way w) {
     1890                if (w == null) return false;
     1891                if (!hasHighwayTag(w)) {
     1892                        return false;
     1893                }
     1894               
     1895                // TODO: Should be configurable
     1896                String hwType = getHighwayValue(w);
     1897                               
     1898                return  HIGHWAY_RESIDENTIAL_VALUE.equals(hwType) ||
     1899                                HIGHWAY_SECONDARY_VALUE.equals(hwType) ||
     1900                                HIGHWAY_TERTIARY_VALUE.equals(hwType) ||
     1901                                HIGHWAY_LIVING_STREET_VALUE.equals(hwType) ||
     1902                                HIGHWAY_UNCLASSIFIED_VALUE.equals(hwType);
    18791903        }
    18801904       
     
    20052029        public static final String ADDR_HOUSENAME_TAG = "addr:housename";
    20062030       
     2031        /* Highway types */
     2032        public static final String HIGHWAY_CYCLEWAY_VALUE = "cycleway";
     2033        public static final String HIGHWAY_FOOTWAY_VALUE = "footway";
     2034        public static final String HIGHWAY_MOTORWAY_LINK_VALUE = "motorway_link";
     2035        public static final String HIGHWAY_MOTORWAY_VALUE = "motorway";
     2036        public static final String HIGHWAY_PATH_VALUE = "path";
     2037        public static final String HIGHWAY_RESIDENTIAL_VALUE = "residential";
     2038        public static final String HIGHWAY_LIVING_STREET_VALUE = "living_street";
     2039        public static final String HIGHWAY_ROAD_VALUE = "road";
     2040        public static final String HIGHWAY_SECONDARY_VALUE = "secondary";
     2041        public static final String HIGHWAY_SERVICE_VALUE = "service";
     2042        public static final String HIGHWAY_STEPS_VALUE = "steps";
     2043        public static final String HIGHWAY_TERTIARY_VALUE = "tertiary";
     2044        public static final String HIGHWAY_TRACK_VALUE = "track";
     2045        public static final String HIGHWAY_TRUNK_LINK_VALUE = "trunk_link";
     2046        public static final String HIGHWAY_TRUNK_VALUE = "trunk";
     2047        public static final String HIGHWAY_UNCLASSIFIED_VALUE = "unclassified";
     2048
    20072049        /* Relation keys */
    20082050       
Note: See TracChangeset for help on using the changeset viewer.