Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update airspaces, fixes CO #340

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/fxc-tiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Install [tippecanoe](https://github.com/felt/tippecanoe) - note that the the map

## Airspaces

- nx build fxc-tiles
- nx build secrets && nx build fxc-tiles
vicb marked this conversation as resolved.
Show resolved Hide resolved
- cd dist/apps/fxc-tiles
- `npm run download-airspaces`
- Display stats with `node dist/apps/fxc-tiles/airspaces/stats.js` (quick check of the airspaces)
Expand Down
29 changes: 28 additions & 1 deletion apps/fxc-tiles/src/app/airspaces/create-geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,23 @@ openaipAirspaces = openaipAirspaces.map(processFn);
printLogs('Processed:', logs);
// filter
openaipAirspaces = openaipAirspaces.filter(filterFn);
openaipAirspaces = openaipAirspaces.filter(createFilterOutColombia(logs));
printLogs('Filtered:', logs);
console.log(`-> ${openaipAirspaces.length} airspaces`);

// Colombia
console.log('\n# Colombia airspaces (XContest)');
const coContent = readFileSync(join(program.opts().input, 'colombia.openair'), 'utf-8');
let coAirspaces = oair.parseAll(coContent, 'CO');
console.log(`${coAirspaces.length} airspaces imported`);
// post process
coAirspaces = coAirspaces.map(processFn);
printLogs('Processed:', logs);
// filter
coAirspaces = coAirspaces.filter(filterFn);
printLogs('Filtered:', logs);
console.log(`-> ${coAirspaces.length} airspaces`);

// Ukraine
console.log('\n# Ukraine airspaces');
const uaContent = readFileSync(join(program.opts().input, 'UKRAINE (UK).txt'), 'utf-8');
Expand Down Expand Up @@ -68,7 +82,7 @@ printLogs('Filtered:', logs);
console.log(`-> ${reAirspaces.length} airspaces`);

console.log('\n# Airspaces');
const airspaces = [...openaipAirspaces, ...uaAirspaces, ...reAirspaces];
const airspaces = [...openaipAirspaces, ...coAirspaces, ...uaAirspaces, ...reAirspaces];
console.log(`-> ${airspaces.length} airspaces`);
const airspaceObj = GeoJSON.parse(airspaces, { Polygon: 'polygon' });
writeFileSync(program.opts().output, JSON.stringify(airspaceObj, null, 2));
Expand All @@ -95,6 +109,19 @@ function createFilter(logs: Map<string, number>) {
};
}

// Filter out CO airspaces from openaip.net
// They are not up to date
// See https://paltakats.com/airspace-piedechinche
function createFilterOutColombia(logs: Map<string, number>) {
return (airspace: Airspace, index: number) => {
if (airspace.country.toUpperCase() === 'CO') {
incMapKey(logs, 'CO');
return false;
}
return true;
};
}

