项目作者: DanielJDufour

项目描述 :
Reproject a Bounding Box
高级语言: JavaScript
项目地址: git://github.com/DanielJDufour/reproject-bbox.git
创建时间: 2021-05-17T15:42:50Z
项目社区:https://github.com/DanielJDufour/reproject-bbox

开源协议:Creative Commons Zero v1.0 Universal

下载


reproject-bbox

Reproject a Bounding Box

install

  1. npm install reproject-bbox

basic usage

  1. import reprojectBoundingBox from "reproject-bbox";
  2. const bbox = reprojectBoundingBox({
  3. bbox: [ -122.51, 40.97, -122.34, 41.11 ],
  4. // spatial reference system of input bounding box
  5. from: 4326,
  6. // convert bounding box to this spatial reference system
  7. to: 3857
  8. });
  9. // bbox is [-13637750.817083945, 5007917.677222896, -13618826.503649088, 5028580.202823918]

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.

  1. import reprojectBoundingBox from "reproject-bbox";
  2. // example WKT and PROJ4 Strings from http://proj4js.org/
  3. reprojectBoundingBox({
  4. bbox,
  5. 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]]',
  6. to: "+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
  7. });

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.

  1. import reprojectBoundingBox from "reproject-bbox";
  2. const bbox = [ -2316545, -1971615, 1015455, 1512385 ];
  3. reprojectBoundingBox({
  4. bbox,
  5. density: 100, // add 100 points to each side of the box before reprojecting
  6. from: 6623,
  7. to: 4326
  8. });
  9. reprojectBoundingBox({
  10. bbox,
  11. // add 11 points along the x-axis (11 to top side and 11 to bottom side)
  12. // and 99 points along the y-axis (99 to left side and 99 to right side)
  13. density: [11, 99],
  14. from: 6623,
  15. to: 4326
  16. });

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.

  1. reprojectBoundingBox({
  2. bbox,
  3. from: 3857,
  4. split: false, // turn off automatic splitting
  5. to: 4326
  6. })

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.