reproject-bbox
Reproject a Bounding Box
install
npm install reproject-bbox
basic usage
import reprojectBoundingBox from "reproject-bbox";
const bbox = reprojectBoundingBox({
bbox: [ -122.51, 40.97, -122.34, 41.11 ],
from: 4326,
to: 3857
});
advanced usage
well-known text
Because reproject-bbox passes the from
and to
parameters to proj4js and proj4js supports
Well-Known Text,
you can also pass WKT strings and Proj4JS strings in place of EPSG Codes.
import reprojectBoundingBox from "reproject-bbox";
reprojectBoundingBox({
bbox,
from: 'PROJCS["NAD83 / Massachusetts Mainland",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],UNIT["metre",1,AUTHORITY["EPSG","9001"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",42.68333333333333],PARAMETER["standard_parallel_2",41.71666666666667],PARAMETER["latitude_of_origin",41],PARAMETER["central_meridian",-71.5],PARAMETER["false_easting",200000],PARAMETER["false_northing",750000],AUTHORITY["EPSG","26986"],AXIS["X",EAST],AXIS["Y",NORTH]]',
to: "+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
});
density
You can increase the accuracy of your reprojected bounding box by increasing the point density.
Density is the number of points that you would like to add to each side of the bounding box.
If you pass in an array of two numbers, you can control how many points to add along the x and y-axis.
import reprojectBoundingBox from "reproject-bbox";
const bbox = [ -2316545, -1971615, 1015455, 1512385 ];
reprojectBoundingBox({
bbox,
density: 100,
from: 6623,
to: 4326
});
reprojectBoundingBox({
bbox,
density: [11, 99],
from: 6623,
to: 4326
});
split
reproject-bbox will automatically split bounding boxes where x=0 and y=0 before reprojecting and merging them back together. This can greatly improve accuracy for certain projections, especially ones around the poles. However, if you really want to turn it off, you can.
reprojectBoundingBox({
bbox,
from: 3857,
split: false,
to: 4326
})
proj4-fully-loaded dependency
This library depends on proj4-fully-loaded.
If proj4-fully-loaded isn't found (perhaps because you used null-loader, then reproject-bbox will attempt to look for a valid proj4 at window.proj4.
lite
If you are looking for a lighter library without as many dependencies, check out bbox-fns.