// Process airspaces.
function createProcess(logs: Map<string, number>) {
return (airspace: Airspace, index: number) => {
Expand Down
93 changes: 62 additions & 31 deletions apps/fxc-tiles/src/app/parser/openair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function decodeCoordinates(coords: string): { lat: number; lon: number } {
const lon = Number(parseFloat(match[3]).toFixed(6)) * (match[4] == 'E' ? 1 : -1);
return { lon, lat };
}
// 30:58:01 N 084:49:00 W
match = coords.match(/([\d:]+) (N|S) ([\d:]+) (W|E)/);
// 30:58:01.00 N 084:49:00.00 W
match = coords.match(/([\d.:]+) (N|S) ([\d.:]+) (W|E)/);
if (match != null) {
let [d, m, s] = match[1].split(':').map((s) => parseFloat(s));
const lat = sexagesimalToDecimal(`${d}° ${m}' ${s}" ${match[2]}`);
Expand Down Expand Up @@ -160,42 +160,31 @@ export function parseAll(openair: string, country: string): Airspace[] {
throw new Error(`Unsupported variable ${line}`);
}

case 'DA': {
const [radiusNm, startAngle, endAngle] = content.split(',').map((v) => parseFloat(v));
if (radiusNm == null || startAngle == null || endAngle == null) {
throw new Error(`Invalid DA arc ${line}`);
}
if (center == null) {
throw new Error(`No center for DA ${line}`);
}
addArc(center, radiusNm * NAUTICAL_MILE_IN_METER, direction, startAngle, endAngle, coords);
break;
}

case 'DB': {
// Arc
const [start, end] = content.split(',').map((coords) => decodeCoordinates(coords));
if (start == null || end == null) {
throw new Error(`Invalid arc ${line}`);
throw new Error(`Invalid DB arc ${line}`);
}
if (center == null) {
throw new Error(`No center for DB ${line}`);
}
let angle = getGreatCircleBearing(center, start);
let endAngle = getGreatCircleBearing(center, end);
if (direction === Direction.Clockwise && endAngle < angle) {
endAngle += 360;
}
if (direction === Direction.CounterClockwise && endAngle > angle) {
endAngle -= 360;
}
const angleStep = 10 * (direction === Direction.Clockwise ? 1 : -1);
const distance = getDistance(center, start);
// eslint-disable-next-line no-constant-condition
for (let i = 0; true; i++) {
const { latitude, longitude } = computeDestinationPoint(center, distance, angle);
coords.push([longitude, latitude]);
angle += angleStep;
if (direction === Direction.Clockwise && angle > endAngle) {
break;
}
if (direction === Direction.CounterClockwise && angle < endAngle) {
break;
}
if (i > 100) {
throw new Error(`Angle error`);
}
}
const { latitude, longitude } = computeDestinationPoint(center, distance, endAngle);
coords.push([longitude, latitude]);
const startAngle = getGreatCircleBearing(center, start);
const endAngle = getGreatCircleBearing(center, end);
const radius = getDistance(center, start);
addArc(center, radius, direction, startAngle, endAngle, coords);
break;
}

Expand Down Expand Up @@ -227,6 +216,40 @@ export function parseAll(openair: string, country: string): Airspace[] {
return airspaces;
}

function addArc(
center: { lat: number; lon: number },
radius: number,
direction: Direction,
startAngle: number,
endAngle: number,
coords: [lon: number, lat: number][],
) {
if (direction === Direction.Clockwise && endAngle < startAngle) {
endAngle += 360;
}
if (direction === Direction.CounterClockwise && endAngle > startAngle) {
endAngle -= 360;
}
const angleStep = 10 * (direction === Direction.Clockwise ? 1 : -1);
// eslint-disable-next-line no-constant-condition
for (let i = 0; true; i++) {
const { latitude, longitude } = computeDestinationPoint(center, radius, startAngle);
coords.push([longitude, latitude]);
startAngle += angleStep;
if (direction === Direction.Clockwise && startAngle > endAngle) {
break;
}
if (direction === Direction.CounterClockwise && startAngle < endAngle) {
break;
}
if (i > 100) {
throw new Error(`Angle error`);
}
}
const { latitude, longitude } = computeDestinationPoint(center, radius, endAngle);
coords.push([longitude, latitude]);
}
vicb marked this conversation as resolved.
Show resolved Hide resolved

function decodeACField(ac: string, country: string) {
if (ac === 'CTR') {
return {
Expand All @@ -252,14 +275,22 @@ function decodeACField(ac: string, country: string) {
};
}

if (ac === 'PROHIBITED') {
if (ac === 'P' || ac === 'PROHIBITED') {
return {
icaoClass: Class.SUA,
type: Type.Prohibited,
ignoreAirspace: false,
};
}

if (ac === 'W') {
return {
icaoClass: Class.SUA,
type: Type.WarningArea,
ignoreAirspace: false,
};
}

// Ukraine specific rules
if (country == 'UA') {
if (['ATZ', 'UNKNOWN', 'TRANING', 'FIR'].includes(ac)) {
Expand Down
Loading
Loading