estimate_offset#
- rapidtools.processing.aerial_evidence.estimate_offset(positions: Sequence[tuple[float, float]], detections: Sequence[BaseGeometry], *, max_distance_m: float = 3.0, project: Callable[[float, float], tuple[float, float]] | None = None) tuple[float, float, int][source]#
Shift that lines overhead detections up with objects placed from the street.
Pairs every street position with the nearest detection center within
max_distance_m(mutual nearest neighbors only) and takes the median of the differences, twice: the second pass searches half as far around the shifted detections. Use objects that do not move and that both sources place well (hydrants, poles, the same day’s parked cars).- Parameters:
positions – Street-level object positions as
(lon, lat).detections – Overhead outlines of the same class in longitude and latitude.
max_distance_m – Farthest pairing in the first pass.
project –
(lon, lat) -> (x, y)in meters; one centered on the positions is made when omitted.
- Returns:
tuple[float, float, int] –
(east, north)in meters to add to the detections (pass it asAerialEvidence.offset_m) and the number of pairs it rests on (0and no shift when none are found).
Example
>>> from shapely.geometry import Point >>> from rapidtools.processing.street_localization import local_projection >>> project, unproject = local_projection(-117.4, 47.7) >>> street = [unproject(10.0 * i, 5.0) for i in range(6)] >>> aerial = [Point(*unproject(10.0 * i - 1.0, 5.5)).buffer(1e-5) ... for i in range(6)] >>> dx, dy, n = estimate_offset(street, aerial, project=project) >>> round(dx, 1), round(dy, 1), n (1.0, -0.5, 6)