(no commit message)
[paste/555.git] / combine-geojson.php
1 <?php
2 /**
3  * Takes several geojson files and combines them into a single one.
4  *
5  * @author Christian Weiske <cweiske@cweiske.de>
6  */
7 function err($msg)
8 {
9     echo $msg . "\n";
10     exit(1);
11 }
12
13 if ($argc < 2) {
14     err("combine-geojson.php <files>");
15 }
16
17 $files = $argv;
18 array_shift($files);
19
20 $combined = [
21     'type'     => 'FeatureCollection',
22     'features' => [],
23 ];
24
25 foreach ($files as $file) {
26     $combined['features'][] = json_decode(file_get_contents($file));
27 }
28
29 echo json_encode($combined, JSON_PRETTY_PRINT) . "\n";
30 ?>