-
Notifications
You must be signed in to change notification settings - Fork 953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify fix #903
Merged
Merged
Simplify fix #903
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7fc4aaa
implements all original tests
stebogit 3d3c6b1
completed refactor:
stebogit b360f9b
Merge branch 'master' into simplify-fix
stebogit e18785d
Update typescript definition
DenisCarriere 3b339d9
Add failing tests (strips id & bbox)
DenisCarriere d45b250
Update bbox/id test
DenisCarriere b815e2d
Refactor to support mutate param
DenisCarriere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
implements all original tests
- Loading branch information
commit 7fc4aaa41dd731019306b864b3efae3002a7d797
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,36 @@ | ||
var simplify = require('./'); | ||
var test = require('tape'); | ||
var fs = require('fs'); | ||
|
||
test('simplify -- line', function (t) { | ||
var line = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/in/linestring.geojson')); | ||
|
||
var simplified = simplify(line, 0.01, false); | ||
t.ok(simplified); | ||
t.equal(simplified.type, 'Feature'); | ||
t.equal(typeof simplified.geometry.coordinates[0][0], 'number'); | ||
fs.writeFileSync(__dirname + '/test/fixtures/out/linestring_out.geojson', JSON.stringify(simplified, null, 2)); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('simplify -- multiline', function (t) { | ||
var multiline = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/in/multilinestring.geojson')); | ||
|
||
var simplified = simplify(multiline, 0.01, false); | ||
t.ok(simplified); | ||
t.equal(simplified.type, 'Feature'); | ||
var len = multiline.geometry.coordinates.length, | ||
i; | ||
for (i = 0; i < len; i++) { | ||
t.equal(typeof simplified.geometry.coordinates[i][0][0], 'number'); | ||
} | ||
fs.writeFileSync(__dirname + '/test/fixtures/out/multilinestring_out.geojson', JSON.stringify(simplified, null, 2)); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('simplify -- polygon', function (t) { | ||
var polygon = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/in/polygon.geojson')); | ||
|
||
var simplified = simplify(polygon, 1, false); | ||
t.equal(simplified.type, 'Feature'); | ||
t.equal(typeof simplified.geometry.coordinates[0][0][0], 'number'); | ||
fs.writeFileSync(__dirname + '/test/fixtures/out/polygon_out.geojson', JSON.stringify(simplified, null, 2)); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('simplify -- over simplify polygon', function (t) { | ||
var polygon = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/in/simple.geojson')); | ||
|
||
var simplified = simplify(polygon, 100, false); | ||
t.equal(simplified.type, 'Feature'); | ||
t.equal(typeof simplified.geometry.coordinates[0][0][0], 'number'); | ||
fs.writeFileSync(__dirname + '/test/fixtures/out/simple_out.geojson', JSON.stringify(simplified, null, 2)); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('simplify -- multipolygon', function (t) { | ||
var multipolygon = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/in/multipolygon.geojson')); | ||
|
||
var simplified = simplify(multipolygon, 0.01, false); | ||
t.equal(simplified.type, 'Feature'); | ||
var len = multipolygon.geometry.coordinates.length, | ||
i; | ||
for (i = 0; i < len; i++) { | ||
t.equal(typeof simplified.geometry.coordinates[i][0][0][0], 'number'); | ||
} | ||
fs.writeFileSync(__dirname + '/test/fixtures/out/multipolygon_out.geojson', JSON.stringify(simplified, null, 2)); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('simplify -- featurecollection', function (t) { | ||
var featurecollection = JSON.parse((fs.readFileSync(__dirname + '/test/fixtures/in/featurecollection.geojson'))); | ||
|
||
var simplified = simplify(featurecollection, 0.01, false); | ||
t.equal(simplified.type, 'FeatureCollection'); | ||
|
||
fs.writeFileSync(__dirname + '/test/fixtures/out/featurecollection_out.geojson', JSON.stringify(simplified, null, 2)); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('simplify -- geometrycollection', function (t) { | ||
var geometrycollection = JSON.parse((fs.readFileSync(__dirname + '/test/fixtures/in/geometrycollection.geojson'))); | ||
|
||
var simplified = simplify(geometrycollection, 0.01, false); | ||
t.equal(simplified.type, 'GeometryCollection'); | ||
simplified.geometries.forEach(function (g) { | ||
if (g.type === 'LineString') { | ||
t.equal(typeof g.coordinates[0][0], 'number'); | ||
} else if (g.type === 'MultiLineString' || g.type === 'Polygon') { | ||
// intentionally only checking the first line for multilinestring, test covered elsewhere | ||
t.equal(typeof g.coordinates[0][0][0], 'number'); | ||
} else if (g.type === 'MultiPolygon') { | ||
// intentionally only checking the first ring, test covered elsewhere | ||
t.equal(typeof g.coordinates[0][0][0][0], 'number'); | ||
const fs = require('fs'); | ||
const test = require('tape'); | ||
const path = require('path'); | ||
const load = require('load-json-file'); | ||
const write = require('write-json-file'); | ||
const {point, lineString, geometryCollection, featureCollection} = require('@turf/helpers'); | ||
const simplify = require('./'); | ||
|
||
const directories = { | ||
in: path.join(__dirname, 'test', 'in') + path.sep, | ||
out: path.join(__dirname, 'test', 'out') + path.sep | ||
}; | ||
|
||
const fixtures = fs.readdirSync(directories.in).map(filename => { | ||
return { | ||
filename, | ||
name: path.parse(filename).name, | ||
geojson: load.sync(directories.in + filename) | ||
}; | ||
}); | ||
|
||
test('simplify', t => { | ||
for (const {filename, name, geojson} of fixtures) { | ||
let {tolerance, highQuality} = geojson.properties || {}; | ||
tolerance = tolerance || 0.01; | ||
highQuality = highQuality || false; | ||
|
||
const simplified = simplify(geojson, tolerance, highQuality); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests look so much nicer now!! 😄 |
||
// const result = featureCollection([simplified, geojson]); | ||
|
||
if (process.env.REGEN) write.sync(directories.out + filename, simplified); | ||
t.deepEqual(simplified, load.sync(directories.out + filename), name); | ||
} | ||
}); | ||
|
||
fs.writeFileSync(__dirname + '/test/fixtures/out/geometrycollection_out.geojson', JSON.stringify(simplified, null, 2)); | ||
|
||
t.end(); | ||
}); | ||
|
||
test('simplify -- argentina', function (t) { | ||
var argentina = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/in/argentina.geojson')); | ||
|
||
var simplified = simplify(argentina, 0.1, false); | ||
t.equal(simplified.type, 'Feature'); | ||
t.equal(typeof simplified.geometry.coordinates[0][0][0], 'number'); | ||
fs.writeFileSync(__dirname + '/test/fixtures/out/argentina_out.geojson', JSON.stringify(simplified, null, 2)); | ||
|
||
t.end(); | ||
t.end(); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try including past contributors to this list when updating modules (@tmcw was heavily involved in the initial development of this module).
Click the history button on the
index.js
file./~https://github.com/Turfjs/turf/commits/b360f9beeec921c38468062fce893158e4a84988/packages/turf-simplify/index.js