question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New module @turf/polygon-slice

See original GitHub issue

New module ~@turf/slice~ @turf/polygon-slice, currently on slice branch

Contributions and comments are welcomed before we publish to TurfJS.

Example

var sliced = turf.polygonSlice(polygon, linestring);

Current fallbacks of PolyK

  • Linestring is limited to two segments
  • Coordinate precision is limited to a few decimal points.
  • Output & Input is a very strange array [x1 y1, x2, y2, …]

JSDocs

/**
 * Takes a {@link Polygon} and cuts it with a {@link Linestring}. Note the linestring must be a straight line (eg made of only two points).
 * Properties from the input polygon will be retained on output polygons. Internally uses [polyK](http://polyk.ivank.net/) to perform split.
 *
 * @name slice
 * @param {Feature<Polygon>} poly - single Polygon Feature
 * @param {Feature<LineString>} line - single Polyline Feature
 * @return {FeatureCollection<Polygon>} A FeatureCollection of polygons
 */

Input

image

Output

image

Benchmark

$ node bench.js
simple x 117,605 ops/sec ±0.57% (98 runs sampled)

CC: @Turfjs/ownership

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:38 (18 by maintainers)

github_iconTop GitHub Comments

6reactions
gdrouetcommented, Dec 29, 2017

Looking for this feature! It would be useful to split polygons that are too big.

2reactions
rowanwinscommented, Feb 1, 2018

Thanks for those links @alexgleith and your work on the module, will try and take a look this evening and see if I can find a clever way around it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced geospatial analysis - Turf.js
Takes one or more features and calculates the centroid using the mean of all vertices. This lessens the effect of small islands and...
Read more >
turf-polygon - npm
turf.polygon(rings, properties). Takes an array of LinearRings and optionally an Object with properties and returns a GeoJSON Polygon feature.
Read more >
@turf/line-slice-along | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Turf for Swift - Mapbox
A spatial analysis library written in Swift for native iOS, macOS, tvOS, watchOS, and Linux applications, ported from Turf.js.
Read more >
How to use the @turf/union function in @turf/union - Snyk
To help you get started, we've selected a few @turf/union examples, based on popular ways it is used in public projects. ; type:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found