mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
keep bent streets, enclosed landmarks and same-name outlines honest
A street ribbon that holds neither its ring mean nor the anchor is centred on the street's nearest point when the street runs within 100 m. Nominatim outline selection ranks an exact name, then one holding every asked word, then an overlap, and refuses an overlap whose name lacks the ask's last word unless that word is in the result's address or type, so "Central Park Zoo" is no longer Central Park. The server caches every accepted outline and answers each ask with the one holding its resolved anchor (sent as alat/alon), read across the antimeridian. A duplicate mark that fails to clean up no longer tears down the new outline it duplicates.
This commit is contained in:
1 parent
d9a460658d
commit
a38a065c5c
16 files changed
+516
-133
No files matched your search
@@ -253,6 +253,37 @@ export function ringCentroid(ring) {
|
||||
return { lat: sumLat / ring.length, lon: sumLon / ring.length };
|
||||
}
|
||||
|
||||
/**
|
||||
* The point on any of `lines` ([lon, lat] chains) nearest `lat, lon`, with
|
||||
* its distance in metres, or null when no line has a segment.
|
||||
*/
|
||||
export function nearestPointOnLines(lines, lat, lon) {
|
||||
const mLat = 111320;
|
||||
const mLon = mLat * Math.cos((lat * Math.PI) / 180);
|
||||
let best = null;
|
||||
let bestD2 = Infinity;
|
||||
for (const line of lines || []) {
|
||||
for (let i = 0; i + 1 < line.length; i++) {
|
||||
const ax = (line[i][0] - lon) * mLon;
|
||||
const ay = (line[i][1] - lat) * mLat;
|
||||
const dx = (line[i + 1][0] - line[i][0]) * mLon;
|
||||
const dy = (line[i + 1][1] - line[i][1]) * mLat;
|
||||
const len2 = dx * dx + dy * dy;
|
||||
const t = len2
|
||||
? Math.max(0, Math.min(1, -(ax * dx + ay * dy) / len2))
|
||||
: 0;
|
||||
const x = ax + t * dx;
|
||||
const y = ay + t * dy;
|
||||
if (x * x + y * y < bestD2) {
|
||||
bestD2 = x * x + y * y;
|
||||
best = { lat: lat + y / mLat, lon: lon + x / mLon, distanceM: 0 };
|
||||
}
|
||||
}
|
||||
}
|
||||
if (best) best.distanceM = Math.sqrt(bestD2);
|
||||
return best;
|
||||
}
|
||||
|
||||
export function approximateAreaM2(coords) {
|
||||
// Shoelace in a local equirectangular projection (good enough for buildings).
|
||||
if (coords.length < 3) return 0;
|
||||
|
||||
Reference in new issue
Block a user