3

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);
ahmadhanb
41.8k5 gold badges55 silver badges110 bronze badges
asked Dec 4, 2017 at 23:04

1 Answer 1

3

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.

IvanSanchez
10.4k2 gold badges21 silver badges35 bronze badges
answered Dec 5, 2017 at 2:40
5
  • 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 work Commented 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> Commented Dec 5, 2017 at 15:36
  • it says road.toGeoJSON() is not a function ?? Commented 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? Commented Dec 5, 2017 at 18:55
  • See gis.stackexchange.com/questions/264268/… for working solution. Commented Dec 5, 2017 at 20:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.