Skip to content

Commit

Permalink
3.7.2 - make simplify actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
yocontra committed Apr 16, 2019
1 parent fc94ceb commit cbadc78
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion dist/util/geo/simplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.default = (geometry, { tolerance = 0.00001 } = {}) => {
if (type === 'LineString' && coordinates.length === 2 && (0, _lodash.isEqual)(coordinates[0], coordinates[1])) {
throw new Error('Invalid LineString! Only two coordinates that are identical.');
}
const res = (0, _turf.simplify)(geometry, { tolerance });
const res = (0, _turf.simplify)((0, _turf.cleanCoords)((0, _turf.truncate)(geometry, { precision: 6, coordinates: 3 })), { tolerance });
return Object.assign({
type
}, rest, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vandelay-util",
"version": "3.7.1",
"version": "3.7.2",
"description": "Grab bag of utilities for vandelay transform functions",
"main": "dist/index.js",
"keywords": [],
Expand Down
6 changes: 4 additions & 2 deletions src/util/geo/simplify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { simplify } from '@turf/turf'
import { simplify, truncate, cleanCoords } from '@turf/turf'
import { isEqual } from 'lodash'

// 1 = 69 miles
Expand All @@ -16,7 +16,9 @@ export default (geometry, { tolerance=0.00001 }={}) => {
if (type === 'LineString' && coordinates.length === 2 && isEqual(coordinates[0], coordinates[1])) {
throw new Error('Invalid LineString! Only two coordinates that are identical.')
}
const res = simplify(geometry, { tolerance })
const res = simplify(
cleanCoords(truncate(geometry, { precision: 6, coordinates: 3 }))
, { tolerance })
return {
type,
...rest,
Expand Down
61 changes: 31 additions & 30 deletions test/geo/simplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,38 +85,39 @@ describe('geo#simplify', () => {
}
const expected = {
type: 'LineString',
coordinates: [ [ -79.808996, 36.070662 ],
[ -79.80891, 36.070629999999994 ],
[ -79.809, 36.070499999999996 ],
[ -79.80912000000001, 36.07018 ],
[ -79.80922000000001, 36.07003 ],
[ -79.80940000000001, 36.06989 ],
[ -79.81016000000001, 36.07001 ],
[ -79.81026000000001, 36.06989 ],
coordinates: [
[ -79.808996, 36.070662 ],
[ -79.80891, 36.07063 ],
[ -79.809, 36.0705 ],
[ -79.80912, 36.07018 ],
[ -79.80922, 36.07003 ],
[ -79.8094, 36.06989 ],
[ -79.81016, 36.07001 ],
[ -79.81026, 36.06989 ],
[ -79.8104, 36.06962 ],
[ -79.81048, 36.06933 ],
[ -79.81061, 36.069019999999995 ],
[ -79.81062, 36.068889999999996 ],
[ -79.81076, 36.06858999999999 ],
[ -79.81078000000001, 36.06844999999999 ],
[ -79.811, 36.068369999999994 ],
[ -79.81137000000001, 36.068389999999994 ],
[ -79.81151000000001, 36.06842999999999 ],
[ -79.81168000000001, 36.06844999999999 ],
[ -79.81184, 36.06844999999999 ],
[ -79.81201, 36.06841999999999 ],
[ -79.8124, 36.068409999999986 ],
[ -79.81239, 36.06853999999999 ],
[ -79.81258, 36.067519999999995 ],
[ -79.81258, 36.067389999999996 ],
[ -79.81264000000002, 36.06692999999999 ],
[ -79.81267000000003, 36.066419999999994 ],
[ -79.81266000000002, 36.06565999999999 ],
[ -79.81269000000002, 36.065519999999985 ],
[ -79.81307000000002, 36.06543999999999 ],
[ -79.81357000000003, 36.065299999999986 ],
[ -79.81380000000003, 36.06527999999999 ],
[ -79.81423000000002, 36.06533999999999 ] ]
[ -79.81061, 36.06902 ],
[ -79.81062, 36.06889 ],
[ -79.81076, 36.06859 ],
[ -79.81078, 36.06845 ],
[ -79.811, 36.06837 ],
[ -79.81137, 36.06839 ],
[ -79.81151, 36.06843 ],
[ -79.81168, 36.06845 ],
[ -79.81184, 36.06845 ],
[ -79.81201, 36.06842 ],
[ -79.8124, 36.06841 ],
[ -79.81239, 36.06854 ],
[ -79.81258, 36.06752 ],
[ -79.81258, 36.06739 ],
[ -79.81264, 36.06693 ],
[ -79.81267, 36.06642 ],
[ -79.81266, 36.06566 ],
[ -79.81269, 36.06552 ],
[ -79.81307, 36.06544 ],
[ -79.81357, 36.0653 ],
[ -79.8138, 36.06528 ],
[ -79.81423, 36.06534 ] ]
}
util.geo.simplify(src).should.eql(expected)
util.geo.simplify(expected).should.eql(expected)
Expand Down

0 comments on commit cbadc78

Please sign in to comment.