geosolutions-it/proj4js

Name: proj4js

Owner: GeoSolutions

Description: JavaScript library to transform coordinates from one coordinate system to another, including datum transformations

Forked from: proj4js/proj4js

Created: 2017-11-13 09:59:21.0

Updated: 2017-11-13 09:59:23.0

Pushed: 2017-12-14 11:06:56.0

Homepage: http://proj4js.org

Size: 4171

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

PROJ4JS Build Status

Proj4js is a JavaScript library to transform point coordinates from one coordinate system to another, including datum transformations. Originally a port of PROJ.4 and GCTCP C it is a part of the MetaCRS group of projects.

Installing

Depending on your preferences

install proj4
r install proj4
onent install proj4js/proj4js

or just manually grab the file proj4.js from the latest release's dist/ folder.

if you do not want to download anything, Proj4js is also hosted on cdnjs for direct use in your browser applications.

Using

the basic signature is:

4(fromProjection[, toProjection, coordinates])

Projections can be proj or wkt strings.

Coordinates may an object of the form {x:x,y:y} or an array of the form [x,y].

When all 3 arguments are given, the result is that the coordinates are transformed from projection1 to projection 2. And returned in the same format that they were given in.

firstProjection = '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]]';
secondProjection = "+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
m not going to redefine those two in latter examples.
4(firstProjection,secondProjection,[2,5]);
-2690666.2977344505, 3662659.885459918]

If only 1 projection is given then it is assumed that it is being projected from WGS84 (fromProjection is WGS84).

4(firstProjection,[-71,41]);
242075.00535055372, 750123.32090043]

If no coordinates are given an object with two methods is returned, its methods are forward which projects from the first projection to the second and inverse which projects from the second to the first.

4(firstProjection,secondProjection).forward([2,5]);
-2690666.2977344505, 3662659.885459918]
4(secondProjection,firstProjection).inverse([2,5]);
-2690666.2977344505, 3662659.885459918]

and as above if only one projection is given, it's assumed to be coming from wgs84

4(firstProjection).forward([-71,41]);
242075.00535055372, 750123.32090043]
4(firstProjection).inverse([242075.00535055372, 750123.32090043]);
71, 40.99999999999986]
e floating points to answer your question
Named Projections

If you prefer to define a projection as a string and reference it that way, you may use the proj4.defs method which can be called 2 ways, with a name and projection:

4.defs('WGS84', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");

or with an array

4.defs([

'EPSG:4326',
'+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees'],

'EPSG:4269',
'+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees'


you can then do

4('EPSG:4326');

instead of writing out the whole proj definition, by default proj4 has the following projections predefined:

defined projections can also be accessed through the proj4.defs function (proj4.defs('EPSG:4326')).

proj4.defs can also be used to define a named alias:

4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'));
TypeScript

TypeScript implementation was added to the DefinitelyTyped repository.

m install --save @types/proj4
Developing

to set up build tools make sure you have node and grunt-cli installed and then run npm install

to do the complete build and browser tests run

_modules/.bin/grunt

to run node tests run

test

to run node tests with coverage run

test --coverage

to create a build with only default projections (latlon and Mercator) run

_modules/.bin/grunt build

to create a build with only custom projections include a comma separated list of projections codes (the file name in 'lib/projections' without the '.js') after a colon, e.g.

_modules/.bin/grunt build:tmerc
ludes transverse Mercator
_modules/.bin/grunt build:lcc
ludes lambert conformal conic
_modules/.bin/grunt build:omerc,moll
ludes oblique Mercator and Mollweide

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.