Skip to content

Commit

Permalink
v0.6.16
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed Jan 3, 2023
1 parent 722903a commit 511cf2c
Show file tree
Hide file tree
Showing 45 changed files with 8,355 additions and 3,581 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.6.16
* Added support for saving output files to a user-selected directory in the web UI, if supported by the browser.
* Added support to the web UI for reading and writing gzipped (.gz) files.
* Improved support for .zip and .gz files in both web and cli programs.
* Minor update to dbf text encoding detection.

v0.6.15
* Added support to the CLI for reading .kml and .kmz files.
* Added support to the CLI for writing .kml files.
Expand Down
77 changes: 69 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mapshaper",
"version": "0.6.15",
"version": "0.6.16",
"description": "A tool for editing vector datasets for mapping and GIS.",
"keywords": [
"shapefile",
Expand Down Expand Up @@ -28,7 +28,7 @@
"lint": "eslint --ext mjs src/",
"prepublishOnly": "npm lint; npm test; ./pre-publish",
"postpublish": "./release_web_ui; ./release_github_version",
"browserify": "browserify -r sync-request -r mproj -r buffer -r iconv-lite -r fs -r flatbush -r rw -r path -r kdbush -r @tmcw/togeojson -r @placemarkio/tokml -o www/modules.js",
"browserify": "browserify -r sync-request -r mproj -r buffer -r iconv-lite -r fs -r flatbush -r rw -r path -r kdbush -r @tmcw/togeojson -r @placemarkio/tokml -r bson -o www/modules.js",
"dev": "rollup --config --watch"
},
"main": "./mapshaper.js",
Expand All @@ -44,12 +44,14 @@
"@tmcw/togeojson": "^5.5.0",
"@xmldom/xmldom": "^0.8.6",
"adm-zip": "^0.5.9",
"bson": "^4.7.0",
"commander": "7.0.0",
"cookies": "^0.8.0",
"d3-color": "3.1.0",
"d3-interpolate": "^3.0.1",
"d3-scale-chromatic": "3.0.0",
"delaunator": "^5.0.0",
"fflate": "^0.7.4",
"flatbush": "^3.2.1",
"geokdbush": "^1.1.0",
"iconv-lite": "^0.6.3",
Expand Down
65 changes: 65 additions & 0 deletions src/bson/bson-export.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ArcCollection } from '../paths/mapshaper-arcs';
import { DataTable } from '../datatable/mapshaper-data-table';

export function exportBSON(datasets, opts) {
var { serialize } = require('bson');
var obj = exportDatasets(datasets);
var content = serialize(obj);
return [{
content: content,
filename: opts.file || 'output.mshp'
}];
}

// gui: (optional) gui instance
//
export function exportDatasets(datasets) {
// TODO: add targets
// TODO: add gui state
return {
version: 1,
datasets: datasets.map(exportDataset)
};
}

// TODO..
// export function serializeSession(catalog) {
// var obj = exportDatasets(catalog.getDatasets());
// return BSON.serialize(obj);
// }

export function exportDataset(dataset) {
return Object.assign(dataset, {
arcs: dataset.arcs ? exportArcs(dataset.arcs) : null,
info: dataset.info ? exportInfo(dataset.info) : null,
layers: (dataset.layers || []).map(exportLayer)
});
}

function typedArrayToBuffer(arr) {
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
}

function exportArcs(arcs) {
var data = arcs.getVertexData();
var obj = {
nn: typedArrayToBuffer(data.nn),
xx: typedArrayToBuffer(data.xx),
yy: typedArrayToBuffer(data.yy)
};
return obj;
}

function exportLayer(lyr) {
return {
name: lyr.name || null,
geometry_type: lyr.geometry_type || null,
shapes: lyr.shapes || null,
data: lyr.data ? lyr.data.getRecords() : null
};
}

function exportInfo(info) {
// TODO: export CRS
return info;
}
60 changes: 60 additions & 0 deletions src/bson/bson-import.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ArcCollection } from '../paths/mapshaper-arcs';
import { DataTable } from '../datatable/mapshaper-data-table';
import { stop } from '../utils/mapshaper-logging';
import { BinArray } from '../utils/mapshaper-binarray';

// Import datasets contained in a BSON blob
// Return command target as a dataset
//
export function importBSON(buf) {
var { deserialize } = require('bson');
var obj = deserialize(buf, {
promoteBuffers: true,
promoteValues: true
});
if (!isValidSession(obj)) {
stop('Invalid mapshaper session data object');
}

var datasets = obj.datasets.map(importDataset);
var target = datasets[0]; // TODO: improve
return {
datasets: datasets,
target: target
};
}

function isValidSession(obj) {
if (!Array.isArray(obj.datasets)) {
return false;
}
return true;
}

function importDataset(obj) {
return {
info: obj.info,
layers: (obj.layers || []).map(importLayer),
arcs: obj.arcs ? importArcs(obj.arcs) : null
};
}

function bufferToDataView(buf, constructor) {
return new constructor(BinArray.copyToArrayBuffer(buf));
// this doesn't work: "RangeError: start offset of Float64Array should be a multiple of 8"
// return new constructor(buf.buffer, buf.byteOffset, buf.byteLength);
}

function importArcs(obj) {
var nn = bufferToDataView(obj.nn, Uint32Array);
var xx = bufferToDataView(obj.xx, Float64Array);
var yy = bufferToDataView(obj.yy, Float64Array);
var arcs = new ArcCollection(nn, xx, yy);
return arcs;
}

function importLayer(lyr) {
return Object.assign(lyr, {
data: lyr.data ? new DataTable(lyr.data) : null
});
}
3 changes: 1 addition & 2 deletions src/cli/mapshaper-run-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@ export function runCommand(command, job, cb) {

} else if (name == 'i') {
if (opts.replace) job.catalog = new Catalog(); // is this what we want?
targetDataset = cmd.importFiles(command.options);
targetDataset = cmd.importFiles(job.catalog, command.options);
if (targetDataset) {
job.catalog.addDataset(targetDataset);
outputLayers = targetDataset.layers; // kludge to allow layer naming below
}

Expand Down
Loading

0 comments on commit 511cf2c

Please sign in to comment.