-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.js
27 lines (23 loc) · 879 Bytes
/
convert.js
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
var togeojson = require('@mapbox/togeojson'),
geojsonMerge = require('@mapbox/geojson-merge'),
flatten = require('geojson-flatten'),
area = require('@mapbox/geojson-area'),
fs = require('fs'),
DOMParser = require('xmldom').DOMParser,
find = require('findit');
var find = find('./data');
var geojsons = [];
find.on('file', function (file, stat) {
// convert all kml files to geojson
var kml = new DOMParser().parseFromString(fs.readFileSync(file, 'utf8'));
var gj = flatten(togeojson.kml(kml));
gj.features.forEach(function(gjf) {
gjf.properties.geofabrikName = file.substr(0,file.length-4).substr(5);
gjf.properties.area = area.geometry(gjf.geometry);
});
geojsons.push(gj);
});
find.on('end', function () {
var geojson = geojsonMerge.merge(geojsons);
process.stdout.write(JSON.stringify(geojson));
});