mapshaper 0.6.29 → 0.6.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/mapshaper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function () {
2
2
 
3
- var VERSION = "0.6.29";
3
+ var VERSION = "0.6.30";
4
4
 
5
5
 
6
6
  var utils = /*#__PURE__*/Object.freeze({
@@ -4846,13 +4846,14 @@
4846
4846
 
4847
4847
  // @info: info property of source dataset (instead of crs object, so wkt string
4848
4848
  // can be preserved if present)
4849
- function setDatasetCrsInfo(dataset, info) {
4849
+ function setDatasetCrsInfo(dataset, crsInfo) {
4850
+ crsInfo = crsInfo || {}; // also accepts null/unknown crs info
4850
4851
  dataset.info = dataset.info || {};
4851
4852
  // Assumes that proj4 object is never mutated.
4852
4853
  // TODO: assign a copy of crs (if present)
4853
- dataset.info.crs = info.crs;
4854
- dataset.info.prj = info.prj;
4855
- dataset.info.crs_string = info.crs_string;
4854
+ dataset.info.crs = crsInfo.crs;
4855
+ dataset.info.prj = crsInfo.prj;
4856
+ dataset.info.crs_string = crsInfo.crs_string;
4856
4857
  return dataset;
4857
4858
  }
4858
4859
 
@@ -23814,6 +23815,10 @@ ${svg}
23814
23815
  type: 'strings',
23815
23816
  describe: 'fields to retain (comma-sep.), e.g. \'fips,name\''
23816
23817
  })
23818
+ .option('invert', {
23819
+ type: 'flag',
23820
+ describe: 'retain only fields that would have been deleted'
23821
+ })
23817
23822
  .option('target', targetOpt);
23818
23823
 
23819
23824
  parser.command('filter-geom')
@@ -36481,7 +36486,7 @@ ${svg}
36481
36486
  return removed;
36482
36487
  }
36483
36488
 
36484
- cmd.filterFields = function(lyr, names) {
36489
+ cmd.filterFields = function(lyr, names, opts) {
36485
36490
  var table = lyr.data;
36486
36491
  names = names || [];
36487
36492
  requireDataFields(table, names);
@@ -36490,6 +36495,9 @@ ${svg}
36490
36495
  // utils.difference(table.getFields(), names).forEach(table.deleteField, table);
36491
36496
  // the below method sets field order of CSV output, and is generally faster
36492
36497
  var map = mapFieldNames(names);
36498
+ if (opts.invert) {
36499
+ map = invertFieldMap(map, table.getFields());
36500
+ }
36493
36501
  lyr.data.update(getRecordMapper(map));
36494
36502
  };
36495
36503
 
@@ -36500,6 +36508,15 @@ ${svg}
36500
36508
  lyr.data.update(getRecordMapper(map));
36501
36509
  };
36502
36510
 
36511
+ function invertFieldMap(map, fields) {
36512
+ return fields.reduce(function(memo, name) {
36513
+ if (!(name in map)) {
36514
+ memo[name] = name;
36515
+ }
36516
+ return memo;
36517
+ }, {});
36518
+ }
36519
+
36503
36520
  function mapFieldNames(names) {
36504
36521
  return (names || []).reduce(function(memo, str) {
36505
36522
  var parts = str.split('='),
@@ -37123,7 +37140,7 @@ ${svg}
37123
37140
  crsInfo = getDatasetCrsInfo(source.dataset);
37124
37141
  } else if (opts.bbox) {
37125
37142
  bounds = new Bounds(opts.bbox);
37126
- crsInfo = getCrsInfo('wgs84');
37143
+ crsInfo = probablyDecimalDegreeBounds(bounds) ? getCrsInfo('wgs84') : {};
37127
37144
  }
37128
37145
  bounds = bounds && applyRectangleOptions(bounds, crsInfo.crs, opts);
37129
37146
  if (!bounds || !bounds.hasBounds()) {
@@ -43237,7 +43254,7 @@ ${svg}
43237
43254
  outputLayers = applyCommandToEachLayer(cmd.filterFeatures, targetLayers, arcs, opts);
43238
43255
 
43239
43256
  } else if (name == 'filter-fields') {
43240
- applyCommandToEachLayer(cmd.filterFields, targetLayers, opts.fields);
43257
+ applyCommandToEachLayer(cmd.filterFields, targetLayers, opts.fields, opts);
43241
43258
 
43242
43259
  } else if (name == 'filter-geom') {
43243
43260
  applyCommandToEachLayer(cmd.filterGeom, targetLayers, arcs, opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.6.29",
3
+ "version": "0.6.30",
4
4
  "description": "A tool for editing vector datasets for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
@@ -2026,23 +2026,23 @@
2026
2026
  }
2027
2027
  if (group[internal.PACKAGE_EXT]) {
2028
2028
  await importSessionData(group[internal.PACKAGE_EXT].content, gui);
2029
- } else {
2030
- importDataset(group, importOpts);
2029
+ } else if (importDataset(group, importOpts)) {
2030
+ importCount++;
2031
+ gui.session.fileImported(group.filename, optStr);
2031
2032
  }
2032
- importCount++;
2033
- gui.session.fileImported(group.filename, optStr);
2034
2033
  }
2035
2034
  }
2036
2035
 
2037
2036
  function importDataset(group, importOpts) {
2038
2037
  var dataset = internal.importContent(group, importOpts);
2039
- if (datasetIsEmpty(dataset)) return;
2038
+ if (datasetIsEmpty(dataset)) return false;
2040
2039
  if (group.layername) {
2041
2040
  dataset.layers.forEach(lyr => lyr.name = group.layername);
2042
2041
  }
2043
2042
  // save import options for use by repair control, etc.
2044
2043
  dataset.info.import_options = importOpts;
2045
2044
  model.addDataset(dataset);
2045
+ return true;
2046
2046
  }
2047
2047
 
2048
2048
  function addEmptyLayer() {
@@ -2183,8 +2183,8 @@
2183
2183
  name: filename,
2184
2184
  content: index[filename]
2185
2185
  });
2186
- return memo;
2187
2186
  }
