Remove difference between two Geojson layers using Turfjs
See original GitHub issueI’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 :
This is what I want to get:
Issue Analytics
- State:
- Created 7 years ago
- Comments:16 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.