0.0.1 • Published 7 months ago

reproject-line v0.0.1

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
7 months ago

reproject-line

smart line reprojection

install

npm install reproject-line

basic usage

import proj4 from "proj4-fully-loaded";
import reproject_line from "reproject-line";

// reproject line from UTM to Lat/Lng
const reproject = proj4("EPSG:4326", "EPSG:32610").forward;

const line = [
  [-119.016667, 35.366667], // Bakersfield, CA
  [-119.766667, 36.75], // Fresno, CA, USA
];

reproject_line(line, reproject);
[
  [861953.7586231146,3920995.6805079672], // Bakersfield in UTM
  [788672.26444508,4072016.1098799286] // Fresno in UTM
]

advanced usage

point densification

number of points

You can also increase the number of vertices in each line segment before reprojection.

// adds 3 points to every line segment
reproject_line(line, reproject, { densify: 3 });

strategy

By default, reproject-line takes an "optimal" approach of only adding vertices if they are necessary, in other words, only adding if the line segment bends when reprojected. If you would like to add points to each line segment regardless of whether it's still straight when reprojected, pass strategy: "always"

// always add 3 point to each line segment even if unnecessary
reproject_line(line, reproject, { densify: 3, strategy: "always" });