<?php
/**
 * Takes several geojson files and combines them into a single one.
 *
 * @author Christian Weiske <cweiske@cweiske.de>
 */
function err($msg)
{
    echo $msg . "\n";
    exit(1);
}

if ($argc < 2) {
    err("combine-geojson.php <files>");
}

$files = $argv;
array_shift($files);

$combined = [
    'type'     => 'FeatureCollection',
    'features' => [],
];

foreach ($files as $file) {
    $combined['features'][] = json_decode(file_get_contents($file));
}

echo json_encode($combined, JSON_PRETTY_PRINT) . "\n";
?>
