Changeset 15043 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2019-05-03T23:47:54+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java
r14914 r15043 8 8 import java.util.Arrays; 9 9 import java.util.Collection; 10 import java.util.Collections; 10 11 import java.util.HashMap; 11 12 import java.util.HashSet; … … 62 63 protected static final String ADDR_PLACE = "addr:place"; 63 64 protected static final String ADDR_STREET = "addr:street"; 65 protected static final String ADDR_SUBURB = "addr:suburb"; 64 66 protected static final String ADDR_CITY = "addr:city"; 65 67 protected static final String ADDR_UNIT = "addr:unit"; … … 72 74 private Map<String, Collection<OsmPrimitive>> knownAddresses; 73 75 private Set<String> ignoredAddresses; 74 75 76 76 77 /** … … 104 105 } 105 106 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) { 108 113 // Find house number without proper location 109 114 // (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; 125 127 } 126 128 … … 177 179 } 178 180 179 protected voidcheckForDuplicate(OsmPrimitive p) {181 protected List<TestError> checkForDuplicate(OsmPrimitive p) { 180 182 if (knownAddresses == null) { 181 183 initAddressMap(p); 182 184 } 183 185 if (!isPOI(p) && hasAddress(p)) { 186 List<TestError> result = new ArrayList<>(); 184 187 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)) { 189 189 double maxDistance = MAX_DUPLICATE_DISTANCE.get(); 190 190 for (OsmPrimitive p2 : knownAddresses.get(simplifiedAddress)) { … … 198 198 if (city1 != null && city2 != null) { 199 199 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)))) { 201 202 severityLevel = Severity.WARNING; 202 203 } else { 203 // address including city identical but postcode differs204 // address including city identical but postcode or suburb differs 204 205 // most likely perfectly fine 205 206 severityLevel = Severity.OTHER; … … 228 229 } 229 230 } 230 errors.add(TestError.builder(this, severityLevel, DUPLICATE_HOUSE_NUMBER)231 result.add(TestError.builder(this, severityLevel, DUPLICATE_HOUSE_NUMBER) 231 232 .message(tr("Duplicate house numbers"), marktr("''{0}'' ({1}m)"), simplifiedAddress, (int) distance) 232 233 .primitives(Arrays.asList(p, p2)).build()); … … 234 235 knownAddresses.get(simplifiedAddress).remove(p); // otherwise we would get every warning two times 235 236 } 236 } 237 errors.addAll(result); 238 return result; 239 } 240 return Collections.emptyList(); 237 241 } 238 242
Note:
See TracChangeset
for help on using the changeset viewer.