Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get bounding box based on distance from given point?

I need restrict map area to 5km radius around given point. How can I get appropriate bounding box using mapbox-gl-js or turf?

like image 999
Rantiev Avatar asked Jul 05 '17 14:07

Rantiev


People also ask

How do you find the bounding box of a city?

You can find the bounding box of those cities at www.mapdevelopers.com/geocode_bounding_box.php. Entering a city will display a box on a map and give the latitude and longitude of each side. Hopefully that will give you the information you need.

How do you find the bounding box of a triangle?

To find the bounds of the box containing a triangle, you simply need to find the smallest and largest x and y coordinates from the three coordinates making up the triangle.


2 Answers

You can use http://turfjs.org/docs/#buffer to get a feature in size of the radius that you want and then use http://turfjs.org/docs/#bbox to get the bbox.

var point = turf.point([-90.548630, 14.616599]);
var buffered = turf.buffer(point, 5, {units:'kilometers'});
var bbox = turf.bbox(buffered);
console.log(turf.bboxPolygon(bbox));
<script src="https://npmcdn.com/@turf/turf/turf.min.js"></script>
like image 94
Andi-lo Avatar answered Oct 13 '22 02:10

Andi-lo


Buffer API has changed. Buffer's optional argument needs to be an object like so:

var point = turf.point([-90.548630, 14.616599]);
var buffered = turf.buffer(point, 5, {units:'kilometers'}); /// notice 'units'
var bbox = turf.bbox(buffered);
console.log(turf.bboxPolygon(bbox));
like image 44
mbejda Avatar answered Oct 13 '22 01:10

mbejda