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.

Question about additional functionality related to lineToPolygon function

See original GitHub issue

Hi guys, Thank you for this awesome library!

I would like to ask you one question regarding converting line to polygon. I’m using lineToPolygon function and it works like a charm. But I need more functionality.

For example, I have one complex line, something like this, which was converted to polygon via lineToPolygon function:

photo_2020-04-05_11-01-21

There is a lot of lines and shapes within polygon, which are part of this polygon. And I need to reduce it to avoid drawing unnecessary lines and make a correct searching inside it.

So the question is: Does Turf have functionality to detect crossed lines within polygon, remove these lines and make polygon like on the next screenshot?

photo_2020-04-05_11-01-28

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rowanwinscommented, Apr 5, 2020

Brilliant solution @stebogit , so elegant!

2reactions
stebogitcommented, Apr 5, 2020

@alexeyvax if I understand correctly what you want to do, I think you could do something like this, where I destructured the line into points and generated a concave polygon out of them:

function toPoints (features) {
  const points = [];
  turf.coordEach(features, function (currentCoord) {
    points.push(turf.point(turf.getCoords(currentCoord)));
  }, {excludeWrapCoord: true});
  return turf.featureCollection(points);
}

const hull = turf.concave(toPoints(data));
Screen Shot 2020-04-05 at 9 49 05 AM Screen Shot 2020-04-05 at 9 48 45 AM
Read more comments on GitHub >

github_iconTop Results From Across the Web

Splitting a polygon by multiple linestrings leaflet and turf.js
This is done in two steps. First step is to 'fatten' dividing line to one side, cut polygon by it and take into...
Read more >
Combine feature collection into polygon turfjs - Stack Overflow
Just use turfs http://turfjs.org/docs/#lineToPolygon which Converts (Multi)LineString(s) to Polygon(s).
Read more >
simplepolygon - Cesium Documentation
Returns: Feature collection containing the simple, non-self-intersecting one-ring polygon features that the complex polygon is composed of. These simple ...
Read more >
Advanced geospatial analysis - Turf.js
Takes two (Multi)Polygon(s) and returns a combined polygon. If the input polygons are not contiguous, this function returns a MultiPolygon feature. Arguments ...
Read more >
(PDF) Extended Web Direction Service to Avoid Obstacle on ...
However, most web routing service platforms cannot add points or areas to ... A set of spatial analysis functions in Turf.js was used...
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