Highlight possibly-conflicting (nearby) addresses in yellow
This commit is contained in:
@@ -27,6 +27,9 @@ import warnings
|
||||
warnings.filterwarnings('ignore')
|
||||
|
||||
|
||||
CONFLICT_RADIUS_METERS = 5.0
|
||||
|
||||
|
||||
class AddressComparator:
|
||||
def __init__(self, tolerance_meters: float = 500.0):
|
||||
self.tolerance_meters = tolerance_meters
|
||||
@@ -62,6 +65,27 @@ class AddressComparator:
|
||||
s = re.sub(r'\s+', ' ', s).strip()
|
||||
return s
|
||||
|
||||
@staticmethod
|
||||
def _flag_close_conflicts(addresses: List[Dict], radius_meters: float = CONFLICT_RADIUS_METERS) -> None:
|
||||
"""Mark each address dict's 'conflict' key True when another point in the
|
||||
same list falls within radius_meters. Doesn't dedupe or exclude anything -
|
||||
just surfaces tight clusters (e.g. ambiguous source data reusing the same
|
||||
unit label across distinct points) for manual review in the map UI."""
|
||||
if not addresses:
|
||||
return
|
||||
geoms = [a['geometry'] for a in addresses]
|
||||
tree = STRtree(geoms)
|
||||
radius_deg = radius_meters / 111000.0
|
||||
for i, addr in enumerate(addresses):
|
||||
conflict = False
|
||||
for j in tree.query(geoms[i].buffer(radius_deg)):
|
||||
if j == i:
|
||||
continue
|
||||
if geoms[i].distance(geoms[j]) * 111000.0 <= radius_meters:
|
||||
conflict = True
|
||||
break
|
||||
addr['conflict'] = conflict
|
||||
|
||||
def compare_addresses(self, local_file: str, osm_file: str) -> Tuple[List[Dict], List[Dict], List[Dict]]:
|
||||
"""Compare local and OSM address data.
|
||||
|
||||
@@ -175,6 +199,8 @@ class AddressComparator:
|
||||
props['status'] = 'removed'
|
||||
removed_addresses.append({'geometry': osm_row.geometry, **props})
|
||||
|
||||
self._flag_close_conflicts(new_addresses)
|
||||
|
||||
return new_addresses, existing_addresses, removed_addresses
|
||||
|
||||
def save_results(self, new_addresses, existing_addresses, removed_addresses, output_dir):
|
||||
|
||||
Reference in New Issue
Block a user