Skip to content

Commit fdc7fb5

Browse files
fix: improve error handling of invalid geometries
1 parent 379bd96 commit fdc7fb5

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎src/renderer/src/lib/map/data/utils.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,21 @@ export function applyGalaxyBoundary(
283283
externalBorder: PolygonalFeature | null,
284284
) {
285285
if (externalBorder != null) {
286-
return turf.intersect(geojson, externalBorder);
286+
try {
287+
return turf.intersect(geojson, externalBorder);
288+
} catch {
289+
// try again with buffered shapes; this _can_ repair invalid geojson
290+
// but it is expensive and it can produce artifacts so don't do this by default
291+
console.warn('Intersect failed; retrying with buffered geometries');
292+
return turf.intersect(
293+
turf.buffer(turf.buffer(geojson, 10 ** -5, { units: 'millimeters' }), 10 ** -5, {
294+
units: 'millimeters',
295+
}),
296+
turf.buffer(turf.buffer(externalBorder, 10 ** -5, { units: 'millimeters' }), 10 ** -5, {
297+
units: 'millimeters',
298+
}),
299+
);
300+
}
287301
}
288302
return geojson;
289303
}

0 commit comments

Comments
 (0)