Skip to content

DataMerger

Defined in: packages/core/src/data/merge/data-merger.ts:116

Merges GeoJSON FeatureCollections using configurable strategies.

Supports three merge strategies:

replace: Complete replacement of existing data

  • Replaces all existing features with incoming features
  • Simple and efficient for full updates

merge: Update by key, keep unmatched

  • Updates existing features by matching on a key property
  • Adds new features that don’t match existing keys
  • Preserves existing features not in the update
  • Requires updateKey option

append-window: Add with time/size limits

  • Appends incoming features to existing features
  • Applies size limit (keeps most recent N features)
  • Applies time limit (removes features older than duration)
  • Requires timestampField for time-based filtering
const merger = new DataMerger();
// Replace all data
const result = merger.merge(existing, incoming, {
strategy: 'replace'
});
// Merge by vehicle ID
const result = merger.merge(existing, incoming, {
strategy: 'merge',
updateKey: 'vehicleId'
});
// Append with 100 feature limit and 1 hour window
const result = merger.merge(existing, incoming, {
strategy: 'append-window',
windowSize: 100,
windowDuration: 3600000,
timestampField: 'timestamp'
});

new DataMerger(): DataMerger

DataMerger

merge(existing, incoming, options): MergeResult

Defined in: packages/core/src/data/merge/data-merger.ts:139

Merge two FeatureCollections using the specified strategy.

ParameterTypeDescription
existingFeatureCollectionExisting feature collection
incomingFeatureCollectionIncoming feature collection to merge
optionsMergeOptionsMerge options including strategy

MergeResult

Merge result with statistics

If merge strategy requires missing options

const merger = new DataMerger();
const result = merger.merge(existingData, newData, {
strategy: 'merge',
updateKey: 'id'
});
console.log(`Added: ${result.added}, Updated: ${result.updated}`);
console.log(`Total features: ${result.total}`);