Skip to content
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 7 commits into from
Aug 17, 2017
Merged

Simplify fix #903

merged 7 commits into from
Aug 17, 2017

Conversation

stebogit
Copy link
Collaborator

Fixes #555

  • used @turf/clean-coords (instead of suggested patch)
  • added (previously) failing tests.
  • extended support of any GeoJSON
  • refactored code, updated bench.js and test.js to current standard

- added tests from #555;
- extended input to GeoJSON;
- updated readme, bench and types;
/**
* http://turfjs.org/docs/#simplify
*/
declare function simplify(geojson: Geoms, tolerance?: number, highQuality?: boolean): Geoms;
Copy link
Member

@DenisCarriere DenisCarriere Aug 15, 2017

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.

Copy link
Member

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
Copy link
Member

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 👍

}
}
var type = feature.geometry.type;
// "unsimplyfiable" geometry types
Copy link
Member

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>"
],
Copy link
Member

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

tolerance = tolerance || 0.01;
highQuality = highQuality || false;

const simplified = simplify(geojson, tolerance, highQuality);
Copy link
Member

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!! 😄

Copy link
Member

@DenisCarriere DenisCarriere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@DenisCarriere DenisCarriere added this to the 4.7.0 milestone Aug 15, 2017
@DenisCarriere
Copy link
Member

DenisCarriere commented Aug 15, 2017

@stebogit Seems like this would benefit from having a mutate param since right now this module is stripping off any extra properties from the FeatureCollection or Features (ex: id, bbox or any custom properties).

We could include clone at the beginning and leverage geomEach to handle the simplify transformations.

@DenisCarriere
Copy link
Member

DenisCarriere commented Aug 15, 2017

Added test cases for bbox & id removal.

Failing:

  • bbox
  • id
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();
});

@DenisCarriere
Copy link
Member

@stebogit You'll have to take a lot at it again to see if everything is ok, I've done some pretty drastic changes.

@DenisCarriere DenisCarriere merged commit 03e8df3 into master Aug 17, 2017
@DenisCarriere DenisCarriere deleted the simplify-fix branch August 17, 2017 17:55
@stebogit
Copy link
Collaborator Author

It seems you got it all done @DenisCarriere 😜 👍

@DenisCarriere
Copy link
Member

Woot! 🤓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants