Skip to content

Commit

Permalink
Merge pull request #54 from dfpc-coe/sensor
Browse files Browse the repository at this point in the history
Sensor Parsing
  • Loading branch information
ingalls authored Nov 21, 2024
2 parents fc352bb + adf31df commit 3dd1bc4
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 183 deletions.
19 changes: 10 additions & 9 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import CoT from './lib/cot.js';
export * as Feature from './lib/types/feature.js'
export * as Types from './lib/types/types.js'
export * as CoTTypes from './lib/types/cot-types.js'
export * from './lib/chat.js'
export * from './lib/fileshare.js'
export * from './lib/force-delete.js'
export * from './lib/data-package.js'
export * from './lib/xml/basemap.js'
export * from './lib/xml/iconset.js'
export * as Feature from './lib/types/feature.js';
export * as Types from './lib/types/types.js';
export * as CoTTypes from './lib/types/cot-types.js';
export * from './lib/chat.js';
export * from './lib/sensor.js';
export * from './lib/fileshare.js';
export * from './lib/force-delete.js';
export * from './lib/data-package.js';
export * from './lib/xml/basemap.js';
export * from './lib/xml/iconset.js';

export default CoT;
34 changes: 34 additions & 0 deletions lib/cot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Static } from '@sinclair/typebox';
import type {
Feature,
Polygon,
Position,
FeaturePropertyMission,
FeaturePropertyMissionLayer,
} from './types/feature.js';
Expand All @@ -16,11 +17,13 @@ import type {
Link,
LinkAttributes,
VideoAttributes,
SensorAttributes,
VideoConnectionEntryAttributes,
} from './types/types.js'
import {
InputFeature,
} from './types/feature.js';
import Sensor from './sensor.js';
import type { AllGeoJSON } from "@turf/helpers";
import PointOnFeature from '@turf/point-on-feature';
import Truncate from '@turf/truncate';
Expand Down Expand Up @@ -236,6 +239,37 @@ export default class CoT {
return this;
}

position(position?: Static<typeof Position>): Static<typeof Position> {
if (position) {
this.raw.event.point._attributes.lon = String(position[0]);
this.raw.event.point._attributes.lat = String(position[1]);
}

return [
Number(this.raw.event.point._attributes.lon),
Number(this.raw.event.point._attributes.lat)
];
}

sensor(sensor?: Static<typeof SensorAttributes>): Static<typeof Polygon> | null {
if (!this.raw.event.detail) this.raw.event.detail = {};

if (sensor) {
this.raw.event.detail.sensor = {
_attributes: sensor
}
}

if (!this.raw.event.detail.sensor || !this.raw.event.detail.sensor._attributes) {
return null;
}

return new Sensor(
this.position(),
this.raw.event.detail.sensor._attributes
).to_geojson();
};

addLink(link: Static<typeof LinkAttributes>): CoT {
if (!this.raw.event.detail) this.raw.event.detail = {};

Expand Down
30 changes: 30 additions & 0 deletions lib/sensor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Static } from '@sinclair/typebox';
import { Position, Polygon } from './types/feature.js';
import { SensorAttributes } from './types/types.js';
import { sector } from '@turf/sector';

export default class Sensor {
center: Static<typeof Position>;
sensor: Static<typeof SensorAttributes>;

constructor(
center: Static<typeof Position>,
sensor: Static<typeof SensorAttributes>
) {
this.center = center;
this.sensor = sensor;
}

to_geojson(): Static<typeof Polygon> | null {
if (!this.sensor.range) return null;
if (!this.sensor.azimuth) return null;
if (!this.sensor.fov) return null;

return sector(
this.center,
this.sensor.range / 1000,
this.sensor.azimuth,
this.sensor.azimuth + this.sensor.fov,
).geometry;
}
}
Loading

0 comments on commit 3dd1bc4

Please sign in to comment.