-
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
Simplify fix #903
Conversation
- added tests from #555; - extended input to GeoJSON; - updated readme, bench and types;
packages/turf-simplify/index.d.ts
Outdated
/** | ||
* http://turfjs.org/docs/#simplify | ||
*/ | ||
declare function simplify(geojson: Geoms, tolerance?: number, highQuality?: boolean): Geoms; |
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.
This isn't correct, the ): Geoms
is saying that the output is FeatureCollection/Feature/Geometry when in fact it should be the same as the Input defined in Geoms.
The previous definition was a mess! :)
But here's an updated one:
declare function simplify<T extends Geoms>(
geojson: T,
tolerance?: number,
highQuality?: boolean): T;
Which means whatever you enter as T
will be the same for the output.
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.
Another catch would be to include more robust Typescript testing in types.ts.
One day I'll write a guide for using Typescript with TurfJS
This would fail:
import {polygon, Polygon} from '@turf/helpers'
import * as simplify from './'
const poly = polygon([[[0, 0], [10, 10], [20, 20], [0, 0]]]);
const simplifiedPoly: Polygon = simplify(poly);
With the following error:
[ts]
Type 'Geoms' is not assignable to type 'Feature<Polygon>'.
Type 'GeometryObject' is not assignable to type 'Feature<Polygon>'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"Feature"'.
* | ||
* @name simplify | ||
* @param {Feature<(LineString|Polygon|MultiLineString|MultiPolygon)>|FeatureCollection|GeometryCollection} feature feature to be simplified | ||
* @param {GeoJSON} geojson object to be simplified |
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.
Way better to support all GeoJSON types 👍
packages/turf-simplify/index.js
Outdated
} | ||
} | ||
var type = feature.geometry.type; | ||
// "unsimplyfiable" geometry types |
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.
👍 Agreed
@@ -22,16 +22,23 @@ | |||
"simplify" | |||
], | |||
"author": "Turf Authors", | |||
"contributors": [ | |||
"Stefano Borghi <@stebogit>" | |||
], |
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
packages/turf-simplify/test.js
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
These tests look so much nicer now!! 😄
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.
Looks great!
@stebogit Seems like this would benefit from having a We could include |
Added test cases for Failing:
test('simplify -- removes ID & BBox from properties', t => {
const properties = {foo: 'bar'};
const id = 12345;
const bbox = [0, 0, 2, 2];
const poly = polygon([[[0, 0], [2, 2], [2, 0], [0, 0]]], properties, bbox, id);
const simple = simplify(poly, 0.1);
t.equal(simple.id, id);
t.deepEqual(simple.bbox, bbox);
t.deepEqual(simple.properties, properties);
t.end();
}); |
@stebogit You'll have to take a lot at it again to see if everything is ok, I've done some pretty drastic changes. |
It seems you got it all done @DenisCarriere 😜 👍 |
Woot! 🤓 |
Fixes #555
@turf/clean-coords
(instead of suggested patch)bench.js
andtest.js
to current standard