2187
+ return memo;
2188
2188
  }, []);
2189
2189
  }
2190
2190
 
package/www/mapshaper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function () {
2
2
 
3
- var VERSION = "0.6.29";
3
+ var VERSION = "0.6.30";
4
4
 
5
5
 
6
6
  var utils = /*#__PURE__*/Object.freeze({
@@ -4846,13 +4846,14 @@
4846
4846
 
4847
4847
  // @info: info property of source dataset (instead of crs object, so wkt string
4848
4848
  // can be preserved if present)
4849
- function setDatasetCrsInfo(dataset, info) {
4849
+ function setDatasetCrsInfo(dataset, crsInfo) {
4850
+ crsInfo = crsInfo || {}; // also accepts null/unknown crs info
4850
4851
  dataset.info = dataset.info || {};
4851
4852
  // Assumes that proj4 object is never mutated.
4852
4853
  // TODO: assign a copy of crs (if present)
4853
- dataset.info.crs = info.crs;
4854
- dataset.info.prj = info.prj;
4855
- dataset.info.crs_string = info.crs_string;
4854
+ dataset.info.crs = crsInfo.crs;
4855
+ dataset.info.prj = crsInfo.prj;
4856
+ dataset.info.crs_string = crsInfo.crs_string;
4856
4857
  return dataset;
4857
4858
  }
4858
4859
 
@@ -23814,6 +23815,10 @@ ${svg}
23814
23815
  type: 'strings',
23815
23816
  describe: 'fields to retain (comma-sep.), e.g. \'fips,name\''
23816
23817
  })
23818
+ .option('invert', {
23819
+ type: 'flag',
23820
+ describe: 'retain only fields that would have been deleted'
23821
+ })
23817
23822
  .option('target', targetOpt);
23818
23823
 
23819
23824
  parser.command('filter-geom')
@@ -36481,7 +36486,7 @@ ${svg}
36481
36486
  return removed;
36482
36487
  }
36483
36488
 
36484
- cmd.filterFields = function(lyr, names) {
36489
+ cmd.filterFields = function(lyr, names, opts) {
36485
36490
  var table = lyr.data;
36486
36491
  names = names || [];
36487
36492
  requireDataFields(table, names);
@@ -36490,6 +36495,9 @@ ${svg}
36490
36495
  // utils.difference(table.getFields(), names).forEach(table.deleteField, table);
36491
36496
  // the below method sets field order of CSV output, and is generally faster
36492
36497
  var map = mapFieldNames(names);
36498
+ if (opts.invert) {
36499
+ map = invertFieldMap(map, table.getFields());
36500
+ }
36493
36501
  lyr.data.update(getRecordMapper(map));
36494
36502
  };
36495
36503
 
@@ -36500,6 +36508,15 @@ ${svg}
36500
36508
  lyr.data.update(getRecordMapper(map));
36501
36509
  };
36502
36510
 
36511
+ function invertFieldMap(map, fields) {
36512
+ return fields.reduce(function(memo, name) {
36513
+ if (!(name in map)) {
36514
+ memo[name] = name;
36515
+ }
36516
+ return memo;
36517
+ }, {});
36518
+ }
36519
+
36503
36520
  function mapFieldNames(names) {
36504
36521
  return (names || []).reduce(function(memo, str) {
36505
36522
  var parts = str.split('='),
@@ -37123,7 +37140,7 @@ ${svg}
37123
37140
  crsInfo = getDatasetCrsInfo(source.dataset);
37124
37141
  } else if (opts.bbox) {
37125
37142
  bounds = new Bounds(opts.bbox);
37126
- crsInfo = getCrsInfo('wgs84');
37143
+ crsInfo = probablyDecimalDegreeBounds(bounds) ? getCrsInfo('wgs84') : {};
37127
37144
  }
37128
37145
  bounds = bounds && applyRectangleOptions(bounds, crsInfo.crs, opts);
37129
37146
  if (!bounds || !bounds.hasBounds()) {
@@ -43237,7 +43254,7 @@ ${svg}
43237
43254
  outputLayers = applyCommandToEachLayer(cmd.filterFeatures, targetLayers, arcs, opts);
43238
43255
 
43239
43256
  } else if (name == 'filter-fields') {
43240
- applyCommandToEachLayer(cmd.filterFields, targetLayers, opts.fields);
43257
+ applyCommandToEachLayer(cmd.filterFields, targetLayers, opts.fields, opts);
43241
43258
 
43242
43259
  } else if (name == 'filter-geom') {
43243
43260
  applyCommandToEachLayer(cmd.filterGeom, targetLayers, arcs, opts);