Changeset 15043 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2019-05-03T23:47:54+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #17674 - use addr:suburb to distinguish similar addresses in the same city, like addr:postcode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java

    r14914 r15043  
    88import java.util.Arrays;
    99import java.util.Collection;
     10import java.util.Collections;
    1011import java.util.HashMap;
    1112import java.util.HashSet;
     
    6263    protected static final String ADDR_PLACE         = "addr:place";
    6364    protected static final String ADDR_STREET        = "addr:street";
     65    protected static final String ADDR_SUBURB        = "addr:suburb";
    6466    protected static final String ADDR_CITY          = "addr:city";
    6567    protected static final String ADDR_UNIT          = "addr:unit";
     
    7274    private Map<String, Collection<OsmPrimitive>> knownAddresses;
    7375    private Set<String> ignoredAddresses;
    74 
    7576
    7677    /**
     
    104105    }
    105106
    106     protected void checkHouseNumbersWithoutStreet(OsmPrimitive p) {
    107         List<Relation> associatedStreets = getAndCheckAssociatedStreets(p);
     107    /**
     108     * Checks for house numbers for which the street is unknown.
     109     * @param p primitive to test
     110     * @return error found, or null
     111     */
     112    protected TestError checkHouseNumbersWithoutStreet(OsmPrimitive p) {
    108113        // Find house number without proper location
    109114        // (neither addr:street, associatedStreet, addr:place, addr:neighbourhood or addr:interpolation)
    110         if (p.hasKey(ADDR_HOUSE_NUMBER) && !p.hasKey(ADDR_STREET, ADDR_PLACE, ADDR_NEIGHBOURHOOD)) {
    111             for (Relation r : associatedStreets) {
    112                 if (r.hasTag("type", ASSOCIATED_STREET)) {
    113                     return;
    114                 }
    115             }
    116             if (p.referrers(Way.class).anyMatch(w -> w.hasKey(ADDR_INTERPOLATION) && w.hasKey(ADDR_STREET))) {
    117                 return;
    118             }
    119             // No street found
    120             errors.add(TestError.builder(this, Severity.WARNING, HOUSE_NUMBER_WITHOUT_STREET)
    121                     .message(tr("House number without street"))
    122                     .primitives(p)
    123                     .build());
    124         }
     115        if (p.hasKey(ADDR_HOUSE_NUMBER) && !p.hasKey(ADDR_STREET, ADDR_PLACE, ADDR_NEIGHBOURHOOD)
     116            && getAndCheckAssociatedStreets(p).isEmpty()
     117            && p.referrers(Way.class).noneMatch(w -> w.hasKey(ADDR_INTERPOLATION) && w.hasKey(ADDR_STREET))) {
     118            // no street found
     119            TestError e = TestError.builder(this, Severity.WARNING, HOUSE_NUMBER_WITHOUT_STREET)
     120                .message(tr("House number without street"))
     121                .primitives(p)
     122                .build();
     123            errors.add(e);
     124            return e;
     125        }
     126        return null;
    125127    }
    126128
     
    177179    }
    178180
    179     protected void checkForDuplicate(OsmPrimitive p) {
     181    protected List<TestError> checkForDuplicate(OsmPrimitive p) {
    180182        if (knownAddresses == null) {
    181183            initAddressMap(p);
    182184        }
    183185        if (!isPOI(p) && hasAddress(p)) {
     186            List<TestError> result = new ArrayList<>();
    184187            String simplifiedAddress = getSimplifiedAddress(p);
    185             if (ignoredAddresses.contains(simplifiedAddress)) {
    186                 return;
    187             }
    188             if (knownAddresses.containsKey(simplifiedAddress)) {
     188            if (!ignoredAddresses.contains(simplifiedAddress) && knownAddresses.containsKey(simplifiedAddress)) {
    189189                double maxDistance = MAX_DUPLICATE_DISTANCE.get();
    190190                for (OsmPrimitive p2 : knownAddresses.get(simplifiedAddress)) {
     
    198198                    if (city1 != null && city2 != null) {
    199199                        if (city1.equals(city2)) {
    200                             if (!p.hasKey(ADDR_POSTCODE) || !p2.hasKey(ADDR_POSTCODE) || p.get(ADDR_POSTCODE).equals(p2.get(ADDR_POSTCODE))) {
     200                            if ((!p.hasKey(ADDR_POSTCODE) || !p2.hasKey(ADDR_POSTCODE) || p.get(ADDR_POSTCODE).equals(p2.get(ADDR_POSTCODE)))
     201                             && (!p.hasKey(ADDR_SUBURB) || !p2.hasKey(ADDR_SUBURB) || p.get(ADDR_SUBURB).equals(p2.get(ADDR_SUBURB)))) {
    201202                                severityLevel = Severity.WARNING;
    202203                            } else {
    203                                 // address including city identical but postcode differs
     204                                // address including city identical but postcode or suburb differs
    204205                                // most likely perfectly fine
    205206                                severityLevel = Severity.OTHER;
     
    228229                        }
    229230                    }
    230                     errors.add(TestError.builder(this, severityLevel, DUPLICATE_HOUSE_NUMBER)
     231                    result.add(TestError.builder(this, severityLevel, DUPLICATE_HOUSE_NUMBER)
    231232                            .message(tr("Duplicate house numbers"), marktr("''{0}'' ({1}m)"), simplifiedAddress, (int) distance)
    232233                            .primitives(Arrays.asList(p, p2)).build());
     
    234235                knownAddresses.get(simplifiedAddress).remove(p); // otherwise we would get every warning two times
    235236            }
    236         }
     237            errors.addAll(result);
     238            return result;
     239        }
     240        return Collections.emptyList();
    237241    }
    238242
Note: See TracChangeset for help on using the changeset viewer.