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

New module proposal @turf/clean-coords #874

Closed
stebogit opened this issue Jul 29, 2017 · 5 comments
Closed

New module proposal @turf/clean-coords #874

stebogit opened this issue Jul 29, 2017 · 5 comments

Comments

@stebogit
Copy link
Collaborator

stebogit commented Jul 29, 2017

/**
 * Removes redundant coordinates from any GeoJSON Geometry.
 *
 * @name cleanCoords
 * @param {Geometry|Feature} geojson Feature or Geometry
 * @param {boolean} [mutate=false] allows GeoJSON input to be mutated
 * @returns {Geometry|Feature} the cleaned input Feature/Geometry
 * @example
 * var line = turf.lineString([[0, 0], [0, 2], [0, 5], [0, 8], [0, 8], [0, 10]]);
 * var multiPoint = turf.multiPoint([[0, 0], [0, 0], [2, 2]]);
 *
 * turf.cleanCoords(line).geometry.coordinates;
 * //= [[0, 0], [0, 10]]
 *
 * turf.cleanCoords(multiPoint).geometry.coordinates;
 * //= [[0, 0], [2, 2]]
 */
module.exports = function (geojson, mutate) {

Don't know if these coordinates are actually redundant (as in useless), but in some cases are definitely in the way, e.g. #869 or the new segmentEach/segmentReduce.
We can have this as a module, handling the feature, or as a helpers function, simply returning the cleaned coordinates array.

Looking forward for any suggestion.

@DenisCarriere
Copy link
Member

DenisCarriere commented Jul 29, 2017

Love it! Exactly what we need!

@stebogit
Copy link
Collaborator Author

Great! @DenisCarriere I'll work on the code in the weekend as well, for now was just a proposal to make sure it was acceptable

@DenisCarriere
Copy link
Member

I was going to propose the exact same thing at one point, sounds like a good module to help improve those boolean modules.

@rowanwins
Copy link
Member

My only comment @stebogit would be in relation to the name, im not sure that clean-coords is the best. My reading is that the module removes redundant vertices, I'd perhaps name it something more along those lines. IMHO cleaning implies other things might be done like trimming precision or removing coords outside a valid a range.

@stebogit
Copy link
Collaborator Author

stebogit commented Aug 1, 2017

Implemented with #875

@stebogit stebogit closed this as completed Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants