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.

Remove difference between two Geojson layers using Turfjs

See original GitHub issue

I’ve draw line programmatically (not using leaflet draw) inside polygone using leaflet draw plugin on map, I want to keep only the points of polyline that are inside of polygone and remove those are outside. Using difference method of Turfsjs library, I can get the “difference” layer between the polygon and line, now I want to remove the difference between this layers from map and keep only the polygone and part of line that is inside the polygon. Any help is much appreciated. Thank you. Here is a code snippet:

var line = path.toGeoJSON();
var polygon = selectedPoly.toGeoJSON();
var difference
var result = []
var difference = turf.difference(line, polygon)
var if (difference) {
  result.push(difference)
  var inter = L.geoJson(result).addTo(map);
}

Here is a screenshot of difference method : capturedifference

This is what I want to get: capturebefore

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
rowanwinscommented, Mar 6, 2017

Hi @marie15 , please be aware that both @DenisCarriere & myself maintain this repo in our spare time so please be patient, we will provide support when we can.

1reaction
rowanwinscommented, Mar 5, 2017

Hi @marie15 - turf will not do things like remove the old parts of the polygon from the map, turf does not tied to any particular mapping library (eg leaflet or open layers) etc, it only concerns itself with spatial operations on geojson.

As suggested above a jsfiddle might help us give you the best assistance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced geospatial analysis - Turf.js
GeoJSON - layer with truncated geometry ... Finds the difference between two polygons by clipping the second polygon from ... npm install @turf/difference...
Read more >
Removing intersection of GeoJSON Multipolygons with ...
In this post, I'll show you how to use Turf.js functions to remove the overlap of multiple multipolygons so that you're left with...
Read more >
TurfJs union - How to ignore point which are inside but with ...
If your result is invalid geojson then using a buffer of 0 should cleanse the geometry (remove the points/lines in the middle).
Read more >
Advance spatial analysis in leaflet | turf | tekson - YouTube
Hello, guys, this is the video about advance spatial analysis with turfjs. Turfjs is the open-source javascript library widely used on the ...
Read more >
Analyze data with Turf.js and Mapbox GL JS | Help
As mentioned above, this example uses two data files: libraries and hospitals in Lexington, KY, each of them is a GeoJSON FeatureCollection. In...
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