What is @turf/projection?
@turf/projection is a module within the Turf.js library that provides functionality for projecting geographical coordinates. It allows for the conversion of coordinates between different coordinate reference systems (CRS), which is essential for various geospatial analyses and visualizations.
What are @turf/projection's main functionalities?
toMercator
Converts a GeoJSON object from geographic coordinates (longitude, latitude) to Mercator (x, y) coordinates.
const turf = require('@turf/turf');
const point = turf.point([-75.343, 39.984]);
const projected = turf.toMercator(point);
console.log(projected);
toWgs84
Converts a GeoJSON object from Mercator (x, y) coordinates to geographic coordinates (longitude, latitude).
const turf = require('@turf/turf');
const point = turf.point([0, 0]);
const projected = turf.toWgs84(point);
console.log(projected);
Other packages similar to @turf/projection
proj4
Proj4 is a JavaScript library for converting coordinates between different coordinate reference systems. It is highly versatile and supports a wide range of projections. Compared to @turf/projection, proj4 offers more extensive support for various CRS and is often used in more complex geospatial applications.
@turf/projection
toMercator
Converts a WGS84 GeoJSON object into Mercator (EPSG:900913) projection
Parameters
Examples
var pt = turf.point([-71,41]);
var converted = turf.toMercator(pt);
var addToMap = [pt, converted];
Returns GeoJSON Projected GeoJSON
toWgs84
Converts a Mercator (EPSG:900913) GeoJSON object into WGS84 projection
Parameters
Examples
var pt = turf.point([-7903683.846322424, 5012341.663847514]);
var converted = turf.toWgs84(pt);
var addToMap = [pt, converted];
Returns GeoJSON Projected GeoJSON
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Installation
Install this single module individually:
$ npm install @turf/projection
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf