All Projects → proj4js → Proj4js

proj4js / Proj4js

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

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Proj4js

Cesium
An open-source JavaScript library for world-class 3D globes and maps 🌎
Stars: ✭ 8,095 (+493.04%)
Mutual labels:  gis, geospatial
Wq.app
💻📱 wq's app library: a JavaScript framework powering offline-first web & native apps for geospatial data collection, mobile surveys, and citizen science. Powered by Redux, React, Material UI and Mapbox GL.
Stars: ✭ 99 (-92.75%)
Mutual labels:  gis, geospatial
Geemap
A Python package for interactive mapping with Google Earth Engine, ipyleaflet, and folium
Stars: ✭ 959 (-29.74%)
Mutual labels:  gis, geospatial
Proj4.jl
Julia wrapper for the PROJ cartographic projections library
Stars: ✭ 23 (-98.32%)
Mutual labels:  gis, geospatial
Arctern
Stars: ✭ 94 (-93.11%)
Mutual labels:  gis, geospatial
Postgis
PostGIS spatial database extension to PostgreSQL [mirror]
Stars: ✭ 925 (-32.23%)
Mutual labels:  gis, geospatial
Urbansprawl
Open framework for calculating spatial urban sprawl indices and performing disaggregated population estimates using open data
Stars: ✭ 48 (-96.48%)
Mutual labels:  gis, geospatial
Go Geom
Package geom implements efficient geometry types for geospatial applications.
Stars: ✭ 456 (-66.59%)
Mutual labels:  gis, geospatial
Geocube
Tool to convert geopandas vector data into rasterized xarray data.
Stars: ✭ 87 (-93.63%)
Mutual labels:  gis, geospatial
Geotiff.io
Static website for viewing and analyzing GeoTIFF's in the browser
Stars: ✭ 53 (-96.12%)
Mutual labels:  gis, geospatial
Lpfmpoints
Evolution of LPFM Stations
Stars: ✭ 19 (-98.61%)
Mutual labels:  gis, geospatial
Geoscript Js
A JavaScript Implementation of GeoScript
Stars: ✭ 72 (-94.73%)
Mutual labels:  gis, geospatial
Agentmaps
Make social simulations on interactive maps with Javascript! Agent-based modeling for the web.
Stars: ✭ 822 (-39.78%)
Mutual labels:  gis, geospatial
Rlur
Shiny dashboard for Land Use Regression modelling
Stars: ✭ 8 (-99.41%)
Mutual labels:  gis, geospatial
Earthengine Py Notebooks
A collection of 360+ Jupyter Python notebook examples for using Google Earth Engine with interactive mapping
Stars: ✭ 807 (-40.88%)
Mutual labels:  gis, geospatial
Shapefile.jl
Parsing .shp files in Julia
Stars: ✭ 40 (-97.07%)
Mutual labels:  gis, geospatial
Orb
Types and utilities for working with 2d geometry in Golang
Stars: ✭ 378 (-72.31%)
Mutual labels:  gis, geospatial
Mapsui
Mapsui is a .NET Map component for WPF, Xamarin.Forms, Xamarin.Android, Xamarin.iOS and UWP
Stars: ✭ 447 (-67.25%)
Mutual labels:  gis, geospatial
3d Tiles
Specification for streaming massive heterogeneous 3D geospatial datasets 🌎
Stars: ✭ 1,054 (-22.78%)
Mutual labels:  gis, geospatial
Geotools
Official GeoTools repository
Stars: ✭ 1,109 (-18.75%)
Mutual labels:  gis, geospatial

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 (then known as PROJ.4) and GCTCP C (Archive) it is a part of the MetaCRS group of projects.

Installing

Depending on your preferences

npm install proj4
bower install proj4
component 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:

proj4(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.

var 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]]';
var secondProjection = "+proj=gnom +lat_0=90 +lon_0=0 +x_0=6300000 +y_0=6300000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
//I'm not going to redefine those two in latter examples.
proj4(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).

proj4(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.

proj4(firstProjection,secondProjection).forward([2,5]);
// [-2690666.2977344505, 3662659.885459918]
proj4(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:

proj4(firstProjection).forward([-71,41]);
// [242075.00535055372, 750123.32090043]
proj4(firstProjection).inverse([242075.00535055372, 750123.32090043]);
//[-71, 40.99999999999986]
//the 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:

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

or with an array

proj4.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

proj4('EPSG:4326');

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

  • 'EPSG:4326', which has the following alias
    • 'WGS84'
  • 'EPSG:4269'
  • 'EPSG:3857', which has the following aliases
    • 'EPSG:3785'
    • 'GOOGLE'
    • 'EPSG:900913'
    • 'EPSG:102113'

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:

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

Grid Based Datum Adjustments

To use +nadgrids= in a proj definition, first read your NTv2 .gsb file (e.g. from https://github.com/OSGeo/proj-datumgrid) into an ArrayBuffer, then pass it to proj4.nadgrid. E.g:

const buffer = fs.readFileSync('ntv2.gsb').buffer
proj4.nadgrid('key', buffer);

then use the given key in your definition, e.g. Grid Based Datum Adjustments.

TypeScript

TypeScript implementation was added to the DefinitelyTyped repository.

$ npm 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:

node_modules/.bin/grunt

To run node tests run:

npm test

To run node tests with coverage run:

npm test --coverage

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

node_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.:

node_modules/.bin/grunt build:tmerc
#includes transverse Mercator
node_modules/.bin/grunt build:lcc
#includes lambert conformal conic
node_modules/.bin/grunt build:omerc,moll
#includes oblique Mercator and Mollweide
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].