-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,067 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { exportDatasetAsGeoJSON } from '../geojson/geojson-export'; | ||
import { getOutputFileBase } from '../utils/mapshaper-filename-utils'; | ||
// import { isKmzFile } from '../io/mapshaper-file-types'; | ||
|
||
export function exportKML(dataset, opts) { | ||
var toKML = require("@placemarkio/tokml").toKML; | ||
var geojsonOpts = Object.assign({combine_layers: true, geojson_type: 'FeatureCollection'}, opts); | ||
var geojson = exportDatasetAsGeoJSON(dataset, geojsonOpts); | ||
var kml = toKML(geojson); | ||
// TODO: add KMZ output | ||
// var useKmz = opts.file && isKmzFile(opts.file); | ||
var ofile = opts.file || getOutputFileBase(dataset) + '.kml'; | ||
return [{ | ||
content: kml, | ||
filename: ofile | ||
}]; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import api from '../'; | ||
import assert from 'assert'; | ||
import fs from 'fs'; | ||
|
||
describe('kml i/o', function () { | ||
|
||
it('kmz -> kml -> .geojson', async function() { | ||
var file = 'test/data/kml/Albania.kmz'; | ||
var cmd = `-i ${file} -o points.kml`; | ||
var out = await api.applyCommands(cmd); | ||
var cmd2 = '-i points.kml -o format=geojson'; | ||
var out2 = await api.applyCommands(cmd2, {'points.kml': out['points.kml']}); | ||
var geojson = JSON.parse(out2['points.json']); | ||
assert.equal(geojson.features[0].geometry.type, 'Point'); | ||
}) | ||
|
||
it('-o format=kml syntax', async function() { | ||
var file = 'test/data/kml/Albania.kmz'; | ||
var cmd = `-i ${file} -filter-fields -o format=kml`; | ||
var out = await api.applyCommands(cmd); | ||
assert(/^<kml/.test(out['Albania.kml'])); | ||
}) | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.