Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

proj4

Package Overview
Dependencies
Maintainers
0
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proj4

Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations.

  • 2.15.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is proj4?

The proj4 npm package is a JavaScript library for performing cartographic projections and coordinate transformations. It allows you to convert geographic coordinates from one coordinate system to another, which is essential for mapping and GIS applications.

What are proj4's main functionalities?

Coordinate Transformation

This feature allows you to transform coordinates from one projection system to another. In this example, coordinates in WGS84 (EPSG:4326) are transformed to Web Mercator (EPSG:3857).

const proj4 = require('proj4');

// Define two coordinate systems
const firstProjection = 'EPSG:4326'; // WGS84
const secondProjection = 'EPSG:3857'; // Web Mercator

// Transform coordinates from WGS84 to Web Mercator
const coordinates = [12.4924, 41.8902]; // Longitude, Latitude for Rome, Italy
const transformedCoordinates = proj4(firstProjection, secondProjection, coordinates);
console.log(transformedCoordinates); // Output: [1389919.142, 5146592.928]

Defining Custom Projections

This feature allows you to define custom projections using Proj4 strings. In this example, a UTM projection is defined and used to transform UTM coordinates to WGS84.

const proj4 = require('proj4');

// Define a custom projection
const customProjection = '+proj=utm +zone=33 +ellps=WGS84 +datum=WGS84 +units=m +no_defs';

// Transform coordinates using the custom projection
const coordinates = [500000, 4649776.22482]; // UTM coordinates
const transformedCoordinates = proj4(customProjection, 'EPSG:4326', coordinates);
console.log(transformedCoordinates); // Output: [9.0, 42.0]

Batch Transformations

This feature allows you to perform batch transformations on an array of coordinates. In this example, coordinates for Rome, London, and Tokyo are transformed from WGS84 to Web Mercator.

const proj4 = require('proj4');

// Define two coordinate systems
const firstProjection = 'EPSG:4326'; // WGS84
const secondProjection = 'EPSG:3857'; // Web Mercator

// Batch transform an array of coordinates
const coordinatesArray = [
  [12.4924, 41.8902], // Rome
  [-0.1276, 51.5074], // London
  [139.6917, 35.6895] // Tokyo
];
const transformedArray = coordinatesArray.map(coords => proj4(firstProjection, secondProjection, coords));
console.log(transformedArray); // Output: [[1389919.142, 5146592.928], [-14273.880, 6711545.653], [15550447.354, 4258423.671]]

Other packages similar to proj4

FAQs

Package last updated on 23 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc