-
Notifications
You must be signed in to change notification settings - Fork 3
/
buffer.ts
39 lines (31 loc) · 1006 Bytes
/
buffer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
import buffer from '@turf/buffer';
import es from 'event-stream';
import fs from 'fs';
import { Feature } from 'geojson';
import JSONStream from 'jsonstream-next';
import minimist from 'minimist';
import path from 'path';
import fileExists from './file-exists';
const options = minimist(process.argv.slice(2));
const source = options._[0];
const target = options._[1];
const radius = options.r ?? options.radius;
console.log(`Source: ${path.resolve(source)}`);
console.log(`Radius: ${radius}m.`);
if (fileExists(source) !== true) process.exit(1);
const directory = path.dirname(source);
console.log(path.resolve(directory, target));
fs.createReadStream(source)
.pipe(JSONStream.parse('features.*'))
.pipe(
es.mapSync((feature: Feature) => buffer(feature, radius, { units: 'meters' }))
)
.pipe(
JSONStream.stringify(
'{"type":"FeatureCollection","features":[\n',
',\n',
'\n]}'
)
)
.pipe(fs.createWriteStream(path.resolve(directory, target)));