How to use the proj4.Proj function in proj4

To help you get started, we’ve selected a few proj4 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / proj4 / proj4-tests.ts View on Github external
///////////////////////////////////
proj4.defs('WGS84', epsg['4326'])
proj4.defs([
  ['EPSG:4326', epsg['4326']],
  ['EPSG:4269', epsg['4269']]
])
proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326'))

///////////////////////////////////
// Utils
///////////////////////////////////
// WGS84
proj4.WGS84

// Proj
proj4.Proj('WGS84')

// toPoint
proj4.toPoint([1, 2])
proj4.toPoint([1, 2, 3])
proj4.toPoint([1, 2, 3, 4])

// Point
// WARNING: Deprecated in v3
proj4.Point([1, 2, 3, 4])
github OpenGeoscience / geojs / src / transform.js View on Github external
transform.transformCoordinatesFlatArray3 = function (srcPrj, tgtPrj, coordinates) {
  'use strict';

  var i,
      smatch = srcPrj.match(axisPattern),
      tmatch = tgtPrj.match(axisPattern);
  // if the two projections only differ in the middle axis
  if (smatch && tmatch && smatch[1] === tmatch[1] && smatch[3] === tmatch[3]) {
    for (i = coordinates.length - 3 + 1; i >= 0; i -= 3) {
      coordinates[i] *= -1;
    }
    return coordinates;
  }
  var src = proj4.Proj(srcPrj),
      tgt = proj4.Proj(tgtPrj),
      projPoint, initPoint = {};
  for (i = coordinates.length - 3; i >= 0; i -= 3) {
    initPoint.x = +coordinates[i];
    initPoint.y = +coordinates[i + 1];
    initPoint.z = +(coordinates[i + 2] || 0.0);
    projPoint = proj4.transform(src, tgt, initPoint);
    coordinates[i] = projPoint.x;
    coordinates[i + 1] = projPoint.y;
    coordinates[i + 2] = projPoint.z === undefined ? initPoint.z : projPoint.z;
  }
  return coordinates;
};
github OpenGeoscience / geojs / src / transform.js View on Github external
transform.transformCoordinatesFlatArray3 = function (srcPrj, tgtPrj, coordinates) {
  'use strict';

  var i,
      smatch = srcPrj.match(axisPattern),
      tmatch = tgtPrj.match(axisPattern);
  // if the two projections only differ in the middle axis
  if (smatch && tmatch && smatch[1] === tmatch[1] && smatch[3] === tmatch[3]) {
    for (i = coordinates.length - 3 + 1; i >= 0; i -= 3) {
      coordinates[i] *= -1;
    }
    return coordinates;
  }
  var src = proj4.Proj(srcPrj),
      tgt = proj4.Proj(tgtPrj),
      projPoint, initPoint = {};
  for (i = coordinates.length - 3; i >= 0; i -= 3) {
    initPoint.x = +coordinates[i];
    initPoint.y = +coordinates[i + 1];
    initPoint.z = +(coordinates[i + 2] || 0.0);
    projPoint = proj4.transform(src, tgt, initPoint);
    coordinates[i] = projPoint.x;
    coordinates[i + 1] = projPoint.y;
    coordinates[i + 2] = projPoint.z === undefined ? initPoint.z : projPoint.z;
  }
  return coordinates;
};
github perliedman / gis-nerd-tools / src / projections.js View on Github external
throw 'Unable to parse SRS name';
    }

    if (!codeParts || !codeParts[1]) {
      throw 'Unable to parse SRS name';
    }

    code = codeParts[1];
    transformation = codeParts[3];

    name = authority + ':' + code;
    proj = this.projections[name];

    if (!proj) {
      try {
        proj4.Proj(name);
        // Known, since no exception
        this._store(name, cb, context);
      } catch (e) {
        this._fetch(authority, code, transformation, cb, context);
      }
    } else {
      cb.call(context || cb, name, proj);
    }
  },
github kalisio / krawler / src / hooks / hooks.geojson.js View on Github external
const crss = _.mapValues(proj4.defs, def => proj4.Proj(def))
github sentinel-hub / SentinelPlayground / src / utils / coords.js View on Github external
export function wgs84ToMercator(point) {
  var sourceCRS = proj4.Proj('EPSG:4326');
  var destCRS = proj4.Proj('EPSG:3857');
  var pt = new proj4.toPoint([point[1], point[0]]);
  proj4.transform(sourceCRS, destCRS, pt);
  return pt;
}
export function calcBboxFromXY(point, zoomLevel) {
github perliedman / gis-nerd-tools / src / projections.js View on Github external
_poll: function(authority, code, cb, context) {
    var _this = this,
        name = authority + ':' + code;
    try {
      proj4.Proj(name);
      this._store(name, cb, context);
    } catch (e) {
      setTimeout(function() {
        _this._poll(authority, code, cb, context);
      }, 100);
    }
  },
github ngageoint / geopackage-js / converters / shapefile / index.js View on Github external
var dbfZipObject = dbffileArray[d];
      if (dbfZipObject.name == basename + '.dbf') {
        var dbfBuffer = dbfZipObject.asNodeBuffer();
        dbfStream = new stream.PassThrough();
        dbfStream.end(dbfBuffer);
        break;
      }
    }

    var projection;

    for (var p = 0; p < prjfileArray.length; p++) {
      var prjZipObject = prjfileArray[p];
      if (prjZipObject.name == basename + '.prj') {
        var prjBuffer = prjZipObject.asNodeBuffer();
        projection = proj4.Proj(prjBuffer.toString());
        break;
      }
    }
    readers.push({
      tableName: basename,
      projection: projection,
      reader: shp.reader({
        shp: shpStream,
        dbf: dbfStream,
        'ignore-properties': !!dbfStream
      })
    });
  }
  return readers;
}
github perliedman / gis-nerd-tools / src / projections.js View on Github external
_store: function(name, cb, context) {
    var p = proj4.Proj(name);
    this.projections[name] = p;
    cb.call(context || cb, name, p);
  }
});

proj4

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

MIT
Latest version published 29 days ago

Package Health Score

89 / 100
Full package analysis

Similar packages