Skip to content

Commit

Permalink
Update website
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed May 15, 2024
1 parent a5b5668 commit ddb4716
Showing 1 changed file with 110 additions and 48 deletions.
158 changes: 110 additions & 48 deletions mapshaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4660,11 +4660,14 @@

var mproj$1 = require$1('mproj');

// A compound projection, consisting of a default projection and one or more rectangular frames
// that are projected separately and affine transformed.
// Constructor function for a compound projection consisting of a default
// projection and one or more rectangular frames that are projected separately
// and affine transformed.
// @mainParams: parameters for main projection, including:
// proj: Proj string
// bbox: lat-lon bounding box
// Returns a mproj CRS object for the main CRS with the CRS objects of the
// embedded projections attached.
function MixedProjection(mainParams, options) {
var mainFrame = initFrame(mainParams);
var mainP = mainFrame.crs;
Expand Down Expand Up @@ -5056,6 +5059,9 @@
return str in projectionAliases;
}

// str: projection string in a variety of forms accepted by the -proj command
// (e.g. alias, EPSG:XXXX, Proj.4 string, bare Proj.4 projection name)
// Returns a properly formatted Proj.4 string or an instantiated mproj object
function getProjDefn(str) {
var defn;
// prepend '+proj=' to bare proj names
Expand Down Expand Up @@ -7701,7 +7707,7 @@
if (currentUnpackr.mapsAsObjects) {
let object = {};
for (let i = 0; i < token; i++) {
let key = readKey$1();
let key = readKey();
if (key === '__proto__')
key = '__proto_';
object[key] = read();
Expand Down Expand Up @@ -8063,7 +8069,7 @@
if (currentUnpackr.mapsAsObjects) {
let object = {};
for (let i = 0; i < length; i++) {
let key = readKey$1();
let key = readKey();
if (key === '__proto__')
key = '__proto_';
object[key] = read();
Expand Down Expand Up @@ -8286,7 +8292,7 @@
}

var keyCache = new Array(4096);
function readKey$1() {
function readKey() {
let length = src[position$1++];
if (length >= 0xa0 && length < 0xc0) {
// fixstr, potentially use key cache
Expand Down Expand Up @@ -11316,9 +11322,11 @@
function guessInputFileType(file) {
var ext = getFileExtension(file || '').toLowerCase(),
type = null;
if (ext == 'dbf' || ext == 'shp' || ext == 'prj' || ext == 'shx' || ext == 'kml' || ext == 'cpg') {
if (ext == 'dbf' || ext == 'shp' || ext == 'kml') {
type = ext;
} else if (/json$/.test(ext)) {
} else if (isAuxiliaryInputFileType(ext)) {
type = ext;
} else if (/json$/.test(ext)) { // matches topojson, geojson, json
type = 'json';
} else if (ext == 'csv' || ext == 'tsv' || ext == 'txt' || ext == 'tab') {
type = 'text';
Expand All @@ -11328,6 +11336,11 @@
return type;
}

// File types that can be imported but are not convertible to datasets
function isAuxiliaryInputFileType(type) {
return type == 'prj' || type == 'shx' || type == 'cpg';
}

function guessInputContentType(content) {
var type = null;
if (utils.isString(content)) {
Expand Down Expand Up @@ -11428,6 +11441,7 @@
var FileTypes = /*#__PURE__*/Object.freeze({
__proto__: null,
guessInputFileType: guessInputFileType,
isAuxiliaryInputFileType: isAuxiliaryInputFileType,
guessInputContentType: guessInputContentType,
guessInputType: guessInputType,
stringLooksLikeJSON: stringLooksLikeJSON,
Expand Down Expand Up @@ -28085,7 +28099,7 @@ ${svg}

var EOF; // undefined is used as an EOF marker

var RESERVE = 0X1000; // RESERVE is the number of bytes to keep in read buffer
var RESERVE = 4096; // RESERVE is the number of bytes to keep in read buffer
var BUFLEN = 1e7; // buffer chunk size
var MAX_STRLEN = 5e6; // max byte len of a value string (object keys are shorter)

Expand All @@ -28102,14 +28116,33 @@ ${svg}
return val;
}

// Read and parse JSON objects from a FileReader
function parseObjects(reader, offset, cb) {
var src = ByteReader(reader, offset);
seekObjectStart(src);
// parse data from:
// * FeatureCollection
// * GeometryCollection
// * Single Feature or Geometry
// * WS-delimited sequence of Features or geometries
//
function parseGeoJSON(reader, cb) {
var src = ByteReader(reader, 0);
var isObject = seekObjectStart(src);
if (!isObject) {
stop('File is not GeoJSON');
}
var obj = readObject(src, cb);
if (obj.type == 'FeatureCollection' || obj.type == 'GeometryCollection') {
return obj;
}
if (!obj.type) { // TODO: validate type
stop('Invalid GeoJSON');
}
cb(obj);
// try to read newline-delimited GeoJSON
skipWS(src);
while (src.peek() == LBRACE) {
cb(readObject(src));
readToken(src, COMMA);
cb(readObject(src, cb));
skipWS(src);
}
return null;
}

function parseError(msg, i) {
Expand Down Expand Up @@ -28166,15 +28199,26 @@ ${svg}
function readArray(src) {
var arr = [], c;
eatChar(src, LBRACK);
c = readToken(src, RBRACK);
c = scanForSyntaxChar(src, RBRACK);
while (c != RBRACK) {
src.refresh();
arr.push(readArrayElement(src));
c = readAorB(src, COMMA, RBRACK);
c = scanForAorB(src, COMMA, RBRACK);
}
return arr;
}

function readCollectionArray(src, cb) {
var c;
eatChar(src, LBRACK);
c = scanForSyntaxChar(src, RBRACK);
while (c != RBRACK) {
src.refresh();
cb(readArrayElement(src));
c = scanForAorB(src, COMMA, RBRACK);
}
}

// Using this function instead of readValue() to read array elements
// gives up to a 25% reduction in overall processing time when parsing
// coordinate-heavy GeoJSON files.
Expand Down Expand Up @@ -28205,7 +28249,7 @@ ${svg}
do {
src.refresh(); // make make sure long arrays of numbers don't overflow
arr.push(readValue(src));
} while(readAorB(src, COMMA, RBRACK) == COMMA);
} while(scanForAorB(src, COMMA, RBRACK) == COMMA);
return arr;
}

Expand All @@ -28226,7 +28270,7 @@ ${svg}
// Reads and returns tok if tok is the next non-whitespace byte,
// else returns null.
// Scans past WS chars, both before and after tok
function readToken(src, tok) {
function scanForSyntaxChar(src, tok) {
skipWS(src);
var c = src.peek();
if (c === tok) {
Expand All @@ -28237,44 +28281,68 @@ ${svg}
return null;
}

// assumes no leading WS
// Assumes next char is the first char of a data object (not WS "," ":" "}" "]" etc)
function readValue(src) {
var c = src.peek();
var val;
if (isFirstNumChar(c)) val = readNumber(src);
else if (c == LBRACK) val = readArray(src);
else if (c == DQUOTE) val = readString(src);
else if (c == LBRACE) val = readObject(src);
else if (c == 110) val = eatChars(src, "null") && null;
else if (c == 116) val = eatChars(src, "true") && true;
else if (c == 102) val = eatChars(src, "false") && false;
else if (c == 110) val = readNull(src); // "n" -> null
else if (c == 116) val = readTrue(src); // "t" -> true
else if (c == 102) val = readFalse(src); // "f" -> false
else unexpectedCharAt(c, src.index());
return val;
}

function readAorB(src, a, b) {
function readTrue(src) {
eatChars(src, 'true');
return true;
}

function readFalse(src) {
eatChars(src, 'false');
return false;
}

function readNull(src) {
eatChars(src, 'null');
return null;
}

function scanForAorB(src, a, b) {
skipWS(src);
var c = src.getChar();
if (c != a && c != b) unexpectedCharAt(c, src.index() - 1);
skipWS(src);
return c;
}

function readObject(src) {

// cb: optional callback for returning GeoJSON features or geometries
//
function readObject(src, cb) {
var o = {};
var key, c;
eatChar(src, LBRACE);
c = readToken(src, RBRACE);
c = scanForSyntaxChar(src, RBRACE);
while (c != RBRACE) {
src.refresh();
key = readKey(src); // use caching for faster key parsing
key = readKeywordString(src); // optimization: use caching with object keys
skipWS(src);
eatChar(src, 58);
eatChar(src, 58); // ":"
skipWS(src);
// use caching with GeoJSON "type" params
o[key] = key == 'type' && src.peek() == DQUOTE ?
readKey(src) : readValue(src);
c = readAorB(src, COMMA, RBRACE);
if ((key == 'features' || key == 'geometries') &&
src.peek() == LBRACK && cb) {
readCollectionArray(src, cb);
o[key] = null;
} else if (key == 'type' && src.peek() == DQUOTE) {
o[key] = readKeywordString(src); // use caching with GeoJSON "type" params
} else {
o[key] = readValue(src);
}
c = scanForAorB(src, COMMA, RBRACE);
}
return o;
}
Expand All @@ -28287,7 +28355,7 @@ ${svg}
// Uses caching to speed up parsing of repeated strings.
// The caching scheme used here can give a 20% overall speed improvement
// when parsing files consisting mostly of attribute data (e.g. typical Point features)
function readKey(src) {
function readKeywordString(src) {
var MAXLEN = 2000; // must be less than RESERVE
var i = src.index();
var cache = src.cache;
Expand Down Expand Up @@ -28532,21 +28600,12 @@ ${svg}
// @reader: a FileReader
function GeoJSONReader(reader) {

// Read objects synchronously, with callback
this.readObjects = function(onObject) {
// Search first x bytes of file for features|geometries key
// 300 bytes not enough... GeoJSON files can have additional non-standard properties, e.g. 'metadata'
// var bytesToSearch = 300;
var bytesToSearch = 5000;
var start = reader.findString('"features"', bytesToSearch) ||
reader.findString('"geometries"', bytesToSearch);
// Assume single Feature or geometry if collection not found
// (this works for ndjson files too)
var offset = start ? start.offset : 0;
T$1.start();
parseObjects(reader, offset, onObject);
// parseObjects_native(reader, offset, onObject);
var val = parseGeoJSON(reader, onObject);
// var val = parseGeoJSON_native(reader, onObject);
debug('Parse GeoJSON', T$1.stop());
return val;
};
}

Expand Down Expand Up @@ -28584,6 +28643,7 @@ ${svg}
function importGeoJSONFile(fileReader, opts) {
var importer = new GeoJSONParser(opts);
new GeoJSONReader(fileReader).readObjects(importer.parseObject);
// TODO: examine top-level objects, like crs
return importer.done();
}

Expand Down Expand Up @@ -28880,7 +28940,7 @@ ${svg}
}

return {
info: importInfo(obj.info || {}),
info: await importInfo(obj.info || {}),
layers: layers,
arcs: arcs
};
Expand Down Expand Up @@ -28920,8 +28980,10 @@ ${svg}
return arcs;
}

function importInfo(o) {
async function importInfo(o) {
if (o.crs_string) {
// load external files (e.g. epsg definitions) if needed in GUI
await initProjLibrary({crs: o.crs_string});
o.crs = parseCrsString(o.crs_string);
} else if (o.prj) {
o.crs = parsePrj(o.prj);
Expand Down Expand Up @@ -29068,7 +29130,7 @@ ${svg}
// don't import .dbf separately if .shp is present
if (replaceFileExtension(filename, 'shp') in cache) return false;
}
return type == 'text' || type == 'json' || type == 'shp' || type == 'dbf' || type == 'kml';
return type && !isAuxiliaryInputFileType(type);
});
}

Expand Down Expand Up @@ -45616,7 +45678,7 @@ ${svg}
});
}

var version = "0.6.93";
var version = "0.6.94";

// Parse command line args into commands and run them
// Function takes an optional Node-style callback. A Promise is returned if no callback is given.
Expand Down

0 comments on commit ddb4716

Please sign in to comment.