.env example

This commit is contained in:
2026-02-16 19:27:45 -07:00
parent a7978de5a0
commit cd19f8c0b9
9 changed files with 836 additions and 32 deletions

View File

@@ -22,6 +22,7 @@ export type SourceStatus = 'pending' | 'running' | 'complete' | 'failed' | 'skip
export interface AreaImportSourceProgress {
status: SourceStatus;
candidatesFound: number;
failedQuadrants?: number;
message?: string;
error?: string;
}
@@ -333,24 +334,28 @@ export const areaImportService = {
progress.sources.osm.status = 'running';
await updateProgress();
try {
const osmCandidates = await overpassService.queryArea(bounds, (msg) => {
const osmResult = await overpassService.queryArea(bounds, (msg) => {
progress.sources.osm.message = msg;
writeProgress(importId, progress).catch(() => {});
});
// Filter by cut polygon if applicable
let filtered = osmCandidates;
let filtered = osmResult.candidates;
if (cutPolygons && cutPolygons.length > 0) {
filtered = osmCandidates.filter((c) =>
filtered = osmResult.candidates.filter((c) =>
cutPolygons.some((ring) => isPointInPolygon(c.latitude, c.longitude, ring)),
);
}
allCandidates.push(...filtered);
for (const c of filtered) allCandidates.push(c);
progress.sources.osm.status = 'complete';
progress.sources.osm.candidatesFound = filtered.length;
if (osmResult.failedQuadrants > 0) {
progress.sources.osm.failedQuadrants = osmResult.failedQuadrants;
progress.sources.osm.message = `${filtered.length} found, ${osmResult.failedQuadrants} quadrant(s) failed`;
}
await updateProgress();
logger.info(`OSM source: ${filtered.length} candidates (${osmCandidates.length} pre-filter)`);
logger.info(`OSM source: ${filtered.length} candidates (${osmResult.candidates.length} pre-filter, ${osmResult.failedQuadrants} failed quadrants)`);
} catch (err) {
const msg = err instanceof Error ? err.message : 'Unknown error';
progress.sources.osm.status = 'failed';
@@ -469,7 +474,7 @@ export const areaImportService = {
}
}
allCandidates.push(...narCandidates);
for (const c of narCandidates) allCandidates.push(c);
progress.sources.nar.status = 'complete';
progress.sources.nar.candidatesFound = narCandidates.length;
await updateProgress();
@@ -564,7 +569,7 @@ export const areaImportService = {
await new Promise((resolve) => setTimeout(resolve, 1100));
}
allCandidates.push(...rgCandidates);
for (const c of rgCandidates) allCandidates.push(c);
progress.sources.reverseGeocode.status = 'complete';
progress.sources.reverseGeocode.candidatesFound = rgCandidates.length;
await updateProgress();

View File

@@ -172,11 +172,12 @@ export const overpassService = {
/**
* Query all address data within a bounding box.
* Automatically splits large areas into sub-quadrants.
* Returns candidates and the number of quadrants that failed.
*/
async queryArea(
bounds: { minLat: number; maxLat: number; minLng: number; maxLng: number },
onProgress?: (msg: string) => void,
): Promise<CandidateLocation[]> {
): Promise<{ candidates: CandidateLocation[]; failedQuadrants: number }> {
const area = areaSqDeg(bounds);
// If area is too large, split into quadrants and query each
@@ -184,20 +185,23 @@ export const overpassService = {
const quadrants = splitBounds(bounds);
const allCandidates: CandidateLocation[] = [];
const totalQuadrants = quadrants.length;
let failedQuadrants = 0;
for (let i = 0; i < totalQuadrants; i++) {
onProgress?.(`Querying OSM quadrant ${i + 1}/${totalQuadrants}`);
try {
const subCandidates = await this.queryArea(quadrants[i]!, onProgress);
allCandidates.push(...subCandidates);
const result = await this.queryArea(quadrants[i]!, onProgress);
for (const c of result.candidates) allCandidates.push(c);
failedQuadrants += result.failedQuadrants;
} catch (err) {
const msg = err instanceof Error ? err.message : 'Unknown error';
logger.warn(`Overpass quadrant ${i + 1} failed: ${msg}`);
failedQuadrants++;
// Continue with other quadrants
}
}
return allCandidates;
return { candidates: allCandidates, failedQuadrants };
}
const bbox = `${bounds.minLat},${bounds.minLng},${bounds.maxLat},${bounds.maxLng}`;
@@ -206,6 +210,6 @@ export const overpassService = {
onProgress?.('Querying OSM addresses...');
const data = await queryOverpass<OverpassResponse>(query);
return parseElements(data.elements);
return { candidates: parseElements(data.elements), failedQuadrants: 0 };
},
};