I have 2 geojson feature collections in leaflet. One of them is road and the other one is parcels. I want to calculate buffer for road and then intersect this buffer layer with parcels. How can I do this using turf.js and leaflet. I am a newby in both of them. I tried to write a little script but it does not work. Could you tell me what ı am doing wrong. Here is a little part of my code that I wrote so far:
var buffered = turf.buffer(road, road.width, {units: 'meters'});
var roadbuf = L.polygon(buffered, {style:myStyle}).addTo(mymap);
1 Answer 1
Try something like this.
var buffered = turf.buffer(road.toGeoJSON(), road.width, {units: 'meters'});
var roadbuf = L.polygon(buffered, {style:myStyle}).addTo(mymap);
A Leaflet layer is not quite the same thing as a Turf GeoJSON layer.
-
Thank you for answer but before I try it I recognized I could not load turf.js properly. How can I do that I looked at Github page and referenced link in script elements but it doesn't workuser51044– user510442017年12月05日 15:26:56 +00:00Commented Dec 5, 2017 at 15:26
-
Here is a demo selecting points. The polygon and rectangle use Turf, the circle does not. I use the CDN method instead of downloading it. gistechsolutions.com/leaflet/DEMO/Select/PolySelect.html Check the head section in the html. <script src="npmcdn.com/@turf/turf/turf.min.js"></script>Bill Chappell– Bill Chappell2017年12月05日 15:36:21 +00:00Commented Dec 5, 2017 at 15:36
-
it says road.toGeoJSON() is not a function ??user51044– user510442017年12月05日 15:51:01 +00:00Commented Dec 5, 2017 at 15:51
-
leafletjs.com/reference-1.2.0.html#polyline-togeojson It looks like road is not a leaflet layer, check the spelling/case, or a question of seeing the leaflet library. Can you show more code?Bill Chappell– Bill Chappell2017年12月05日 18:55:06 +00:00Commented Dec 5, 2017 at 18:55
-
See gis.stackexchange.com/questions/264268/… for working solution.Bill Chappell– Bill Chappell2017年12月05日 20:23:07 +00:00Commented Dec 5, 2017 at 20:23