How to use the proj4.defs 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
// Tests Measurement
///////////////////////////////////////////
proj4(epsg['4269'], epsg['4326'], point1)
proj4(epsg['4269'], point1)
proj4(epsg['4269'], epsg['4326']).forward(point2)
proj4(epsg['4269'], epsg['4326']).inverse(point2)

///////////////////////////////////
// Named Projections
///////////////////////////////////
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
github johnfontaine / LasStreamReader / src / las.js View on Github external
function computeProjectionWithGeoTag(obj, projection_records) {
//    console.log("record is", record);
    let projection = {
      codes : {},
      got_projection : false,
      convert_to_wgs84 : null,
      target_proj : proj4.defs('EPSG:4326'),
      convert_elevation_to_meters : function(value) { return value; },
      convert_linear_to_meters : function(value) { return value; }
    };
    let geokey = new models.GeoKey(projection_records);
    projection.geokey = geokey;
    //get the EPSG code held in key 3072 or throw an error because this file lacks common decency.
    //See http://gis.stackexchange.com/questions/173111/converting-geotiff-projection-definition-to-proj4
    //todo: other projection options.
    //http://www.remotesensing.org/geotiff/spec/geotiff6.html#6.3.3.1
    let epsg_code;
    //check for Unit code
    if (geokey.has_epsg_projection) {
        epsg_code = String(epsg[String(geokey.epsg_projection_code)]);
        if (epsg_code && epsg_code !== "unknown") {
            projection.epsg_proj4 = epsg_code;
            projection.epsg_datum = geokey.epsg_projection_code;
github county-of-simcoe-gis / SimcoeCountyWebViewer / src / sidebar / components / tools / coordinates / Coordinates.jsx View on Github external
componentDidMount() {
    // LISTEN FOR MAP TO MOUNT
    window.emitter.addListener("mapLoaded", () => this.onMapLoad());

    // DISABLE PROPERTY CLICK
    window.disableParcelClick = true;

    // REGISTER MAP EVENTS
    this.onPointerMoveEvent = window.map.on("pointermove", this.onPointerMoveHandler);
    this.onMapClickEvent = window.map.on("click", this.onMapClick);
    this.onMapMoveEvent = window.map.on("moveend", this.onMapMoveEnd);

    // REGISTER CUSTOM PROJECTIONS
    proj4.defs([
      ["EPSG:26917", "+proj=utm +zone=17 +ellps=GRS80 +datum=NAD83 +units=m +no_defs "],
      ["EPSG:26717", "+proj=utm +zone=17 +ellps=clrk66 +datum=NAD27 +units=m +no_defs "]
    ]);
    register(proj4);

    // INITIAL EXTENT
    this.updateExtent();
  }
github county-of-simcoe-gis / SimcoeCountyWebViewer / src / helpers / helpers.js View on Github external
import Projection from "ol/proj/Projection.js";
import proj4 from "proj4";
import { register } from "ol/proj/proj4";
import { fromLonLat } from "ol/proj";
import { getVectorContext } from "ol/render";

//OTHER
import { parseString } from "xml2js";
import shortid from "shortid";
import ShowMessage from "./ShowMessage.jsx";
import URLWindow from "./URLWindow.jsx";
import mainConfig from "../config.json";
import { InfoRow } from "./InfoRow.jsx";

// REGISTER CUSTOM PROJECTIONS
proj4.defs([["EPSG:26917", "+proj=utm +zone=17 +ellps=GRS80 +datum=NAD83 +units=m +no_defs "]]);
register(proj4);

// UTM NAD 83
const _nad83Proj = new Projection({
  code: "EPSG:26917",
  extent: [194772.8107, 2657478.7094, 805227.1893, 9217519.4415]
});

// APP STAT
export function addAppStat(type, description) {
  if (mainConfig.includeAppStats === false) return;

  // IGNORE LOCAL HOST DEV
  if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") return;

  const appStatsTemplate = (type, description) => `${mainConfig.appStatsUrl}opengis/${type}/${description}`;
github johnfontaine / LasStreamReader / src / las.js View on Github external
this.is_laz = false;
        this.check_laz = false;
        this.check_classification_lookup = false;
        this.has_classification_lookup_table = false;
        if (options) {
            this.point_record_options.transform_lnglat = options.transform_lnglat === false ? false : true; // raw | scaled | wgs
            this.point_record_options.parse_full_point_record = options.parse_full_point_record || false;
            if (options.filter) {
                //include a filter;;
            }
            if (options.projection && options.projection.epsg_datum) {
                let epsg_code = epsg[String(options.projection.epsg_datum)];
                this.projection = {
                    epsg_datum :  options.projection.epsg_datum,
                    epsg_code : epsg_code,
                    convert_to_wgs84 : new proj4(epsg_code, proj4.defs('EPSG:4326')),
                    convert_elevation_to_meters  : function(value) { return value }
                };
                //igore VLR projection data and use this one instead.
                this.got_projection = true;
            }
        }
    }
    _transform(data, encoding, callback) {
github johnfontaine / LasStreamReader / src / las.js View on Github external
function computeProjection(obj, records) { //variable length records
    if(records['LASF_Projection']) {
      if (records['LASF_Projection']['34735']) {
        return computeProjectionWithGeoTag(obj,records['LASF_Projection']);
      } else if (records['LASF_Projection']['2111']) {
        obj.emit("error", new Error("Math WKT transform not supported"));
      } else if (records['LASF_Projection']['2112']) {
        let projection = {
          target_proj : proj4.defs('EPSG:4326'),
          got_projection : true,
          wkt : records['LASF_Projection']['2112'].ascii_data,
          parse_wkt : wkt_parser(records['LASF_Projection']['2112'].ascii_data),
          convert_to_wgs84 : null,
          convert_elevation_to_meters : function(value) { return value; },
          convert_linear_to_meters : function(value) { return value; }
        };
        if (projection.parse_wkt.PROJCS && projection.parse_wkt.PROJCS.UNIT && projection.parse_wkt.PROJCS.UNIT.name != 'meter') {
          projection.convert_elevation_to_meters = function(value) {
            return value * Number(projection.parse_wkt.PROJCS.UNIT.value);
          }
        }
        try {
          projection.convert_to_wgs84 = new proj4(projection.wkt, projection.target_proj); //to
          projection.got_projection = true;
          return projection;
github SuperMap / iClient-JavaScript / src / leaflet / core / Proj4Leaflet.js View on Github external
_projFromCodeDef: function(code, def) {
        if (def) {
            proj4.defs(code, def);
        } else if (proj4.defs[code] === undefined) {
            var urn = code.split(':');
            if (urn.length > 3) {
                code = urn[urn.length - 3] + ':' + urn[urn.length - 1];
            }
            if (proj4.defs[code] === undefined) {
                throw 'No projection definition for code ' + code;
            }
        }

        return proj4(code);
    },
    getUnits: function() {
github camptocamp / ngeo / src / proj / EPSG3947.js View on Github external
const epsg3947def = [
  `+proj=${lcc}`,
  '+lat_1=46.25',
  '+lon_0=3',
  '+lat_0=47',
  '+lat_2=47.75',
  '+x_0=1700000',
  '+y_0=6200000',
  '+ellps=GRS80',
  '+towgs84=0,0,0,0,0,0,0',
  '+units=m',
  '+no_defs'
].join(' ');
const epsg3947extent = [619993.48, 5637784.91, 2212663.72, 6731809.22];

proj4.defs('EPSG:3947', epsg3947def);
olProjProj4.register(proj4);
olProj.get('EPSG:3947').setExtent(epsg3947extent);

const exports = 'EPSG:3947';


export default exports;
github openlayers / openlayers / examples / reprojection.js View on Github external
import {OSM, TileImage, TileWMS, XYZ} from '../src/ol/source.js';
import WMTS, {optionsFromCapabilities} from '../src/ol/source/WMTS.js';
import TileGrid from '../src/ol/tilegrid/TileGrid.js';
import proj4 from 'proj4';


proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 ' +
    '+x_0=400000 +y_0=-100000 +ellps=airy ' +
    '+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
    '+units=m +no_defs');
proj4.defs('EPSG:23032', '+proj=utm +zone=32 +ellps=intl ' +
    '+towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs');
proj4.defs('EPSG:5479', '+proj=lcc +lat_1=-76.66666666666667 +lat_2=' +
    '-79.33333333333333 +lat_0=-78 +lon_0=163 +x_0=7000000 +y_0=5000000 ' +
    '+ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
proj4.defs('EPSG:21781', '+proj=somerc +lat_0=46.95240555555556 ' +
    '+lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel ' +
    '+towgs84=674.4,15.1,405.3,0,0,0,0 +units=m +no_defs');
proj4.defs('EPSG:3413', '+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 ' +
    '+x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs');
proj4.defs('EPSG:2163', '+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 ' +
    '+a=6370997 +b=6370997 +units=m +no_defs');
proj4.defs('ESRI:54009', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 ' +
    '+units=m +no_defs');
register(proj4);

const proj27700 = getProjection('EPSG:27700');
proj27700.setExtent([0, 0, 700000, 1300000]);

const proj23032 = getProjection('EPSG:23032');
proj23032.setExtent([-1206118.71, 4021309.92, 1295389.00, 8051813.28]);
github camptocamp / ngeo / src / proj / EPSG32631.js View on Github external
import * as olProjProj4 from 'ol/proj/proj4.js';

import utm from 'ngeo/proj/utm.js';
import proj4 from 'proj4';

const epsg32631def = [
  `+proj=${utm}`,
  '+zone=31',
  '+ellps=WGS84',
  '+datum=WGS84',
  '+units=m',
  '+no_defs'
].join(' ');
const epsg32631extent = [166021.44, 0.00, 534994.66, 9329005.18];

proj4.defs('EPSG:32631', epsg32631def);
olProjProj4.register(proj4);
olProj.get('EPSG:32631').setExtent(epsg32631extent);

const exports = 'EPSG:32631';


export default exports;

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