Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports.stringify = stringify;

var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
// Matches sequences like '100 100' or '100 100 100'.
var tuples = new RegExp('^' + numberRegexp.source + '(\\s' + numberRegexp.source + '){1,}');
var tuples = new RegExp('^' + numberRegexp.source + '(\\s+' + numberRegexp.source + '){1,}');

/*
* Parse WKT and return GeoJSON.
Expand Down Expand Up @@ -74,8 +74,8 @@ function parse (input) {
} else if (elem === ',') {
pointer = [];
stack[stack.length - 1].push(pointer);
} else if (!elem.split(/\s/g).some(isNaN)) {
Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
} else if (!elem.split(/\s+/g).some(isNaN)) {
Array.prototype.push.apply(pointer, elem.split(/\s+/g).map(parseFloat));
} else {
return null;
}
Expand All @@ -97,9 +97,9 @@ function parse (input) {
if (pt === ',') {
list.push(item);
item = [];
} else if (!pt.split(/\s/g).some(isNaN)) {
} else if (!pt.split(/\s+/g).some(isNaN)) {
if (!item) item = [];
Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
Array.prototype.push.apply(item, pt.split(/\s+/g).map(parseFloat));
}
white();
}
Expand Down
16 changes: 16 additions & 0 deletions test/wellknown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,21 @@ test('wellknown', function(t) {
coordinates: [[[30, 10, 1], [10, 20, 2], [20, 40, 3], [40, 40, 4], [30, 10, 5]]]
});

// OGC SF WKT: the ordinate separator is one or more whitespace, so
// multiple spaces between ordinates denote the same geometry.
t.deepEqual(parse('POINT (1 2)'), parse('POINT (1 2)'));
t.deepEqual(parse('POINT (1 2)'), {
type: 'Point',
coordinates: [1, 2]
});
t.deepEqual(parse('LINESTRING (1 2, 3 4)'), {
type: 'LineString',
coordinates: [[1, 2], [3, 4]]
});
t.deepEqual(parse('POLYGON ((0 0, 1 0, 1 1, 0 0))'), {
type: 'Polygon',
coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]]]
});

t.end();
});
10 changes: 5 additions & 5 deletions wellknown.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports.stringify = stringify;

var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
// Matches sequences like '100 100' or '100 100 100'.
var tuples = new RegExp('^' + numberRegexp.source + '(\\s' + numberRegexp.source + '){1,}');
var tuples = new RegExp('^' + numberRegexp.source + '(\\s+' + numberRegexp.source + '){1,}');

/*
* Parse WKT and return GeoJSON.
Expand Down Expand Up @@ -75,8 +75,8 @@ function parse (input) {
} else if (elem === ',') {
pointer = [];
stack[stack.length - 1].push(pointer);
} else if (!elem.split(/\s/g).some(isNaN)) {
Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
} else if (!elem.split(/\s+/g).some(isNaN)) {
Array.prototype.push.apply(pointer, elem.split(/\s+/g).map(parseFloat));
} else {
return null;
}
Expand All @@ -98,9 +98,9 @@ function parse (input) {
if (pt === ',') {
list.push(item);
item = [];
} else if (!pt.split(/\s/g).some(isNaN)) {
} else if (!pt.split(/\s+/g).some(isNaN)) {
if (!item) item = [];
Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
Array.prototype.push.apply(item, pt.split(/\s+/g).map(parseFloat));
}
white();
}
Expand Down